0
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2025-03-03 09:31:22 -05:00

fix(compile): fix panic when cross-compiling between windows and unix (#9203)

This commit is contained in:
Liam Murphy 2021-01-24 04:40:13 +11:00 committed by GitHub
parent 1518fabfbb
commit a61389a55e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 8 additions and 3 deletions

View file

@ -48,7 +48,11 @@ pub async fn get_base_binary(
}
let archive_data = tokio::fs::read(binary_path).await?;
let base_binary_path = crate::tools::upgrade::unpack(archive_data, exe_name)?;
let base_binary_path = crate::tools::upgrade::unpack(
archive_data,
exe_name,
target.contains("windows"),
)?;
let base_binary = tokio::fs::read(base_binary_path).await?;
Ok(base_binary)
}

View file

@ -109,7 +109,7 @@ pub async fn upgrade_command(
println!("Deno is upgrading to version {}", &install_version);
let old_exe_path = std::env::current_exe()?;
let new_exe_path = unpack(archive_data, "deno")?;
let new_exe_path = unpack(archive_data, "deno", cfg!(windows))?;
let permissions = fs::metadata(&old_exe_path)?.permissions();
fs::set_permissions(&new_exe_path, permissions)?;
check_exe(&new_exe_path)?;
@ -177,12 +177,13 @@ async fn download_package(
pub fn unpack(
archive_data: Vec<u8>,
exe_name: &str,
is_windows: bool,
) -> Result<PathBuf, std::io::Error> {
// We use into_path so that the tempdir is not automatically deleted. This is
// useful for debugging upgrade, but also so this function can return a path
// to the newly uncompressed file without fear of the tempdir being deleted.
let temp_dir = TempDir::new()?.into_path();
let exe_ext = if cfg!(windows) { "exe" } else { "" };
let exe_ext = if is_windows { "exe" } else { "" };
let archive_path = temp_dir.join(exe_name).with_extension(".zip");
let exe_path = temp_dir.join(exe_name).with_extension(exe_ext);
assert!(!exe_path.exists());