From e40c594146c4368e43ce823df6dcc89589b8e547 Mon Sep 17 00:00:00 2001 From: Johannes Schindelin Date: Tue, 23 Jan 2007 13:39:09 +0100 Subject: [PATCH] mingw: always chmod(, 0666) before unlink() On Windows, a read-only file cannot be deleted. To make sure that deletion does not fail because of this, always call chmod() before unlink(). Signed-off-by: Johannes Schindelin --- git-compat-util.h | 7 +++++++ index-pack.c | 4 ---- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/git-compat-util.h b/git-compat-util.h index bf42191ab7..4c3250858b 100644 --- a/git-compat-util.h +++ b/git-compat-util.h @@ -359,6 +359,13 @@ static inline int git_mkdir(const char *path, int mode) } #define mkdir git_mkdir +static inline int git_unlink(const char *pathname) { + /* read-only files cannot be removed */ + chmod(pathname, 0666); + return unlink(pathname); +} +#define unlink git_unlink + #include struct tm *gmtime_r(const time_t *timep, struct tm *result); struct tm *localtime_r(const time_t *timep, struct tm *result); diff --git a/index-pack.c b/index-pack.c index 040957c016..72e0962415 100644 --- a/index-pack.c +++ b/index-pack.c @@ -700,10 +700,6 @@ static const char *write_index_file(const char *index_name, unsigned char *sha1) fd = mkstemp(tmpfile); index_name = xstrdup(tmpfile); } else { -#ifdef __MINGW32__ - /* read-only files cannot be removed */ - chmod(index_name, 0666); -#endif unlink(index_name); fd = open(index_name, O_CREAT|O_EXCL|O_WRONLY, 0600); } -- 2.11.4.GIT