From 188353dcd369699a1e64429808f888edf000d18c Mon Sep 17 00:00:00 2001 From: sergey-shandar Date: Tue, 12 Mar 2024 14:29:03 -0700 Subject: [PATCH] path --- Cargo.toml | 2 +- blockset-lib/src/app/add.rs | 10 +++++++++- blockset-lib/src/app/add_entry.rs | 5 +---- 3 files changed, 11 insertions(+), 6 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 98865f37..7ef1e93b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -13,6 +13,6 @@ repository = "https://github.com/datablockset/blockset" blockset-lib = { path = "blockset-lib", version = "0.4.2" } io-trait = "0.10.0" io-impl = "0.10.0" -io-test = "0.10.0" +io-test = "0.10.1" wasm-bindgen-test = "0.3.42" nanvm-lib = "0.0.3" diff --git a/blockset-lib/src/app/add.rs b/blockset-lib/src/app/add.rs index a7cbbfcb..7a29e9e6 100644 --- a/blockset-lib/src/app/add.rs +++ b/blockset-lib/src/app/add.rs @@ -81,6 +81,14 @@ fn calculate_len(files: &[(String, u64)], state: &mut State) { }); } +fn normalize_path(path: &str) -> &str { + if path.ends_with('/') { + &path[..path.len() - 1] + } else { + path + } +} + impl<'a, T: Io, S: 'a + TreeAdd, F: Fn(&'a T) -> S> Add<'a, T, S, F> { pub fn add_file(&mut self, path: &str) -> io::Result { read_to_tree_file( @@ -133,7 +141,7 @@ impl<'a, T: Io, S: 'a + TreeAdd, F: Fn(&'a T) -> S> Add<'a, T, S, F> { } pub fn add_file_or_dir(&mut self, path: &str, metadata: T::Metadata) -> io::Result { if metadata.is_dir() { - self.add_dir(path) + self.add_dir(normalize_path(path)) } else { self.p.total = metadata.len(); self.add_file(path) diff --git a/blockset-lib/src/app/add_entry.rs b/blockset-lib/src/app/add_entry.rs index 819fa79c..4d1071f5 100644 --- a/blockset-lib/src/app/add_entry.rs +++ b/blockset-lib/src/app/add_entry.rs @@ -39,10 +39,7 @@ pub fn add_entry<'a, T: Io, S: 'a + TreeAdd>( storage: &'a impl Fn(&'a T) -> S, display_new: bool, ) -> io::Result<()> { - let mut path = posix_path(&a.next().ok_or(invalid_input("missing file name"))?); - if path.ends_with('/') { - path.pop(); - } + let path = posix_path(&a.next().ok_or(invalid_input("missing file name"))?); let to_posix_eol = is_to_posix_eol(a)?; let k = add_file_or_dir(io, storage, to_posix_eol, display_new, path)?; io.stdout().println([k.as_str()])