mirror of
https://github.com/NixOS/nixpkgs.git
synced 2026-10-30 16:10:36 +00:00
_7zz: speculatively try unpacking any file (#566897)
This commit is contained in:
@@ -22,6 +22,7 @@
|
||||
|
||||
# For tests
|
||||
testers,
|
||||
fetchurl,
|
||||
}:
|
||||
|
||||
let
|
||||
@@ -165,9 +166,83 @@ stdenv.mkDerivation (finalAttrs: {
|
||||
extraArgs = [ "--version=skip" ];
|
||||
})
|
||||
];
|
||||
tests.version = testers.testVersion {
|
||||
package = finalAttrs.finalPackage;
|
||||
command = "7zz --help";
|
||||
tests = {
|
||||
version = testers.testVersion {
|
||||
package = finalAttrs.finalPackage;
|
||||
command = "7zz --help";
|
||||
};
|
||||
# So dmg can be tested on Linux without
|
||||
# macos toolchains
|
||||
undmg = stdenv.mkDerivation {
|
||||
pname = "test-undmg";
|
||||
version = "none";
|
||||
|
||||
src = fetchurl {
|
||||
url = "https://caido.download/releases/v0.57.0/caido-desktop-v0.57.0-mac-aarch64.dmg";
|
||||
hash = "sha256-GmpMnaGR7gYz1RvSO5xj9AA3xU1mn2IBInakmVkuG7A=";
|
||||
};
|
||||
|
||||
nativeBuildInputs = [
|
||||
finalAttrs.finalPackage
|
||||
];
|
||||
|
||||
buildPhase = ''
|
||||
if [[ ! -e Contents ]]; then
|
||||
# Should exist
|
||||
ls
|
||||
exit 1
|
||||
fi
|
||||
'';
|
||||
installPhase = "touch $out";
|
||||
};
|
||||
|
||||
unzip = stdenv.mkDerivation {
|
||||
pname = "test-unzip";
|
||||
version = "none";
|
||||
|
||||
src = fetchurl {
|
||||
url = "mirror://sourceforge/libjson/libjson_7.6.1.zip";
|
||||
hash = "sha256-ByZ6OVEDjuLgLSbMQb+OJ1Zow491EkDT543JeRguc3Y=";
|
||||
};
|
||||
|
||||
nativeBuildInputs = [
|
||||
finalAttrs.finalPackage
|
||||
];
|
||||
|
||||
buildPhase = ''
|
||||
if [[ ! -e libjson.h ]]; then
|
||||
# Should exist
|
||||
ls
|
||||
exit 1
|
||||
fi
|
||||
'';
|
||||
installPhase = "touch $out";
|
||||
};
|
||||
|
||||
# We do not want to decompress tarballs since
|
||||
# it will just leave an uncompressed tarball in the source dir.
|
||||
tarballs = stdenv.mkDerivation {
|
||||
pname = "test-tarball";
|
||||
version = "none";
|
||||
|
||||
src = fetchurl {
|
||||
url = "https://github.com/ip7z/7zip/archive/refs/tags/26.04.tar.gz";
|
||||
hash = "sha256-SP3G3+h57i24Z7sH8ZxKlAa/6gHVH0h4W2x6E3iB4lw=";
|
||||
};
|
||||
|
||||
nativeBuildInputs = [
|
||||
finalAttrs.finalPackage
|
||||
];
|
||||
|
||||
buildPhase = ''
|
||||
if [[ ! -e README.md ]]; then
|
||||
# Should exist
|
||||
ls
|
||||
exit 1
|
||||
fi
|
||||
'';
|
||||
installPhase = "touch $out";
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
@@ -1,5 +1,27 @@
|
||||
unpackCmdHooks+=(_tryUnpackDmg)
|
||||
_tryUnpackDmg() {
|
||||
if ! [[ "$curSrc" =~ \.dmg$ ]]; then return 1; fi
|
||||
7zz x -sns- -snld "$curSrc"
|
||||
unpackCmdHooks+=(_tryUnpack7zip)
|
||||
|
||||
# 7zip supports unpacking many formats.
|
||||
# No need to implement our own inaccurate extension-based detection.
|
||||
_tryUnpack7zip() {
|
||||
local mime="$(file -zb --mime-type "$curSrc")"
|
||||
|
||||
if [[ "$mime" == "application/x-tar" ]]; then
|
||||
# Compressed tarballs should use tar instead, and 7zip doesn't
|
||||
# recursively unpack. So it would just leave a .tar file in
|
||||
# the build directory
|
||||
return 1
|
||||
fi
|
||||
|
||||
local flags=(
|
||||
"-bso0" # Disable stdout
|
||||
"-bsp0" # Disable progress output
|
||||
"-bse0" # Disable stderr output
|
||||
"-sns-" # Ignore auxilliary filesystem streams
|
||||
# Allow 'dangerous' links, which are links that include '..'
|
||||
# This does not include absolute paths and links that escape the archive,
|
||||
# those require a higher 'dangerous level'.
|
||||
"-snld"
|
||||
"-y" # Accept all prompts
|
||||
)
|
||||
7zz x "${flags[@]}" "$curSrc"
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user