summary refs log tree commit diff
path: root/pkgs/build-support/fetchzip
diff options
context:
space:
mode:
authorCharles Strahan <charles.c.strahan@gmail.com>2015-01-23 00:31:29 -0500
committerCharles Strahan <charles.c.strahan@gmail.com>2015-01-23 17:10:40 -0500
commitfc01353703426458d6990239936659ed3130d294 (patch)
tree6178b58ef9050281a5d5703795b45cfd0993e249 /pkgs/build-support/fetchzip
parent4a3e68951976c08a6b59d95d252cec5acb38f1b4 (diff)
downloadnixpkgs-fc01353703426458d6990239936659ed3130d294.tar
nixpkgs-fc01353703426458d6990239936659ed3130d294.tar.gz
nixpkgs-fc01353703426458d6990239936659ed3130d294.tar.bz2
nixpkgs-fc01353703426458d6990239936659ed3130d294.tar.lz
nixpkgs-fc01353703426458d6990239936659ed3130d294.tar.xz
nixpkgs-fc01353703426458d6990239936659ed3130d294.tar.zst
nixpkgs-fc01353703426458d6990239936659ed3130d294.zip
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
Diffstat (limited to 'pkgs/build-support/fetchzip')
-rw-r--r--pkgs/build-support/fetchzip/default.nix33
1 files changed, 21 insertions, 12 deletions
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];})