Fix tar command for unix

This commit is contained in:
crazywhalecc
2026-03-24 13:30:17 +08:00
parent 93c099dd31
commit b625d80dc0

View File

@@ -6,6 +6,7 @@ namespace StaticPHP\Runtime\Shell;
use StaticPHP\Exception\InterruptException; use StaticPHP\Exception\InterruptException;
use StaticPHP\Exception\SPCInternalException; use StaticPHP\Exception\SPCInternalException;
use StaticPHP\Runtime\SystemTarget;
use StaticPHP\Util\FileSystem; use StaticPHP\Util\FileSystem;
/** /**
@@ -132,7 +133,8 @@ class DefaultShell extends Shell
}; };
$mute = $this->console_putput ? '' : ' 2>/dev/null'; $mute = $this->console_putput ? '' : ' 2>/dev/null';
$cmd = "\"C:\\Windows\\system32\\tar.exe\" {$compression_flag}xf {$archive_arg} --strip-components {$strip} -C {$target_arg}{$mute}"; $tar = SystemTarget::isUnix() ? 'tar' : '"C:\\Windows\\system32\\tar.exe"';
$cmd = "{$tar} {$compression_flag}xf {$archive_arg} --strip-components {$strip} -C {$target_arg}{$mute}";
$this->logCommandInfo($cmd); $this->logCommandInfo($cmd);
logger()->debug("[TAR EXTRACT] {$cmd}"); logger()->debug("[TAR EXTRACT] {$cmd}");
@@ -185,9 +187,11 @@ class DefaultShell extends Shell
}; };
$extname = FileSystem::extname($archive_path); $extname = FileSystem::extname($archive_path);
$tar = SystemTarget::isUnix() ? 'tar' : '"C:\\Windows\\system32\\tar.exe"';
match ($extname) { match ($extname) {
'tar' => $this->executeTarExtract($archive_path, $target_path, 'none'), 'tar' => $this->executeTarExtract($archive_path, $target_path, 'none'),
'gz', 'tgz', 'xz', 'txz', 'bz2' => $run("{$_7z} x -so {$archive_arg} | \"C:\\Windows\\system32\\tar.exe\" -f - -x -C {$target_arg} --strip-components 1"), 'gz', 'tgz', 'xz', 'txz', 'bz2' => $run("{$_7z} x -so {$archive_arg} | {$tar} -f - -x -C {$target_arg} --strip-components 1"),
default => $run("{$_7z} x {$archive_arg} -o{$target_arg} -y{$mute}"), default => $run("{$_7z} x {$archive_arg} -o{$target_arg} -y{$mute}"),
}; };