diff options
author | Junio C Hamano <gitster@pobox.com> | 2010-03-31 15:14:27 -0700 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2010-03-31 15:14:27 -0700 |
commit | 890a13a45285ad44858add2ce2f74eb478f549c8 (patch) | |
tree | 778d3d73aef0d238edd621eaaf38dcdb9f22616e /compat/mingw.c | |
parent | 87b3c0117a340df61bdbac6794611c74696bd42a (diff) | |
parent | 2be10bb5c1cfe15aa4f1b43137ccd17d826d8553 (diff) | |
download | git-890a13a45285ad44858add2ce2f74eb478f549c8.tar.gz |
Sync with 1.7.0.4
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'compat/mingw.c')
-rw-r--r-- | compat/mingw.c | 20 |
1 files changed, 18 insertions, 2 deletions
diff --git a/compat/mingw.c b/compat/mingw.c index c5bfb39b39..30716903f5 100644 --- a/compat/mingw.c +++ b/compat/mingw.c @@ -275,8 +275,17 @@ int mingw_utime (const char *file_name, const struct utimbuf *times) int fh, rc; /* must have write permission */ - if ((fh = open(file_name, O_RDWR | O_BINARY)) < 0) - return -1; + DWORD attrs = GetFileAttributes(file_name); + if (attrs != INVALID_FILE_ATTRIBUTES && + (attrs & FILE_ATTRIBUTE_READONLY)) { + /* ignore errors here; open() will report them */ + SetFileAttributes(file_name, attrs & ~FILE_ATTRIBUTE_READONLY); + } + + if ((fh = open(file_name, O_RDWR | O_BINARY)) < 0) { + rc = -1; + goto revert_attrs; + } time_t_to_filetime(times->modtime, &mft); time_t_to_filetime(times->actime, &aft); @@ -286,6 +295,13 @@ int mingw_utime (const char *file_name, const struct utimbuf *times) } else rc = 0; close(fh); + +revert_attrs: + if (attrs != INVALID_FILE_ATTRIBUTES && + (attrs & FILE_ATTRIBUTE_READONLY)) { + /* ignore errors again */ + SetFileAttributes(file_name, attrs); + } return rc; } |