From 9c7f3032556e46f0e4a31bafd3a93d4959abfd5e Mon Sep 17 00:00:00 2001 From: aszlig Date: Thu, 28 Aug 2014 22:10:17 +0200 Subject: [PATCH] Use mktemp for tempdir creation in prefetchers. This incorporates the following two commits from : NixOS/nixpkgs@f83af95f8a54d0375ac6e159b663de887ba5b6a6 NixOS/nixpkgs@5e7a1cf955e43e1fa3c1c157c0d6961e1bcf9801 Hydra was the original reason why I was fixing tempdir creation in the first place. Seeing that Hydra ships its own versions of these scripts, we need to patch them here as well. Signed-off-by: aszlig --- src/script/nix-prefetch-bzr | 7 +++---- src/script/nix-prefetch-git | 8 ++++---- src/script/nix-prefetch-hg | 7 +++---- 3 files changed, 10 insertions(+), 12 deletions(-) diff --git a/src/script/nix-prefetch-bzr b/src/script/nix-prefetch-bzr index 167892fb..574703d4 100755 --- a/src/script/nix-prefetch-bzr +++ b/src/script/nix-prefetch-bzr @@ -43,11 +43,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/bzr-checkout-tmp-$$ - tmpFile=$tmpPath/$dstFile - mkdir $tmpPath + tmpPath="$(mktemp -d "${TMPDIR:-/tmp}/bzr-checkout-tmp-XXXXXXXX")" + trap "rm -rf \"$tmpPath\"" EXIT - trap "rm -rf $tmpPath" EXIT + tmpFile="$tmpPath/$dstFile" # Perform the checkout. if test "$NIX_PREFETCH_BZR_LEAVE_DOT_BZR" != 1 diff --git a/src/script/nix-prefetch-git b/src/script/nix-prefetch-git index 979aa531..8aa599b9 100755 --- a/src/script/nix-prefetch-git +++ b/src/script/nix-prefetch-git @@ -237,11 +237,11 @@ else # download the file and add it to the store. if test -z "$finalPath"; then - tmpPath=/tmp/git-checkout-tmp-$$ - tmpFile=$tmpPath/git-export - mkdir $tmpPath $tmpFile + tmpPath="$(mktemp -d "${TMPDIR:-/tmp}/git-checkout-tmp-XXXXXXXX")" + trap "rm -rf \"$tmpPath\"" EXIT - trap "rm -rf $tmpPath" EXIT + tmpFile="$tmpPath/git-export" + mkdir "$tmpFile" # Perform the checkout. clone_user_rev "$tmpFile" "$url" "$rev" diff --git a/src/script/nix-prefetch-hg b/src/script/nix-prefetch-hg index f1f648f4..4d78c68a 100755 --- a/src/script/nix-prefetch-hg +++ b/src/script/nix-prefetch-hg @@ -35,11 +35,10 @@ fi # download the file and add it to the store. if test -z "$finalPath"; then - tmpPath=/tmp/hg-checkout-tmp-$$ - tmpArchive=$tmpPath/hg-archive - mkdir $tmpPath + tmpPath="$(mktemp -d "${TMPDIR:-/tmp}/hg-checkout-tmp-XXXXXXXX")" + trap "rm -rf \"$tmpPath\"" EXIT - trap "rm -rf $tmpPath" EXIT + tmpArchive="$tmpPath/hg-archive" # Perform the checkout. if [[ $url != /* ]]; then