diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/posix.h | 4 | ||||
-rw-r--r-- | src/win32/posix_w32.c | 34 |
2 files changed, 33 insertions, 5 deletions
diff --git a/src/posix.h b/src/posix.h index bd5a98e26..d26371bca 100644 --- a/src/posix.h +++ b/src/posix.h @@ -24,6 +24,10 @@ #define _S_IFLNK S_IFLNK #endif +#ifndef S_IWUSR +#define S_IWUSR 00200 +#endif + #ifndef S_IXUSR #define S_IXUSR 00100 #endif diff --git a/src/win32/posix_w32.c b/src/win32/posix_w32.c index 5172627b0..af4f5743a 100644 --- a/src/win32/posix_w32.c +++ b/src/win32/posix_w32.c @@ -212,16 +212,40 @@ int p_lstat_posixly(const char *filename, struct stat *buf) return do_lstat(filename, buf, true); } -int p_utimes(const char *filename, const struct p_timeval times[2]) +int p_utimes(const char *path, const struct p_timeval times[2]) { + git_win32_path wpath; int fd, error; + DWORD attrs_orig, attrs_new = 0; - if ((fd = p_open(filename, O_RDWR)) < 0) - return fd; + if (git_win32_path_from_utf8(wpath, path) < 0) + return -1; - error = p_futimes(fd, times); + attrs_orig = GetFileAttributesW(wpath); + + if (attrs_orig & FILE_ATTRIBUTE_READONLY) { + attrs_new = attrs_orig & ~FILE_ATTRIBUTE_READONLY; + + if (!SetFileAttributesW(wpath, attrs_new)) { + giterr_set(GITERR_OS, "failed to set attributes"); + return -1; + } + } + /* TODO: CreateFile */ + if ((error = fd = p_open(path, O_RDWR)) < 0) + goto done; + + error = p_futimes(fd, times); close(fd); + +done: + if (attrs_orig != attrs_new) { + DWORD os_error = GetLastError(); + SetFileAttributesW(wpath, attrs_orig); + SetLastError(os_error); + } + return error; } @@ -605,7 +629,7 @@ static int ensure_writable(wchar_t *fpath) return -1; } - return 0; + return 1; } int p_rename(const char *from, const char *to) |