mirror of
https://github.com/NixOS/nixpkgs.git
synced 2024-11-22 06:53:01 +00:00
fetchzip: various fixes
This fixes: * Passing stripRoot. * Archives containing a single file. * Archives where the root folder has the same name as one of it's children. Fixes #5851
This commit is contained in:
parent
4a3e689519
commit
fc01353703
@ -23,22 +23,31 @@ lib.overrideDerivation (fetchurl ({
|
||||
''
|
||||
export PATH=${unzip}/bin:$PATH
|
||||
mkdir $out
|
||||
cd $out
|
||||
renamed="$TMPDIR/${baseNameOf url}"
|
||||
|
||||
unpackDir="$TMPDIR/unpack"
|
||||
mkdir "$unpackDir"
|
||||
cd "$unpackDir"
|
||||
|
||||
renamed="$TMPDIR/$name"
|
||||
mv "$downloadedFile" "$renamed"
|
||||
unpackFile "$renamed"
|
||||
''
|
||||
# FIXME: handle zip files that contain a single regular file.
|
||||
+ lib.optionalString stripRoot ''
|
||||
|
||||
shopt -s dotglob
|
||||
if [ "$(ls -d $out/* | wc -l)" != 1 ]; then
|
||||
echo "error: zip file must contain a single directory."
|
||||
''
|
||||
+ (if stripRoot then ''
|
||||
if [ $(ls "$unpackDir" | wc -l) != 1 ]; then
|
||||
echo "error: zip file must contain a single file or directory."
|
||||
exit 1
|
||||
fi
|
||||
fn=$(cd "$out" && echo *)
|
||||
mv $out/$fn/* "$out/"
|
||||
rmdir "$out/$fn"
|
||||
'';
|
||||
} // args))
|
||||
fn=$(cd "$unpackDir" && echo *)
|
||||
if [ -f "$unpackDir/$fn" ]; then
|
||||
mv "$unpackDir/$fn" "$out"
|
||||
else
|
||||
mv "$unpackDir/$fn"/* "$out/"
|
||||
fi
|
||||
'' else ''
|
||||
mv "$unpackDir"/* "$out/"
|
||||
'');
|
||||
} // removeAttrs args [ "stripRoot" ]))
|
||||
# Hackety-hack: we actually need unzip hooks, too
|
||||
(x: {nativeBuildInputs = x.nativeBuildInputs++ [unzip];})
|
||||
|
Loading…
Reference in New Issue
Block a user