mirror of
https://github.com/crazywhalecc/static-php-cli.git
synced 2026-03-18 04:44:53 +08:00
Fix windows 7z unzip strip function, fix windows pkg extract files path
This commit is contained in:
parent
487980c9a8
commit
dd752cd5be
3
.gitignore
vendored
3
.gitignore
vendored
@ -22,6 +22,9 @@ docker/source/
|
|||||||
# default package root directory
|
# default package root directory
|
||||||
/pkgroot/**
|
/pkgroot/**
|
||||||
|
|
||||||
|
# Windows PHP SDK binary tools
|
||||||
|
/php-sdk-binary-tools/**
|
||||||
|
|
||||||
# default pack:lib and release directory
|
# default pack:lib and release directory
|
||||||
/dist/**
|
/dist/**
|
||||||
packlib_files.txt
|
packlib_files.txt
|
||||||
|
|||||||
@ -23,8 +23,8 @@
|
|||||||
"type": "url",
|
"type": "url",
|
||||||
"url": "https://dl.static-php.dev/static-php-cli/deps/nasm/nasm-2.16.01-win64.zip",
|
"url": "https://dl.static-php.dev/static-php-cli/deps/nasm/nasm-2.16.01-win64.zip",
|
||||||
"extract-files": {
|
"extract-files": {
|
||||||
"nasm-2.16.01/nasm.exe": "{php_sdk_path}/bin/nasm.exe",
|
"nasm.exe": "{php_sdk_path}/bin/nasm.exe",
|
||||||
"nasm-2.16.01/ndisasm.exe": "{php_sdk_path}/bin/ndisasm.exe"
|
"ndisasm.exe": "{php_sdk_path}/bin/ndisasm.exe"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"pkg-config-aarch64-linux": {
|
"pkg-config-aarch64-linux": {
|
||||||
@ -84,7 +84,7 @@
|
|||||||
"repo": "upx/upx",
|
"repo": "upx/upx",
|
||||||
"match": "upx.+-win64\\.zip",
|
"match": "upx.+-win64\\.zip",
|
||||||
"extract-files": {
|
"extract-files": {
|
||||||
"upx-*-win64/upx.exe": "{pkg_root_path}/bin/upx.exe"
|
"upx.exe": "{pkg_root_path}/bin/upx.exe"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"zig-aarch64-linux": {
|
"zig-aarch64-linux": {
|
||||||
|
|||||||
@ -635,7 +635,7 @@ class FileSystem
|
|||||||
|
|
||||||
private static function extractWithType(string $source_type, string $filename, string $extract_path): void
|
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 */
|
/* @phpstan-ignore-next-line */
|
||||||
match ($source_type) {
|
match ($source_type) {
|
||||||
SPC_SOURCE_ARCHIVE => self::extractArchive($filename, $extract_path),
|
SPC_SOURCE_ARCHIVE => self::extractArchive($filename, $extract_path),
|
||||||
@ -680,23 +680,38 @@ class FileSystem
|
|||||||
if (count($contents) === 1 && is_dir($subdir)) {
|
if (count($contents) === 1 && is_dir($subdir)) {
|
||||||
rename($subdir, $extract_path);
|
rename($subdir, $extract_path);
|
||||||
} else {
|
} else {
|
||||||
// else, move all contents to extract_path
|
// else, if it contains only one dir, strip dir and copy other files
|
||||||
self::createDir($extract_path);
|
$dircount = 0;
|
||||||
|
$dir = [];
|
||||||
|
$top_files = [];
|
||||||
foreach ($contents as $item) {
|
foreach ($contents as $item) {
|
||||||
$subdir = self::convertPath("{$temp_dir}/{$item}");
|
if (is_dir(self::convertPath("{$temp_dir}/{$item}"))) {
|
||||||
if (is_dir($subdir)) {
|
++$dircount;
|
||||||
// move all dir contents to extract_path (strip top-level)
|
$dir[] = $item;
|
||||||
$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}"));
|
|
||||||
}
|
|
||||||
} else {
|
} 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}"));
|
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}"));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user