Fix mingw patch paths

This commit is contained in:
crazywhalecc
2026-07-06 19:10:10 +08:00
parent ab37b34fb5
commit fa040bc346
2 changed files with 6 additions and 4 deletions

View File

@@ -174,7 +174,7 @@ class FileSystem
public static function convertWinPathToMinGW(string $path): string public static function convertWinPathToMinGW(string $path): string
{ {
if (preg_match('/^[A-Za-z]:/', $path)) { 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; return $path;
} }

View File

@@ -48,13 +48,14 @@ class SourcePatcher
$patch_cwd = FileSystem::convertPath($cwd); $patch_cwd = FileSystem::convertPath($cwd);
$patch_arg = $patch_str; $patch_arg = $patch_str;
if (PHP_OS_FAMILY === 'Windows') { if (PHP_OS_FAMILY === 'Windows') {
$patch_cwd = FileSystem::convertWinPathToMinGW($patch_cwd);
$patch_arg = FileSystem::convertWinPathToMinGW($patch_arg); $patch_arg = FileSystem::convertWinPathToMinGW($patch_arg);
} }
// Detect if patch is already applied (reverse detection) // Detect if patch is already applied (reverse detection)
$detect_reverse = !$reverse; $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) . ' -i ' . escapeshellarg($patch_arg)
. ($detect_reverse ? ' -R' : '') . ($detect_reverse ? ' -R' : '')
. ' > ' . (PHP_OS_FAMILY === 'Windows' ? 'NUL' : '/dev/null') . ' 2>&1'; . ' > ' . (PHP_OS_FAMILY === 'Windows' ? 'NUL' : '/dev/null') . ' 2>&1';
@@ -66,7 +67,8 @@ class SourcePatcher
} }
// Apply patch // Apply patch
$apply_cmd = 'patch -p1 -d ' . escapeshellarg($patch_cwd) $apply_cmd = $cd_cmd
. ' && patch -p1'
. ' -i ' . escapeshellarg($patch_arg) . ' -i ' . escapeshellarg($patch_arg)
. ($reverse ? ' -R' : ''); . ($reverse ? ' -R' : '');