Correctly set last-modified time on exported files in Windows.

This commit is contained in:
Dmitry Brant 2016-07-30 14:14:56 -04:00
parent e1693eb92b
commit 72ac1218f0
4 changed files with 42 additions and 1 deletions

View File

@ -269,6 +269,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)
{
struct my_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, error %d\n", path, GetLastError()));
}
// Open Finder info file
int fd = open_finf(path, O_RDWR);
if (fd < 0)

View File

@ -1123,3 +1123,28 @@ int my_write( int fd, const void *buffer, unsigned int count )
D(bug("write(%ld,%08x,%ld) = %d\n", fd, buffer, count, result));
return result;
}
FILETIME getFileTime(time_t time) {
FILETIME ft;
unsigned long long result = 11644473600LL;
result += time;
result *= 10000000LL;
ft.dwHighDateTime = (result >> 32);
ft.dwLowDateTime = (result & 0xFFFFFFFF);
return ft;
}
int my_utime( const char *path, struct my_utimbuf * my_times )
{
auto tpath = tstr(path);
LPCTSTR p = MRP(tpath.get());
HANDLE f = CreateFile(p, FILE_WRITE_ATTRIBUTES, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
if (f != INVALID_HANDLE_VALUE) {
FILETIME crTime = getFileTime(my_times->actime);
FILETIME modTime = getFileTime(my_times->modtime);
SetFileTime(f, &crTime, NULL, &modTime);
CloseHandle(f);
return 0;
}
return -1;
}

View File

@ -73,6 +73,7 @@ int my_read( int fd, void *, unsigned int);
int my_write( int fd, const void *, unsigned int);
int my_chsize( int fd, unsigned int size );
int my_locking( int fd, int mode, long nbytes );
int my_utime( const char *path, struct my_utimbuf * );
extern int my_errno;
@ -92,6 +93,7 @@ extern int my_errno;
#define write my_write
#define ftruncate my_chsize
#define locking my_locking
#define utime my_utime
#undef errno
#define errno my_errno
@ -116,6 +118,12 @@ struct my_stat {
time_t st_ctime;
};
struct my_utimbuf
{
time_t actime; // access time
time_t modtime; // modification time
};
// Your compiler may have different "struct stat" -> edit "struct my_stat"
#define validate_stat_struct ( sizeof(struct my_stat) == sizeof(struct stat) )

View File

@ -151,6 +151,6 @@ uint32 TimeToMacTime(time_t t)
time_t MacTimeToTime(uint32 t)
{
// simply subtract number of seconds between 1.1.1094 and 1.1.1970
// simply subtract number of seconds between 1.1.1904 and 1.1.1970
return t - 2082826800;
}