mirror of
https://github.com/crazywhalecc/static-php-cli.git
synced 2026-07-07 00:35:41 +08:00
Fix mingw patch paths
This commit is contained in:
@@ -174,7 +174,7 @@ class FileSystem
|
||||
public static function convertWinPathToMinGW(string $path): string
|
||||
{
|
||||
if (preg_match('/^[A-Za-z]:/', $path)) {
|
||||
$path = '/' . strtolower($path[0]) . '/' . str_replace('\\', '/', substr($path, 2));
|
||||
$path = '/' . strtolower($path[0]) . '/' . str_replace('\\', '/', ltrim(substr($path, 2), '\/'));
|
||||
}
|
||||
return $path;
|
||||
}
|
||||
|
||||
@@ -48,13 +48,14 @@ class SourcePatcher
|
||||
$patch_cwd = FileSystem::convertPath($cwd);
|
||||
$patch_arg = $patch_str;
|
||||
if (PHP_OS_FAMILY === 'Windows') {
|
||||
$patch_cwd = FileSystem::convertWinPathToMinGW($patch_cwd);
|
||||
$patch_arg = FileSystem::convertWinPathToMinGW($patch_arg);
|
||||
}
|
||||
|
||||
// Detect if patch is already applied (reverse detection)
|
||||
$detect_reverse = !$reverse;
|
||||
$detect_cmd = 'patch --dry-run -p1 -s -f -d ' . escapeshellarg($patch_cwd)
|
||||
$cd_cmd = (PHP_OS_FAMILY === 'Windows' ? 'cd /d ' : 'cd ') . escapeshellarg($patch_cwd);
|
||||
$detect_cmd = $cd_cmd
|
||||
. ' && patch --dry-run -p1 -s -f'
|
||||
. ' -i ' . escapeshellarg($patch_arg)
|
||||
. ($detect_reverse ? ' -R' : '')
|
||||
. ' > ' . (PHP_OS_FAMILY === 'Windows' ? 'NUL' : '/dev/null') . ' 2>&1';
|
||||
@@ -66,7 +67,8 @@ class SourcePatcher
|
||||
}
|
||||
|
||||
// Apply patch
|
||||
$apply_cmd = 'patch -p1 -d ' . escapeshellarg($patch_cwd)
|
||||
$apply_cmd = $cd_cmd
|
||||
. ' && patch -p1'
|
||||
. ' -i ' . escapeshellarg($patch_arg)
|
||||
. ($reverse ? ' -R' : '');
|
||||
|
||||
|
||||
Reference in New Issue
Block a user