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

[TopGit PATCH] supply template argument to mktemp

From
Jonathan Nieder <jrnieder@uchicago.edu>
Date
Aug 13, 2008, 00:17 UTC
Message-ID
<Pine.GSO.4.62.0808121911340.1112@harper.uchicago.edu>
In-Reply-To
<Pine.GSO.4.62.0808121557290.24244@harper.uchicago.edu>

mktemp versions before 1.5 did not allow omitting the template (prefix.XXXXXX) argument. Thus on Mac OS X,

	$ mktemp -d
	usage: mktemp [-d] [-q] [-t prefix] [-u] template ...
	       mktemp [-d] [-q] [-u] -t prefix

So supply a filename template. To maintain the intended behavior, we have to add -t, too. It was implied before.

Signed-off-by: Jonathan Nieder <jrnieder@uchicago.edu>
---
	Jonathan Nieder wrote:
	> So thinking it through, perhaps we should do the following:
	>  - provide a simple mini-mktemp for users to install themselves
	>    on old systems
	>  - always provide the template argument to mktemp
	Here's the second part.  With this change, plus a sed
	portability fix I will send separately, topgit on Mac OS X
	works.  Thanks for the help.
 tg-export.sh |    2 +-
 tg-info.sh   |    2 +-
 tg-patch.sh  |    2 +-
 tg-update.sh |    2 +-
 tg.sh        |    2 +-
 5 files changed, 5 insertions(+), 5 deletions(-)
diff --git a/tg-export.sh b/tg-export.sh
index 62361dd..62ea4f9 100644
--- a/tg-export.sh
+++ b/tg-export.sh
@@ -32,7 +32,7 @@ base_rev="$(git rev-parse --short --verify "refs/top-bases/$name" 2>/dev/null)"
 	die "not on a TopGit-controlled branch"
 
 
-playground="$(mktemp -d)"
+playground="$(mktemp -d -t tg-export.XXXXXX)"
 trap 'rm -rf "$playground"' EXIT
 
 
diff --git a/tg-info.sh b/tg-info.sh
index 43589f9..f2b6365 100644
--- a/tg-info.sh
+++ b/tg-info.sh
@@ -41,7 +41,7 @@ branch_contains "$name" "$base_rev" ||
 git cat-file blob "$name:.topdeps" |
 	sed '1{s/^/Depends: /;n}; s/^/         /;'
 
-depcheck="$(mktemp)"
+depcheck="$(mktemp -t tg-depcheck.XXXXXX)"
 missing_deps=
 needs_update "$name" >"$depcheck" || :
 if [ -n "$missing_deps" ]; then
diff --git a/tg-patch.sh b/tg-patch.sh
index 04023c0..48f4d77 100644
--- a/tg-patch.sh
+++ b/tg-patch.sh
@@ -29,7 +29,7 @@ echo
 [ -n "$(git grep '^[-]--' "$name" -- ".topmsg")" ] || echo '---'
 
 # Evil obnoxious hack to work around the lack of git diff --exclude
-git_is_stupid="$(mktemp)"
+git_is_stupid="$(mktemp -t tg-patch-changes.XXXXXX)"
 git diff-tree --name-only "$base_rev" "$name" |
 	fgrep -vx ".topdeps" |
 	fgrep -vx ".topmsg" >"$git_is_stupid" || : # fgrep likes to fail randomly?
diff --git a/tg-update.sh b/tg-update.sh
index 27a8e81..50b29b4 100644
--- a/tg-update.sh
+++ b/tg-update.sh
@@ -21,7 +21,7 @@ base_rev="$(git rev-parse --short --verify "refs/top-bases/$name" 2>/dev/null)"
 
 ## First, take care of our base
 
-depcheck="$(mktemp)"
+depcheck="$(mktemp -t tg-depcheck.XXXXXX)"
 missing_deps=
 needs_update "$name" >"$depcheck" || :
 [ -z "$missing_deps" ] || die "some dependencies are missing: $missing_deps"
diff --git a/tg.sh b/tg.sh
index e5766fe..1bc886a 100644
--- a/tg.sh
+++ b/tg.sh
@@ -95,7 +95,7 @@ recurse_deps()
 	_cmd="$1"; shift
 	_name="$1"; # no shift
 	_depchain="$*"
-	_depsfile="$(mktemp)"
+	_depsfile="$(mktemp -t tg-depsfile.XXXXXX)"
 	git cat-file blob "$_name:.topdeps" >"$_depsfile"
 	_ret=0
 	while read _dep; do
-- 
tg: (f27e693..) t/topgit/mktemp-template (depends on: )
Previous: Jonathan NiederNext: Jonathan Nieder
Message 5 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.