From ca27f42a9d3b33815475a5c347775097dff2df75 Mon Sep 17 00:00:00 2001 From: Marshall Bowers Date: Fri, 5 Jul 2024 11:38:48 -0400 Subject: [PATCH] extension: Don't use `unzip` to extract `.zip` files (#13869) This PR replaces the usage of `unzip` for extracting `.zip` files downloaded by extensions with extraction via a library. This will allow us to extract `.zip` files even if `unzip` is not available (e.g., on Windows). Release Notes: - Removed the need for `unzip` to be present on the system to extract `.zip` files downloaded by extensions. --- .../src/wasm_host/wit/since_v0_0_7.rs | 23 +++---------------- 1 file changed, 3 insertions(+), 20 deletions(-) diff --git a/crates/extension/src/wasm_host/wit/since_v0_0_7.rs b/crates/extension/src/wasm_host/wit/since_v0_0_7.rs index 1ce215bdc1..c610f66917 100644 --- a/crates/extension/src/wasm_host/wit/since_v0_0_7.rs +++ b/crates/extension/src/wasm_host/wit/since_v0_0_7.rs @@ -421,27 +421,10 @@ impl ExtensionImports for WasmState { .await?; } DownloadedFileType::Zip => { - let file_name = destination_path - .file_name() - .ok_or_else(|| anyhow!("invalid download path"))? - .to_string_lossy(); - let zip_filename = format!("{file_name}.zip"); - let mut zip_path = destination_path.clone(); - zip_path.set_file_name(zip_filename); - futures::pin_mut!(body); - self.host.fs.create_file_with(&zip_path, body).await?; - - let unzip_status = std::process::Command::new("unzip") - .current_dir(&extension_work_dir) - .arg("-d") - .arg(&destination_path) - .arg(&zip_path) - .output()? - .status; - if !unzip_status.success() { - Err(anyhow!("failed to unzip {} archive", path.display()))?; - } + node_runtime::extract_zip(&destination_path, body) + .await + .with_context(|| format!("failed to unzip {} archive", path.display()))?; } }