From fc01353703426458d6990239936659ed3130d294 Mon Sep 17 00:00:00 2001 From: Charles Strahan Date: Fri, 23 Jan 2015 00:31:29 -0500 Subject: 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 --- pkgs/build-support/fetchzip/default.nix | 33 +++++++++++++++++++++------------ 1 file changed, 21 insertions(+), 12 deletions(-) (limited to 'pkgs/build-support/fetchzip') diff --git a/pkgs/build-support/fetchzip/default.nix b/pkgs/build-support/fetchzip/default.nix index dd927ed8363..ffdf45a1865 100644 --- a/pkgs/build-support/fetchzip/default.nix +++ b/pkgs/build-support/fetchzip/default.nix @@ -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];}) -- cgit 1.4.1