authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2020-02-16 22:34:40-05:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2020-02-16 22:34:40-05:00
logd5860cbade79141c4c547a3411befb8448dd56ab
tree5b1d792ae3fcade10525182e3d6557905f30deeb
parent364a284eb3b5e90a9ec0ea6b29be8b74d2a92fa5

fix os_update_file implementation on Windows


1 files changed, 20 insertions(+), 7 deletions(-)

src/os.cpp+20-7
......@@ -1070,9 +1070,11 @@ static FILETIME windows_os_timestamp_to_filetime(OsTimeStamp mtime) {
10701070
10711071static Error set_file_times(OsFile file, OsTimeStamp ts) {
10721072#if defined(ZIG_OS_WINDOWS)
1073 const atime_ft = windows.nanoSecondsToFileTime(atime);
1074 const mtime_ft = windows.nanoSecondsToFileTime(mtime);
1075 return SetFileTime(file, null, &atime_ft, &mtime_ft);
1073 FILETIME ft = windows_os_timestamp_to_filetime(ts);
1074 if (SetFileTime(file, nullptr, &ft, &ft) == 0) {
1075 return ErrorUnexpected;
1076 }
1077 return ErrorNone;
10761078#else
10771079 struct timespec times[2] = {
10781080 { ts.sec, ts.nsec },
......@@ -1114,14 +1116,25 @@ Error os_update_file(Buf *src_path, Buf *dst_path) {
11141116 os_file_close(&dst_file);
11151117 return ErrorNone;
11161118 }
1117
1119#if defined(ZIG_OS_WINDOWS)
1120 if (SetEndOfFile(dst_file) == 0) {
1121 return ErrorUnexpected;
1122 }
1123#else
1124 if (ftruncate(dst_file, 0) == -1) {
1125 return ErrorUnexpected;
1126 }
1127#endif
1128#if defined(ZIG_OS_WINDOWS)
1129 FILE *src_libc_file = _fdopen(_open_osfhandle((intptr_t)src_file, _O_RDONLY), "rb");
1130 FILE *dst_libc_file = _fdopen(_open_osfhandle((intptr_t)dst_file, 0), "wb");
1131#else
11181132 FILE *src_libc_file = fdopen(src_file, "rb");
11191133 FILE *dst_libc_file = fdopen(dst_file, "wb");
1134#endif
11201135 assert(src_libc_file);
11211136 assert(dst_libc_file);
1122 if (ftruncate(dst_file, 0) == -1) {
1123 return ErrorUnexpected;
1124 }
1137
11251138 if ((err = copy_open_files(src_libc_file, dst_libc_file))) {
11261139 fclose(src_libc_file);
11271140 fclose(dst_libc_file);