Skip to content

Commit dd752cd

Browse files
committed
Fix windows 7z unzip strip function, fix windows pkg extract files path
1 parent 487980c commit dd752cd

File tree

3 files changed

+34
-16
lines changed

3 files changed

+34
-16
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@ docker/source/
2222
# default package root directory
2323
/pkgroot/**
2424

25+
# Windows PHP SDK binary tools
26+
/php-sdk-binary-tools/**
27+
2528
# default pack:lib and release directory
2629
/dist/**
2730
packlib_files.txt

config/pkg.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@
2323
"type": "url",
2424
"url": "https://dl.static-php.dev/static-php-cli/deps/nasm/nasm-2.16.01-win64.zip",
2525
"extract-files": {
26-
"nasm-2.16.01/nasm.exe": "{php_sdk_path}/bin/nasm.exe",
27-
"nasm-2.16.01/ndisasm.exe": "{php_sdk_path}/bin/ndisasm.exe"
26+
"nasm.exe": "{php_sdk_path}/bin/nasm.exe",
27+
"ndisasm.exe": "{php_sdk_path}/bin/ndisasm.exe"
2828
}
2929
},
3030
"pkg-config-aarch64-linux": {
@@ -84,7 +84,7 @@
8484
"repo": "upx/upx",
8585
"match": "upx.+-win64\\.zip",
8686
"extract-files": {
87-
"upx-*-win64/upx.exe": "{pkg_root_path}/bin/upx.exe"
87+
"upx.exe": "{pkg_root_path}/bin/upx.exe"
8888
}
8989
},
9090
"zig-aarch64-linux": {

src/SPC/store/FileSystem.php

Lines changed: 28 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -635,7 +635,7 @@ private static function emitSourceExtractHook(string $name, string $target): voi
635635

636636
private static function extractWithType(string $source_type, string $filename, string $extract_path): void
637637
{
638-
logger()->debug('Extracting source [' . $source_type . ']: ' . $filename);
638+
logger()->debug("Extracting source [{$source_type}]: {$filename}");
639639
/* @phpstan-ignore-next-line */
640640
match ($source_type) {
641641
SPC_SOURCE_ARCHIVE => self::extractArchive($filename, $extract_path),
@@ -680,23 +680,38 @@ private static function unzipWithStrip(string $zip_file, string $extract_path):
680680
if (count($contents) === 1 && is_dir($subdir)) {
681681
rename($subdir, $extract_path);
682682
} else {
683-
// else, move all contents to extract_path
684-
self::createDir($extract_path);
683+
// else, if it contains only one dir, strip dir and copy other files
684+
$dircount = 0;
685+
$dir = [];
686+
$top_files = [];
685687
foreach ($contents as $item) {
686-
$subdir = self::convertPath("{$temp_dir}/{$item}");
687-
if (is_dir($subdir)) {
688-
// move all dir contents to extract_path (strip top-level)
689-
$sub_contents = self::scanDirFiles($subdir, false, true, true);
690-
if ($sub_contents === false) {
691-
throw new FileSystemException('Cannot scan unzip temp sub-dir: ' . $subdir);
692-
}
693-
foreach ($sub_contents as $sub_item) {
694-
rename(self::convertPath("{$subdir}/{$sub_item}"), self::convertPath("{$extract_path}/{$sub_item}"));
695-
}
688+
if (is_dir(self::convertPath("{$temp_dir}/{$item}"))) {
689+
++$dircount;
690+
$dir[] = $item;
696691
} else {
692+
$top_files[] = $item;
693+
}
694+
}
695+
// extract dir contents to extract_path
696+
self::createDir($extract_path);
697+
// extract move dir
698+
if ($dircount === 1) {
699+
$sub_contents = self::scanDirFiles("{$temp_dir}/{$dir[0]}", false, true, true);
700+
if ($sub_contents === false) {
701+
throw new FileSystemException("Cannot scan unzip temp sub-dir: {$dir[0]}");
702+
}
703+
foreach ($sub_contents as $sub_item) {
704+
rename(self::convertPath("{$temp_dir}/{$dir[0]}/{$sub_item}"), self::convertPath("{$extract_path}/{$sub_item}"));
705+
}
706+
} else {
707+
foreach ($dir as $item) {
697708
rename(self::convertPath("{$temp_dir}/{$item}"), self::convertPath("{$extract_path}/{$item}"));
698709
}
699710
}
711+
// move top-level files to extract_path
712+
foreach ($top_files as $top_file) {
713+
rename(self::convertPath("{$temp_dir}/{$top_file}"), self::convertPath("{$extract_path}/{$top_file}"));
714+
}
700715
}
701716
}
702717
}

0 commit comments

Comments
 (0)