From 5a21da7fa960fdcd77f0424197a8203dd196d430 Mon Sep 17 00:00:00 2001 From: David Sherret Date: Tue, 26 Sep 2023 14:46:29 -0400 Subject: [PATCH 1/2] fix(upgrade): output unpack failure --- cli/tools/upgrade.rs | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/cli/tools/upgrade.rs b/cli/tools/upgrade.rs index c0fbb73ce2c419..89951fc9f01980 100644 --- a/cli/tools/upgrade.rs +++ b/cli/tools/upgrade.rs @@ -491,7 +491,7 @@ pub fn unpack_into_dir( archive_data: Vec, is_windows: bool, temp_dir: &tempfile::TempDir, -) -> Result { +) -> Result { const EXE_NAME: &str = "deno"; let temp_dir_path = temp_dir.path(); let exe_ext = if is_windows { "exe" } else { "" }; @@ -503,7 +503,7 @@ pub fn unpack_into_dir( .extension() .and_then(|ext| ext.to_str()) .unwrap(); - let unpack_status = match archive_ext { + let output = match archive_ext { "zip" if cfg!(windows) => { fs::write(&archive_path, &archive_data)?; Command::new("powershell.exe") @@ -526,7 +526,7 @@ pub fn unpack_into_dir( .arg(format!("'{}'", &archive_path.to_str().unwrap())) .arg("-DestinationPath") .arg(format!("'{}'", &temp_dir_path.to_str().unwrap())) - .spawn() + .output() .map_err(|err| { if err.kind() == std::io::ErrorKind::NotFound { std::io::Error::new( @@ -537,14 +537,13 @@ pub fn unpack_into_dir( err } })? - .wait()? } "zip" => { fs::write(&archive_path, &archive_data)?; Command::new("unzip") .current_dir(temp_dir_path) .arg(&archive_path) - .spawn() + .output() .map_err(|err| { if err.kind() == std::io::ErrorKind::NotFound { std::io::Error::new( @@ -555,11 +554,14 @@ pub fn unpack_into_dir( err } })? - .wait()? } - ext => panic!("Unsupported archive type: '{ext}'"), + ext => bail!("Unsupported archive type: '{ext}'"), }; - assert!(unpack_status.success()); + if !output.status.success() { + eprintln!("{}", String::from_utf8_lossy(&output.stdout)); + eprintln!("{}", String::from_utf8_lossy(&output.stderr)); + bail!("Failed to unpack archive."); + } assert!(exe_path.exists()); fs::remove_file(&archive_path)?; Ok(exe_path) From 6644ffd759572a3290d96266bef3356f9dc073d5 Mon Sep 17 00:00:00 2001 From: David Sherret Date: Tue, 26 Sep 2023 15:01:40 -0400 Subject: [PATCH 2/2] Revert. --- cli/tools/upgrade.rs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/cli/tools/upgrade.rs b/cli/tools/upgrade.rs index 89951fc9f01980..366cc7fc45cd9c 100644 --- a/cli/tools/upgrade.rs +++ b/cli/tools/upgrade.rs @@ -503,7 +503,7 @@ pub fn unpack_into_dir( .extension() .and_then(|ext| ext.to_str()) .unwrap(); - let output = match archive_ext { + let unpack_status = match archive_ext { "zip" if cfg!(windows) => { fs::write(&archive_path, &archive_data)?; Command::new("powershell.exe") @@ -526,7 +526,7 @@ pub fn unpack_into_dir( .arg(format!("'{}'", &archive_path.to_str().unwrap())) .arg("-DestinationPath") .arg(format!("'{}'", &temp_dir_path.to_str().unwrap())) - .output() + .spawn() .map_err(|err| { if err.kind() == std::io::ErrorKind::NotFound { std::io::Error::new( @@ -537,13 +537,14 @@ pub fn unpack_into_dir( err } })? + .wait()? } "zip" => { fs::write(&archive_path, &archive_data)?; Command::new("unzip") .current_dir(temp_dir_path) .arg(&archive_path) - .output() + .spawn() .map_err(|err| { if err.kind() == std::io::ErrorKind::NotFound { std::io::Error::new( @@ -554,12 +555,11 @@ pub fn unpack_into_dir( err } })? + .wait()? } ext => bail!("Unsupported archive type: '{ext}'"), }; - if !output.status.success() { - eprintln!("{}", String::from_utf8_lossy(&output.stdout)); - eprintln!("{}", String::from_utf8_lossy(&output.stderr)); + if !unpack_status.success() { bail!("Failed to unpack archive."); } assert!(exe_path.exists());