Skip to content

Commit

Permalink
Fix what to do and how to detect when hardlinking fails
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Linus Torvalds authored and Junio C Hamano committed Oct 26, 2005
1 parent b5c367f commit 7ebb6fc
Showing 1 changed file with 14 additions and 13 deletions.
27 changes: 14 additions & 13 deletions sha1_file.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down

0 comments on commit 7ebb6fc

Please sign in to comment.