git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: git 565ebbf79f61873042c22a7126d002c104e056f4 broken on OpenBSD

From
Linus Torvalds <torvalds@osdl.org>
Date
Oct 26, 2005, 17:27 UTC
Message-ID
<Pine.LNX.4.64.0510261025440.10477@g5.osdl.org>
In-Reply-To
<Pine.LNX.4.63.0510261901140.9686@wbgn013.biozentrum.uni-wuerzburg.de>
On Wed, 26 Oct 2005, Johannes Schindelin wrote:
Show 9 quoted lines
> 
> On Wed, 26 Oct 2005, Jan Harkes wrote:
> 
> > -		if (ret == EXDEV && !rename(tmpfile, filename))
> > +		if (ret && ret != EEXIST && !rename(tmpfile, filename))
> 
> We don't need to test for ret, as we're already in a "if (ret)" block.  
> What would happen if ret==EEXIST, and we try to rename() nevertheless? It 
> should fail, too, right?
No, the rename will succeed and overwrite the existing file.

Which is strictly correct, but it's the wrong thing if we ever want to do collission detection.

So I'd actually prefer something like this patch instead.
		Linus
---
diff --git a/sha1_file.c b/sha1_file.c
index 7fdc469..642f00d 100644
--- a/sha1_file.c
+++ b/sha1_file.c
@@ -1232,19 +1232,20 @@ static int link_temp_to_file(const char 
 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;
 	}
Previous: Johannes SchindelinNext: Linus Torvalds
Message 11 of 17 in “git 565ebbf79f61873042c22a7126d002c104e056f4 broken on OpenBSD”
  1. Randal L. SchwartzOct 26, 2005
  2. Randal L. SchwartzOct 26, 2005
  3. Johannes SchindelinOct 26, 2005
  4. Randal L. SchwartzOct 26, 2005
  5. Johannes SchindelinOct 26, 2005
  6. Randal L. SchwartzOct 26, 2005
  7. Jan HarkesOct 26, 2005
  8. Johannes SchindelinOct 26, 2005
  9. Jan HarkesOct 26, 2005
  10. Johannes SchindelinOct 26, 2005
  11. Linus TorvaldsOct 26, 2005
  12. Linus TorvaldsOct 26, 2005
  13. Johannes SchindelinOct 26, 2005
  14. Horst von BrandOct 26, 2005
  15. Randal L. SchwartzOct 26, 2005
  16. Junio C HamanoOct 26, 2005
  17. Randal L. SchwartzOct 26, 2005

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.