summary refs log tree commit diff
path: root/pkgs/build-support/fetchsvn/nix-prefetch-svn
diff options
context:
space:
mode:
authoraszlig <aszlig@redmoonstudios.org>2014-08-25 15:00:55 +0200
committeraszlig <aszlig@redmoonstudios.org>2014-08-25 15:28:55 +0200
commitf83af95f8a54d0375ac6e159b663de887ba5b6a6 (patch)
tree4caf88900435fdcee5201dd0a3ca037fa5157221 /pkgs/build-support/fetchsvn/nix-prefetch-svn
parent39b1e2fffc60f6603d8b0daa9f1dd55960311c49 (diff)
downloadnixlib-f83af95f8a54d0375ac6e159b663de887ba5b6a6.tar
nixlib-f83af95f8a54d0375ac6e159b663de887ba5b6a6.tar.gz
nixlib-f83af95f8a54d0375ac6e159b663de887ba5b6a6.tar.bz2
nixlib-f83af95f8a54d0375ac6e159b663de887ba5b6a6.tar.lz
nixlib-f83af95f8a54d0375ac6e159b663de887ba5b6a6.tar.xz
nixlib-f83af95f8a54d0375ac6e159b663de887ba5b6a6.tar.zst
nixlib-f83af95f8a54d0375ac6e159b663de887ba5b6a6.zip
build-support: Use mktemp -d in nix-prefetch-*.
Instead of relying on $$ to not collide with an existing path.

Quoting the Bash manual about $$:

> Expands to the process ID of the shell. In a () subshell, it expands
> to the process ID of the current shell, not the subshell.

So, this is different from $BASHPID:

> Expands to the process ID of the current bash process. This differs
> from $$ under certain circumstances, such as subshells that do not
> require bash to be re-initialized.

But even $BASHPID is prone to race conditions if the process IDs wrap
around, so to be on the safe side, we're using mktemp here.

Closes #3784.

Signed-off-by: aszlig <aszlig@redmoonstudios.org>
Diffstat (limited to 'pkgs/build-support/fetchsvn/nix-prefetch-svn')
-rwxr-xr-xpkgs/build-support/fetchsvn/nix-prefetch-svn7
1 files changed, 3 insertions, 4 deletions
diff --git a/pkgs/build-support/fetchsvn/nix-prefetch-svn b/pkgs/build-support/fetchsvn/nix-prefetch-svn
index a2ee3ac6052f..74de0a14c801 100755
--- a/pkgs/build-support/fetchsvn/nix-prefetch-svn
+++ b/pkgs/build-support/fetchsvn/nix-prefetch-svn
@@ -41,11 +41,10 @@ fi
 # If we don't know the hash or a path with that hash doesn't exist,
 # download the file and add it to the store.
 if test -z "$finalPath"; then
-    tmpPath=/tmp/svn-checkout-tmp-$$
-    tmpFile=$tmpPath/$dstFile
-    mkdir $tmpPath
+    tmpPath="$(mktemp --tmpdir -d svn-checkout-tmp-XXXXXXXX)"
+    trap "rm -rf \"$tmpPath\"" EXIT
 
-    trap "rm -rf $tmpPath" EXIT
+    tmpFile="$tmpPath/$dstFile"
 
     # Perform the checkout.
     if test "$NIX_PREFETCH_SVN_LEAVE_DOT_SVN" != 1