From 0bb0ca215830c19220a2cc78ca7c5a3b16b6f1df Mon Sep 17 00:00:00 2001 From: Johannes Sixt Date: Mon, 8 Jan 2007 11:33:35 +0100 Subject: [PATCH] Windows cannot unlink() a file that is read-only. --- builtin-prune-packed.c | 10 ++++++++-- index-pack.c | 4 ++++ 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/builtin-prune-packed.c b/builtin-prune-packed.c index 977730064b..639fbed2fc 100644 --- a/builtin-prune-packed.c +++ b/builtin-prune-packed.c @@ -25,8 +25,14 @@ static void prune_dir(int i, DIR *dir, char *pathname, int len, int opts) memcpy(pathname + len, de->d_name, 38); if (opts & DRY_RUN) printf("rm -f %s\n", pathname); - else if (unlink(pathname) < 0) - error("unable to unlink %s", pathname); + else { +#ifdef __MINGW32__ + /* read-only files cannot be removed */ + chmod(pathname, 0666); +#endif + if (unlink(pathname) < 0) + error("unable to unlink %s", pathname); + } } pathname[len] = 0; rmdir(pathname); diff --git a/index-pack.c b/index-pack.c index 72e0962415..040957c016 100644 --- a/index-pack.c +++ b/index-pack.c @@ -700,6 +700,10 @@ 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