Merge pull request #88 from dbrant/mtime

Correctly set last-modified time on exported files.
This commit is contained in:
asvitkine 2016-07-29 19:17:00 -04:00 committed by GitHub
commit aec76768b5
3 changed files with 20 additions and 0 deletions

View File

@ -25,6 +25,7 @@
#include <unistd.h> #include <unistd.h>
#include <dirent.h> #include <dirent.h>
#include <errno.h> #include <errno.h>
#include <utime.h>
#include "sysdeps.h" #include "sysdeps.h"
#include "extfs.h" #include "extfs.h"
@ -256,6 +257,14 @@ void get_finfo(const char *path, uint32 finfo, uint32 fxinfo, bool is_dir)
void set_finfo(const char *path, uint32 finfo, uint32 fxinfo, bool is_dir) void set_finfo(const char *path, uint32 finfo, uint32 fxinfo, bool is_dir)
{ {
struct utimbuf times;
times.actime = MacTimeToTime(ReadMacInt32(finfo - ioFlFndrInfo + ioFlCrDat));
times.modtime = MacTimeToTime(ReadMacInt32(finfo - ioFlFndrInfo + ioFlMdDat));
if (utime(path, &times) < 0) {
D(bug("utime failed on %s\n", path));
}
// Open Finder info file // Open Finder info file
int fd = open_finf(path, O_RDWR); int fd = open_finf(path, O_RDWR);
if (fd < 0) if (fd < 0)

View File

@ -265,6 +265,7 @@ extern void MountVolume(void *fh); // Mount volume with given file handle (s
extern void FileDiskLayout(loff_t size, uint8 *data, loff_t &start_byte, loff_t &real_size); // Calculate disk image file layout given file size and first 256 data bytes extern void FileDiskLayout(loff_t size, uint8 *data, loff_t &start_byte, loff_t &real_size); // Calculate disk image file layout given file size and first 256 data bytes
extern uint32 DebugUtil(uint32 Selector); // DebugUtil() Replacement extern uint32 DebugUtil(uint32 Selector); // DebugUtil() Replacement
extern uint32 TimeToMacTime(time_t t); // Convert time_t value to MacOS time extern uint32 TimeToMacTime(time_t t); // Convert time_t value to MacOS time
extern time_t MacTimeToTime(uint32 t); // Convert MacOS time to time_t value
// Construct four-character-code // Construct four-character-code
#define FOURCC(a,b,c,d) (((uint32)(a) << 24) | ((uint32)(b) << 16) | ((uint32)(c) << 8) | (uint32)(d)) #define FOURCC(a,b,c,d) (((uint32)(a) << 24) | ((uint32)(b) << 16) | ((uint32)(c) << 8) | (uint32)(d))

View File

@ -144,3 +144,13 @@ uint32 TimeToMacTime(time_t t)
uint32 days = local->tm_yday + 365 * (local->tm_year - 4) + intervening_leap_days; uint32 days = local->tm_yday + 365 * (local->tm_year - 4) + intervening_leap_days;
return local->tm_sec + 60 * (local->tm_min + 60 * (local->tm_hour + 24 * days)); return local->tm_sec + 60 * (local->tm_min + 60 * (local->tm_hour + 24 * days));
} }
/*
* Convert MacOS time to time_t (seconds since 1.1.1970)
*/
time_t MacTimeToTime(uint32 t)
{
// simply subtract number of seconds between 1.1.1094 and 1.1.1970
return t - 2082826800;
}