* Make nix-prefetch-svn use nix-store --add-fixed (just like
nix-prefetch-url) svn path=/nixpkgs/trunk/; revision=5339
This commit is contained in:
parent
9ece10787e
commit
c4c224e368
|
@ -2,10 +2,15 @@
|
||||||
|
|
||||||
url=$1
|
url=$1
|
||||||
rev=$2
|
rev=$2
|
||||||
hash=$3
|
expHash=$3
|
||||||
|
|
||||||
|
hashType=$NIX_HASH_ALGO
|
||||||
|
if test -z "$hashType"; then
|
||||||
|
hashType=md5
|
||||||
|
fi
|
||||||
|
|
||||||
if test -z "$url"; then
|
if test -z "$url"; then
|
||||||
echo "syntax: nix-prefetch-svn URL [REVISION]" >&2
|
echo "syntax: nix-prefetch-svn URL [REVISION [EXPECTED-HASH]]" >&2
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
@ -15,58 +20,46 @@ test -n "$rev" || rev="HEAD"
|
||||||
# is not group- or world-writable. Nix 0.10 complains about this.
|
# is not group- or world-writable. Nix 0.10 complains about this.
|
||||||
umask 0022
|
umask 0022
|
||||||
|
|
||||||
# Determine the hash, unless it was given.
|
|
||||||
if test -z "$hash"; then
|
|
||||||
|
|
||||||
# !!! hacky; we should have a way to query the location of the store.
|
# If the hash was given, a file with that hash may already be in the
|
||||||
if storeDir=$(which nix-store); then
|
# store.
|
||||||
storeDir=$(dirname $(dirname "$storeDir"))/store
|
if test -n "$expHash"; then
|
||||||
else
|
finalPath=$(nix-store --print-fixed-path --recursive "$hashType" "$expHash" svn-export)
|
||||||
storeDir=/nix/store
|
if ! nix-store --check-validity "$finalPath" 2> /dev/null; then
|
||||||
|
finalPath=
|
||||||
fi
|
fi
|
||||||
|
hash=$expHash
|
||||||
|
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
|
||||||
|
|
||||||
# !!! race? should be relatively safe, `svn export' barfs if $tmpPath exists.
|
# !!! race? should be relatively safe, `svn export' barfs if $tmpPath exists.
|
||||||
tmpPath1=$storeDir/svn-checkout-tmp-$$
|
tmpPath=/tmp/svn-checkout-tmp-$$
|
||||||
|
tmpFile=$tmpPath/svn-export
|
||||||
# Test whether we have write permission in the store. If not,
|
mkdir $tmpPath
|
||||||
# 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
|
|
||||||
rm -f $tmpPath1
|
|
||||||
|
|
||||||
# Perform the checkout.
|
# Perform the checkout.
|
||||||
svn export -r "$rev" "$url" $tmpPath1 >&2
|
svn export -r "$rev" "$url" $tmpFile >&2
|
||||||
|
|
||||||
# Compute the hash.
|
# Compute the hash.
|
||||||
hash=$(nix-hash $tmpPath1)
|
hash=$(nix-hash --type $hashType $hashFormat $tmpFile)
|
||||||
echo "hash is $hash" >&2
|
if ! test -n "$QUIET"; then echo "hash is $hash" >&2; fi
|
||||||
|
|
||||||
# Rename it so that the fetchsvn builder can find it.
|
# Add the downloaded file to the Nix store.
|
||||||
if test "$dummyMode" != 1; then
|
finalPath=$(nix-store --add-fixed --recursive "$hashType" $tmpFile)
|
||||||
tmpPath2=$storeDir/svn-checkout-tmp-$hash
|
|
||||||
test -e $tmpPath2 || mv $tmpPath1 $tmpPath2 # !!! race
|
if test -n "$tmpPath"; then rm -rf $tmpPath || true; fi
|
||||||
|
|
||||||
|
if test -n "$expHash" -a "$expHash" != "$hash"; then
|
||||||
|
echo "hash mismatch for URL \`$url'"
|
||||||
|
exit 1
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Create a Nix expression that does a fetchsvn.
|
if ! test -n "$QUIET"; then echo "path is $finalPath" >&2; fi
|
||||||
scriptDir=$(dirname $(readlink -f $0 2> /dev/null || echo $0))
|
|
||||||
nixExpr=$scriptDir/../../top-level/all-packages.nix
|
|
||||||
storeExpr=$( \
|
|
||||||
echo "(import $nixExpr {}).fetchsvn {url=\"$url\"; rev=\"$rev\"; md5=\"$hash\";}" \
|
|
||||||
| nix-instantiate -)
|
|
||||||
|
|
||||||
# Realise it.
|
|
||||||
finalPath=$(nix-store -r $storeExpr)
|
|
||||||
|
|
||||||
echo "path is $finalPath" >&2
|
|
||||||
|
|
||||||
if test -n "$tmpPath1" -o -n "$tmpPath2"; then
|
|
||||||
rm -rf $tmpPath1 $tmpPath2 || true
|
|
||||||
fi
|
|
||||||
|
|
||||||
echo $hash
|
echo $hash
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue