summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLibravatar Junio C Hamano <junkio@cox.net>2006-07-14 15:38:37 -0700
committerLibravatar Junio C Hamano <junkio@cox.net>2006-07-14 15:38:37 -0700
commit1733832d8ec11655924af58efb67ff4503928b59 (patch)
tree2806bdf697d63c3b8e5fe81400ff8e54aca10a55
parentFix "git-fetch --tags" exit status when nothing has been changed (diff)
parentMake lazy mkdir more robust. (diff)
downloadtgif-1733832d8ec11655924af58efb67ff4503928b59.tar.xz
Merge branch 'sp/lazy-mkdir'
* sp/lazy-mkdir: Make lazy mkdir more robust.
-rw-r--r--sha1_file.c26
1 files changed, 12 insertions, 14 deletions
diff --git a/sha1_file.c b/sha1_file.c
index 8734d501fe..e666aec502 100644
--- a/sha1_file.c
+++ b/sha1_file.c
@@ -1331,31 +1331,29 @@ char *write_sha1_file_prepare(void *buf,
static int link_temp_to_file(const char *tmpfile, char *filename)
{
int ret;
+ char *dir;
if (!link(tmpfile, filename))
return 0;
/*
- * Try to mkdir the last path component if that failed
- * with an ENOENT.
+ * Try to mkdir the last path component if that failed.
*
* Re-try the "link()" regardless of whether the mkdir
* succeeds, since a race might mean that somebody
* else succeeded.
*/
ret = errno;
- if (ret == ENOENT) {
- char *dir = strrchr(filename, '/');
- if (dir) {
- *dir = 0;
- mkdir(filename, 0777);
- if (adjust_shared_perm(filename))
- return -2;
- *dir = '/';
- if (!link(tmpfile, filename))
- return 0;
- ret = errno;
- }
+ dir = strrchr(filename, '/');
+ if (dir) {
+ *dir = 0;
+ mkdir(filename, 0777);
+ if (adjust_shared_perm(filename))
+ return -2;
+ *dir = '/';
+ if (!link(tmpfile, filename))
+ return 0;
+ ret = errno;
}
return ret;
}