Fix windows 7z unzip strip function, fix windows pkg extract files path

This commit is contained in:
crazywhalecc 2025-10-21 15:50:12 +08:00
parent 487980c9a8
commit dd752cd5be
No known key found for this signature in database
GPG Key ID: 1F4BDD59391F2680
3 changed files with 34 additions and 16 deletions

3
.gitignore vendored
View File

@ -22,6 +22,9 @@ docker/source/
# default package root directory
/pkgroot/**
# Windows PHP SDK binary tools
/php-sdk-binary-tools/**
# default pack:lib and release directory
/dist/**
packlib_files.txt

View File

@ -23,8 +23,8 @@
"type": "url",
"url": "https://dl.static-php.dev/static-php-cli/deps/nasm/nasm-2.16.01-win64.zip",
"extract-files": {
"nasm-2.16.01/nasm.exe": "{php_sdk_path}/bin/nasm.exe",
"nasm-2.16.01/ndisasm.exe": "{php_sdk_path}/bin/ndisasm.exe"
"nasm.exe": "{php_sdk_path}/bin/nasm.exe",
"ndisasm.exe": "{php_sdk_path}/bin/ndisasm.exe"
}
},
"pkg-config-aarch64-linux": {
@ -84,7 +84,7 @@
"repo": "upx/upx",
"match": "upx.+-win64\\.zip",
"extract-files": {
"upx-*-win64/upx.exe": "{pkg_root_path}/bin/upx.exe"
"upx.exe": "{pkg_root_path}/bin/upx.exe"
}
},
"zig-aarch64-linux": {

View File

@ -635,7 +635,7 @@ class FileSystem
private static function extractWithType(string $source_type, string $filename, string $extract_path): void
{
logger()->debug('Extracting source [' . $source_type . ']: ' . $filename);
logger()->debug("Extracting source [{$source_type}]: {$filename}");
/* @phpstan-ignore-next-line */
match ($source_type) {
SPC_SOURCE_ARCHIVE => self::extractArchive($filename, $extract_path),
@ -680,23 +680,38 @@ class FileSystem
if (count($contents) === 1 && is_dir($subdir)) {
rename($subdir, $extract_path);
} else {
// else, move all contents to extract_path
self::createDir($extract_path);
// else, if it contains only one dir, strip dir and copy other files
$dircount = 0;
$dir = [];
$top_files = [];
foreach ($contents as $item) {
$subdir = self::convertPath("{$temp_dir}/{$item}");
if (is_dir($subdir)) {
// move all dir contents to extract_path (strip top-level)
$sub_contents = self::scanDirFiles($subdir, false, true, true);
if ($sub_contents === false) {
throw new FileSystemException('Cannot scan unzip temp sub-dir: ' . $subdir);
}
foreach ($sub_contents as $sub_item) {
rename(self::convertPath("{$subdir}/{$sub_item}"), self::convertPath("{$extract_path}/{$sub_item}"));
}
if (is_dir(self::convertPath("{$temp_dir}/{$item}"))) {
++$dircount;
$dir[] = $item;
} else {
$top_files[] = $item;
}
}
// extract dir contents to extract_path
self::createDir($extract_path);
// extract move dir
if ($dircount === 1) {
$sub_contents = self::scanDirFiles("{$temp_dir}/{$dir[0]}", false, true, true);
if ($sub_contents === false) {
throw new FileSystemException("Cannot scan unzip temp sub-dir: {$dir[0]}");
}
foreach ($sub_contents as $sub_item) {
rename(self::convertPath("{$temp_dir}/{$dir[0]}/{$sub_item}"), self::convertPath("{$extract_path}/{$sub_item}"));
}
} else {
foreach ($dir as $item) {
rename(self::convertPath("{$temp_dir}/{$item}"), self::convertPath("{$extract_path}/{$item}"));
}
}
// move top-level files to extract_path
foreach ($top_files as $top_file) {
rename(self::convertPath("{$temp_dir}/{$top_file}"), self::convertPath("{$extract_path}/{$top_file}"));
}
}
}
}