Skip to content
This repository was archived by the owner on May 24, 2026. It is now read-only.

Commit 2a6210b

Browse files
caesayclaude
andcommitted
Use native Windows API for setting file creation time
GLib's g_file_set_attributes_from_info may not support writing the time::created attribute on Windows. Use CreateFileW + SetFileTime directly to set creation, access, and modification times on extracted cabinet files. This ensures the IntegrationTest timestamp comparison passes. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 6c9fb5b commit 2a6210b

1 file changed

Lines changed: 33 additions & 0 deletions

File tree

msi-interop/msi_cab.c

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@
1919
#include <string.h>
2020
#include <time.h>
2121

22+
#ifdef _WIN32
23+
#include <windows.h>
24+
#endif
25+
2226
/* ========================================================================= */
2327
/* Internal context for cabinet creation */
2428
/* ========================================================================= */
@@ -734,6 +738,35 @@ CabExtract(const wchar_t *cab_path,
734738
NULL,
735739
NULL);
736740

741+
#ifdef _WIN32
742+
/* GLib may not support writing time::created via attributes.
743+
* Use the native Windows API to set creation time directly. */
744+
{
745+
char *file_path = g_file_get_path(extracted);
746+
if (file_path) {
747+
/* Convert Unix time to Windows FILETIME */
748+
static const int64_t EPOCH_DIFF = 116444736000000000LL;
749+
int64_t ft = (int64_t)unix_time * 10000000LL + EPOCH_DIFF;
750+
FILETIME filetime;
751+
filetime.dwLowDateTime = (DWORD)(ft & 0xFFFFFFFF);
752+
filetime.dwHighDateTime = (DWORD)(ft >> 32);
753+
754+
wchar_t *wpath = (wchar_t *)g_utf8_to_utf16(file_path, -1, NULL, NULL, NULL);
755+
if (wpath) {
756+
HANDLE hFile = CreateFileW(wpath, FILE_WRITE_ATTRIBUTES,
757+
FILE_SHARE_READ | FILE_SHARE_WRITE, NULL,
758+
OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
759+
if (hFile != INVALID_HANDLE_VALUE) {
760+
SetFileTime(hFile, &filetime, &filetime, &filetime);
761+
CloseHandle(hFile);
762+
}
763+
g_free(wpath);
764+
}
765+
g_free(file_path);
766+
}
767+
}
768+
#endif
769+
737770
g_object_unref(finfo);
738771
g_object_unref(extracted);
739772
g_date_time_unref(dt);

0 commit comments

Comments
 (0)