From dd752cd5be23c51a0dbcab3294261b4ae816fcf2 Mon Sep 17 00:00:00 2001 From: crazywhalecc Date: Tue, 21 Oct 2025 15:50:12 +0800 Subject: [PATCH] Fix windows 7z unzip strip function, fix windows pkg extract files path --- .gitignore | 3 +++ config/pkg.json | 6 +++--- src/SPC/store/FileSystem.php | 41 ++++++++++++++++++++++++------------ 3 files changed, 34 insertions(+), 16 deletions(-) diff --git a/.gitignore b/.gitignore index 4bf41b55..0d2bd554 100644 --- a/.gitignore +++ b/.gitignore @@ -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 diff --git a/config/pkg.json b/config/pkg.json index 00e83595..d3b4fb90 100644 --- a/config/pkg.json +++ b/config/pkg.json @@ -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": { diff --git a/src/SPC/store/FileSystem.php b/src/SPC/store/FileSystem.php index 9cbd68b7..e66aee0a 100644 --- a/src/SPC/store/FileSystem.php +++ b/src/SPC/store/FileSystem.php @@ -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}")); + } } } }