X-Git-Url: https://git.octo.it/?a=blobdiff_plain;f=sha1_file.c;h=946a35346bdaf21432b7f463712f5bf8881fee39;hb=df8171ccb34ef346799b8bc2794d8707209c91d1;hp=7fdc46969d718096f6492f08489ae20b9693c64b;hpb=9e48b389990c0201487e58f3bac32734a59a7e89;p=git.git diff --git a/sha1_file.c b/sha1_file.c index 7fdc4696..946a3534 100644 --- a/sha1_file.c +++ b/sha1_file.c @@ -51,6 +51,8 @@ int get_sha1_hex(const char *hex, unsigned char *sha1) int safe_create_leading_directories(char *path) { char *pos = path; + if (*pos == '/') + pos++; while (pos) { pos = strchr(pos, '/'); @@ -1232,19 +1234,20 @@ static int link_temp_to_file(const char *tmpfile, char *filename) int move_temp_to_file(const char *tmpfile, char *filename) { int ret = link_temp_to_file(tmpfile, filename); - if (ret) { - /* - * Coda hack - coda doesn't like cross-directory links, - * so we fall back to a rename, which will mean that it - * won't be able to check collisions, but that's not a - * big deal. - * - * The same holds for FAT formatted media. - * - * When this succeeds, we just return 0. We have nothing - * left to unlink. - */ - if ((ret == EXDEV || ret == ENOTSUP) && !rename(tmpfile, filename)) + + /* + * Coda hack - coda doesn't like cross-directory links, + * so we fall back to a rename, which will mean that it + * won't be able to check collisions, but that's not a + * big deal. + * + * The same holds for FAT formatted media. + * + * When this succeeds, we just return 0. We have nothing + * left to unlink. + */ + if (ret && ret != EEXIST) { + if (!rename(tmpfile, filename)) return 0; ret = errno; }