Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 16 additions & 12 deletions drivers/rust/driver/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion drivers/rust/driver/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ tonic-prost = "0.14.6"
tracing = { version = "0.1.44", features = [ "log" ] }
tracing-core = "0.1.36"
uuid = { version = "1.24.0", features = ["v4"] }
zip = "8.6.0"
zip = "9.0.3"

[dev-dependencies]
env_logger = "0.11.11"
Expand Down
36 changes: 35 additions & 1 deletion drivers/rust/driver/src/download.rs
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ fn unzip_file(zip_file: &PathBuf, plugin_dir: &PathBuf) -> anyhow::Result<PathBu
None => continue
};

if (*file.name()).ends_with('/') {
if file.is_dir() {
debug!("Dir {} extracted to \"{}\"", i, outpath.display());
fs::create_dir_all(&outpath)?;
} else {
Expand Down Expand Up @@ -333,3 +333,37 @@ pub fn check_sha(file: &PathBuf, sha_file: &PathBuf) -> anyhow::Result<()> {
file.display(), sha, calculated))
}
}

#[cfg(test)]
mod tests {
use std::fs::{self, File};
use std::io::Write;

use expectest::prelude::*;
use tempdir::TempDir;
use zip::write::SimpleFileOptions;

use super::unzip_file;

#[test]
fn unzip_file_extracts_files_and_directories() {
let dir = TempDir::new("unzip").unwrap();
let zip_path = dir.path().join("plugin.zip");
let mut writer = zip::ZipWriter::new(File::create(&zip_path).unwrap());
writer.add_directory("bin/", SimpleFileOptions::default()).unwrap();
writer.start_file("bin/plugin", SimpleFileOptions::default().unix_permissions(0o755)).unwrap();
writer.write_all(b"plugin binary").unwrap();
writer.finish().unwrap();

let plugin_dir = dir.path().join("out");
unzip_file(&zip_path, &plugin_dir).unwrap();

expect!(fs::read_to_string(plugin_dir.join("bin/plugin")).unwrap()).to(be_equal_to("plugin binary"));
#[cfg(unix)]
{
use std::os::unix::fs::PermissionsExt;
let mode = fs::metadata(plugin_dir.join("bin/plugin")).unwrap().permissions().mode();
expect!(mode & 0o777).to(be_equal_to(0o755));
}
}
}
Loading