Windows cannot unlink() a file that is read-only.

This commit is contained in:
Johannes Sixt
2007-01-08 11:33:35 +01:00
parent 48f967a161
commit 0bb0ca2158
2 changed files with 12 additions and 2 deletions

View File

@@ -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);

View File

@@ -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);
}