From: Linus Torvalds Date: Wed, 26 Oct 2005 17:27:36 +0000 (-0700) Subject: Fix what to do and how to detect when hardlinking fails X-Git-Tag: v0.99.9~35 X-Git-Url: https://git.verplant.org/?a=commitdiff_plain;h=7ebb6fcafed2a3d47390e6f47ff20a98fe451409;p=git.git Fix what to do and how to detect when hardlinking fails Recent FAT workaround caused compilation trouble on OpenBSD; different platforms use different error codes when we try to hardlink the temporary file to its final location. Existing Coda hack also checks its own error code, but the thing is, the case we care about is if link failed for a reason other than that the final file has already existed (which would be normal, or it could mean collision). So just check the error code against EEXIST. Signed-off-by: Junio C Hamano --- diff --git a/sha1_file.c b/sha1_file.c index 7fdc4696..642f00d3 100644 --- a/sha1_file.c +++ b/sha1_file.c @@ -1232,19 +1232,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; }