@matheusbsbs / matheus-bagliano / commits / 7ebb6fcafe
Fork 0

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 <junkio@cox.net>

Linus Torvalds committed Oct 26, 2005 at 10:27 UTC 7ebb6fcafed2a3d47390e6f47ff20a98fe451409
1 file changed +14 -13
sha1_file.c
+14 -13
@@ -1232,19 +1232,20 @@ static int link_temp_to_file(const char *tmpfile, char *filename)
1232 int move_temp_to_file(const char *tmpfile, char *filename)
1233 {
1234 int ret = link_temp_to_file(tmpfile, filename);
1235 - if (ret) {
1236 - /*
1237 - * Coda hack - coda doesn't like cross-directory links,
1238 - * so we fall back to a rename, which will mean that it
1239 - * won't be able to check collisions, but that's not a
1240 - * big deal.
1241 - *
1242 - * The same holds for FAT formatted media.
1243 - *
1244 - * When this succeeds, we just return 0. We have nothing
1245 - * left to unlink.
1246 - */
1247 - if ((ret == EXDEV || ret == ENOTSUP) && !rename(tmpfile, filename))
1235 +
1236 + /*
1237 + * Coda hack - coda doesn't like cross-directory links,
1238 + * so we fall back to a rename, which will mean that it
1239 + * won't be able to check collisions, but that's not a
1240 + * big deal.
1241 + *
1242 + * The same holds for FAT formatted media.
1243 + *
1244 + * When this succeeds, we just return 0. We have nothing
1245 + * left to unlink.
1246 + */
1247 + if (ret && ret != EEXIST) {
1248 + if (!rename(tmpfile, filename))
1249 return 0;
1250 ret = errno;
1251 }