summary refs log tree commit diff
path: root/pkgs/build-support/fetchsvn/nix-prefetch-svn
diff options
context:
space:
mode:
Diffstat (limited to 'pkgs/build-support/fetchsvn/nix-prefetch-svn')
-rwxr-xr-xpkgs/build-support/fetchsvn/nix-prefetch-svn22
1 files changed, 16 insertions, 6 deletions
diff --git a/pkgs/build-support/fetchsvn/nix-prefetch-svn b/pkgs/build-support/fetchsvn/nix-prefetch-svn
index 7f5f6828941..00d860e347e 100755
--- a/pkgs/build-support/fetchsvn/nix-prefetch-svn
+++ b/pkgs/build-support/fetchsvn/nix-prefetch-svn
@@ -24,6 +24,15 @@ if test -z "$hash"; then
     # !!! race? should be relatively safe, `svn export' barfs if $tmpPath exists.
     tmpPath1=$storeDir/svn-checkout-tmp-$$
 
+    # Test whether we have write permission in the store.  If not,
+    # fetch to /tmp and don't copy to the store.  This is a hack to
+    # make this script at least work somewhat in setuid installations.
+    if ! touch $tmpPath1 2> /dev/null; then
+        echo "(cannot write to the store, result won't be cached)" >&2
+        dummyMode=1
+        tmpPath1=/tmp/nix-prefetch-svn-$$ # !!! security?
+    fi
+
     # Perform the checkout.
     svn export -r "$rev" "$url" $tmpPath1 >&2
 
@@ -32,9 +41,10 @@ if test -z "$hash"; then
     echo "hash is $hash" >&2
 
     # Rename it so that the fetchsvn builder can find it.
-    tmpPath2=$storeDir/svn-checkout-tmp-$hash
-    test -e $tmpPath2 || mv $tmpPath1 $tmpPath2 # !!! race
-
+    if test "$dummyMode" != 1; then
+        tmpPath2=$storeDir/svn-checkout-tmp-$hash
+        test -e $tmpPath2 || mv $tmpPath1 $tmpPath2 # !!! race
+    fi
 fi
 
 # Create a Nix expression that does a fetchsvn.
@@ -44,12 +54,12 @@ storeExpr=$( \
   | nix-instantiate -)
 
 # Realise it.
-finalPath=$(nix-store -qnB --force-realise $storeExpr)
+finalPath=$(nix-store -r $storeExpr)
 
 echo "path is $finalPath" >&2
 
-if test -n "$tmpPath2"; then
-    rm -rf $tmpPath2 || true
+if test -n "$tmpPath1" -o -n "$tmpPath2"; then
+    rm -rf $tmpPath1 $tmpPath2 || true
 fi
 
 echo $hash