Skip to content

Commit d9b2633

Browse files
dschogitster
authored andcommitted
test-chmtime: work around Windows limitation
Windows has problems changing the mtime when the file is write protected, even by the owner of said file. Add a Windows-only workaround to change the mode if necessary before trying to change the mtime. Signed-off-by: Johannes Schindelin <[email protected]> Signed-off-by: Steffen Prohaska <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 492f709 commit d9b2633

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

test-chmtime.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,15 @@ int main(int argc, const char *argv[])
8787
return -1;
8888
}
8989

90+
#ifdef WIN32
91+
if (!(sb.st_mode & S_IWUSR) &&
92+
chmod(argv[i], sb.st_mode | S_IWUSR)) {
93+
fprintf(stderr, "Could not make user-writable %s: %s",
94+
argv[i], strerror(errno));
95+
return -1;
96+
}
97+
#endif
98+
9099
utb.actime = sb.st_atime;
91100
utb.modtime = set_eq ? set_time : sb.st_mtime + set_time;
92101

0 commit comments

Comments
 (0)