diff --git a/src/StaticPHP/Util/FileSystem.php b/src/StaticPHP/Util/FileSystem.php index ad41425c..3bf12f99 100644 --- a/src/StaticPHP/Util/FileSystem.php +++ b/src/StaticPHP/Util/FileSystem.php @@ -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; } diff --git a/src/StaticPHP/Util/SourcePatcher.php b/src/StaticPHP/Util/SourcePatcher.php index de0f1d36..c12717c2 100644 --- a/src/StaticPHP/Util/SourcePatcher.php +++ b/src/StaticPHP/Util/SourcePatcher.php @@ -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' : '');