1 Commits

Author SHA1 Message Date
e219ea13fb fix: file-extension based archive matching 2025-11-21 22:04:34 +11:00
3 changed files with 35 additions and 3 deletions

View File

@ -1,6 +1,6 @@
{ {
"name": "@drop-oss/droplet", "name": "@drop-oss/droplet",
"version": "3.4.0", "version": "3.5.0",
"main": "index.js", "main": "index.js",
"types": "index.d.ts", "types": "index.d.ts",
"napi": { "napi": {

View File

@ -111,6 +111,17 @@ impl VersionBackend for PathVersionBackend {
pub static SEVEN_ZIP_INSTALLED: LazyLock<bool> = pub static SEVEN_ZIP_INSTALLED: LazyLock<bool> =
LazyLock::new(|| Command::new("7z").output().is_ok()); LazyLock::new(|| Command::new("7z").output().is_ok());
// https://7-zip.opensource.jp/chm/general/formats.htm
// Intentionally repeated some because it's a trivial cost and it's easier to directly copy from the docs above
pub const SUPPORTED_FILE_EXTENSIONS: [&str; 89] = [
"7z", "bz2", "bzip2", "tbz2", "tbz", "gz", "gzip", "tgz", "tar", "wim", "swm", "esd", "xz",
"txz", "zip", "zipx", "jar", "xpi", "odt", "ods", "docx", "xlsx", "epub", "apm", "ar", "a",
"deb", "lib", "arj", "cab", "chm", "chw", "chi", "chq", "msi", "msp", "doc", "xls", "ppt",
"cpio", "cramfs", "dmg", "ext", "ext2", "ext3", "ext4", "img", "fat", "img", "hfs", "hfsx",
"hxs", "hxr", "hxq", "hxw", "lit", "ihex", "iso", "img", "lzh", "lha", "lzma", "mbr", "mslz",
"mub", "nsis", "ntfs", "img", "mbr", "rar", "r00", "rpm", "ppmd", "qcow", "qcow2", "qcow2c",
"squashfs", "udf", "iso", "img", "scap", "uefif", "vdi", "vhd", "vmdk", "xar", "pkg", "z", "taz",
];
#[derive(Clone)] #[derive(Clone)]
pub struct ZipVersionBackend { pub struct ZipVersionBackend {
@ -189,7 +200,12 @@ impl VersionBackend for ZipVersionBackend {
continue; continue;
} }
results.push(VersionFile { results.push(VersionFile {
relative_filename: name.into_iter().map(|v| *v).fold(String::new(), |a, b| a + b + " ").trim_end().to_owned(), relative_filename: name
.into_iter()
.map(|v| *v)
.fold(String::new(), |a, b| a + b + " ")
.trim_end()
.to_owned(),
permission: 0o744, // owner r/w/x, everyone else, read permission: 0o744, // owner r/w/x, everyone else, read
size: size.parse().unwrap(), size: size.parse().unwrap(),
}); });

View File

@ -10,7 +10,9 @@ use napi::{bindgen_prelude::*, sys::napi_value__, tokio_stream::StreamExt};
use tokio_util::codec::{BytesCodec, FramedRead}; use tokio_util::codec::{BytesCodec, FramedRead};
use crate::version::{ use crate::version::{
backends::{PathVersionBackend, ZipVersionBackend, SEVEN_ZIP_INSTALLED}, backends::{
PathVersionBackend, ZipVersionBackend, SEVEN_ZIP_INSTALLED, SUPPORTED_FILE_EXTENSIONS,
},
types::{ReadToAsyncRead, VersionBackend, VersionFile}, types::{ReadToAsyncRead, VersionBackend, VersionFile},
}; };
@ -33,6 +35,8 @@ pub fn create_backend_constructor<'a>(
}; };
if *SEVEN_ZIP_INSTALLED { if *SEVEN_ZIP_INSTALLED {
/*
Slow 7zip integrity test
let mut test = Command::new("7z"); let mut test = Command::new("7z");
test.args(vec!["t", path.to_str().expect("invalid utf path")]); test.args(vec!["t", path.to_str().expect("invalid utf path")]);
let status = test.status().ok()?; let status = test.status().ok()?;
@ -40,6 +44,18 @@ pub fn create_backend_constructor<'a>(
let buf = path.to_path_buf(); let buf = path.to_path_buf();
return Some(Box::new(move || Ok(Box::new(ZipVersionBackend::new(buf)?)))); return Some(Box::new(move || Ok(Box::new(ZipVersionBackend::new(buf)?))));
} }
*/
// Fast filename-based test
if let Some(extension) = path.extension().and_then(|v| v.to_str()) {
let supported = SUPPORTED_FILE_EXTENSIONS
.iter()
.find(|v| ***v == *extension)
.is_some();
if supported {
let buf = path.to_path_buf();
return Some(Box::new(move || Ok(Box::new(ZipVersionBackend::new(buf)?))));
}
}
} }
None None