From 746a94952de6d506dee5f45c77c72ccb597bb516 Mon Sep 17 00:00:00 2001 From: HsiangNianian Date: Tue, 13 Jan 2026 16:14:49 +0800 Subject: Implement library rules validation and zip extraction utility - Added `is_library_allowed` function to evaluate library permissions based on defined rules. - Introduced `rule_matches` helper function to check OS compatibility for rules. - Created `extract_zip` function to handle zip file extraction, including directory creation and skipping of META-INF entries. --- src-tauri/src/utils/zip.rs | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 src-tauri/src/utils/zip.rs (limited to 'src-tauri/src/utils/zip.rs') diff --git a/src-tauri/src/utils/zip.rs b/src-tauri/src/utils/zip.rs new file mode 100644 index 0000000..3ddf0f2 --- /dev/null +++ b/src-tauri/src/utils/zip.rs @@ -0,0 +1,34 @@ +use std::path::Path; +use std::fs; + +pub fn extract_zip(zip_path: &Path, extract_to: &Path) -> Result<(), String> { + let file = fs::File::open(zip_path).map_err(|e| format!("Failed to open zip {}: {}", zip_path.display(), e))?; + let mut archive = zip::ZipArchive::new(file).map_err(|e| format!("Failed to read zip: {}", e))?; + + for i in 0..archive.len() { + let mut file = archive.by_index(i).map_err(|e| format!("Failed to read zip entry: {}", e))?; + let outpath = match file.enclosed_name() { + Some(path) => extract_to.join(path), + None => continue, + }; + + // Skip META-INF + if outpath.to_string_lossy().contains("META-INF") { + continue; + } + + if file.name().ends_with('/') { + fs::create_dir_all(&outpath).map_err(|e| format!("Failed to create dir: {}", e))?; + } else { + if let Some(p) = outpath.parent() { + if !p.exists() { + fs::create_dir_all(&p).map_err(|e| format!("Failed to create dir: {}", e))?; + } + } + let mut outfile = fs::File::create(&outpath).map_err(|e| format!("Failed to create file: {}", e))?; + std::io::copy(&mut file, &mut outfile).map_err(|e| format!("Failed to copy file: {}", e))?; + } + } + + Ok(()) +} -- cgit v1.2.3-70-g09d2