Skip to content

Commit

Permalink
fix(upgrade): use tar.exe to extract on Windows (#20711)
Browse files Browse the repository at this point in the history
This is what we do for deno install, so it should be fine here
denoland/deno_install#219

Closes #20683
  • Loading branch information
dsherret authored Sep 27, 2023
1 parent 31991e2 commit 35fad4d
Showing 1 changed file with 7 additions and 22 deletions.
29 changes: 7 additions & 22 deletions cli/tools/upgrade.rs
Original file line number Diff line number Diff line change
Expand Up @@ -481,7 +481,7 @@ async fn download_package(
match maybe_bytes {
Some(bytes) => Ok(bytes),
None => {
log::info!("Download could not be found, aborting");
log::error!("Download could not be found, aborting");
std::process::exit(1)
}
}
Expand All @@ -506,32 +506,17 @@ pub fn unpack_into_dir(
let unpack_status = match archive_ext {
"zip" if cfg!(windows) => {
fs::write(&archive_path, &archive_data)?;
Command::new("powershell.exe")
.arg("-NoLogo")
.arg("-NoProfile")
.arg("-NonInteractive")
.arg("-Command")
.arg(
"& {
param($Path, $DestinationPath)
trap { $host.ui.WriteErrorLine($_.Exception); exit 1 }
Add-Type -AssemblyName System.IO.Compression.FileSystem
[System.IO.Compression.ZipFile]::ExtractToDirectory(
$Path,
$DestinationPath
);
}",
)
.arg("-Path")
.arg(format!("'{}'", &archive_path.to_str().unwrap()))
.arg("-DestinationPath")
.arg(format!("'{}'", &temp_dir_path.to_str().unwrap()))
Command::new("tar.exe")
.arg("xf")
.arg(&archive_path)
.arg("-C")
.arg(temp_dir_path)
.spawn()
.map_err(|err| {
if err.kind() == std::io::ErrorKind::NotFound {
std::io::Error::new(
std::io::ErrorKind::NotFound,
"`powershell.exe` was not found in your PATH",
"`tar.exe` was not found in your PATH",
)
} else {
err
Expand Down

0 comments on commit 35fad4d

Please sign in to comment.