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.
This commit is contained in:
Marshall Bowers 2024-07-05 11:38:48 -04:00 committed by GitHub
parent d70c577293
commit ca27f42a9d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -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()))?;
}
}