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

[TopGit PATCH/RFC fixup] suppress "cannot overwrite existing file" error

From
Jonathan Nieder <jrnieder@uchicago.edu>
Date
Aug 12, 2008, 18:21 UTC
Message-ID
<Pine.GSO.4.62.0808121317110.18832@harper.uchicago.edu>
In-Reply-To
<Pine.GSO.4.62.0808121309000.18832@harper.uchicago.edu>

We had been using sh -C ": >filename" to atomically create a file, but this has the unfortunate side effect of producing an error message if the file already exists. So suppress the error.

Signed-off-by: Jonathan Nieder <jrnieder@uchicago.edu>
---
	Here's a fix to a mistake in the patch I just sent.  If the
	patch was meant for application, I would be suggesting
	squashing this change in.  Sorry for the noise.
 tg.sh |    4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/tg.sh b/tg.sh
index c31256f..65375d6 100644
--- a/tg.sh
+++ b/tg.sh
@@ -85,14 +85,14 @@ branch_contains()
 # nonzero status on failure
 temp_filename()
 {
-	set -C && umask 077
+	umask 077
 	prefix=$1
 	i=0
 	suffix=$(awk 'BEGIN { srand(); rand(); print int(rand()*99999) }')
 	while test $i -lt 256
 	do
 		tmp=$prefix$suffix
-		: >"$tmp" && break
+		sh -C -c ': >"$tmp"' 2>/dev/null && break
 		i=$(($i+1))
 		suffix=$(($suffix+1))
 	done
-- 
1.6.0.rc2.531.g79a96
Previous: Jonathan NiederNext: Petr Baudis
Message 2 of 6 in “Do not use mktemp”
  1. Do not use mktempJonathan Nieder, Aug 12, 2008
  2. suppress "cannot overwrite existing file" errorJonathan Nieder, Aug 12, 2008
  3. Petr BaudisAug 12, 2008
  4. Jonathan NiederAug 12, 2008
  5. supply template argument to mktempJonathan Nieder, Aug 13, 2008
  6. tg-info: fix sed typoJonathan Nieder, Aug 13, 2008

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.