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:
Charles Strahan 2015-01-23 00:31:29 -05:00
parent 4a3e689519
commit fc01353703

View File

@ -23,22 +23,31 @@ lib.overrideDerivation (fetchurl ({
'' ''
export PATH=${unzip}/bin:$PATH export PATH=${unzip}/bin:$PATH
mkdir $out mkdir $out
cd $out
renamed="$TMPDIR/${baseNameOf url}" unpackDir="$TMPDIR/unpack"
mkdir "$unpackDir"
cd "$unpackDir"
renamed="$TMPDIR/$name"
mv "$downloadedFile" "$renamed" mv "$downloadedFile" "$renamed"
unpackFile "$renamed" unpackFile "$renamed"
''
# FIXME: handle zip files that contain a single regular file.
+ lib.optionalString stripRoot ''
shopt -s dotglob 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 exit 1
fi fi
fn=$(cd "$out" && echo *) fn=$(cd "$unpackDir" && echo *)
mv $out/$fn/* "$out/" if [ -f "$unpackDir/$fn" ]; then
rmdir "$out/$fn" mv "$unpackDir/$fn" "$out"
''; else
} // args)) mv "$unpackDir/$fn"/* "$out/"
fi
'' else ''
mv "$unpackDir"/* "$out/"
'');
} // removeAttrs args [ "stripRoot" ]))
# Hackety-hack: we actually need unzip hooks, too # Hackety-hack: we actually need unzip hooks, too
(x: {nativeBuildInputs = x.nativeBuildInputs++ [unzip];}) (x: {nativeBuildInputs = x.nativeBuildInputs++ [unzip];})