Skip to content

Commit

Permalink
path
Browse files Browse the repository at this point in the history
  • Loading branch information
sergey-shandar committed Mar 12, 2024
1 parent 0c3da8a commit 188353d
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 6 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
10 changes: 9 additions & 1 deletion blockset-lib/src/app/add.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<String> {
read_to_tree_file(
Expand Down Expand Up @@ -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<String> {
if metadata.is_dir() {
self.add_dir(path)
self.add_dir(normalize_path(path))
} else {
self.p.total = metadata.len();
self.add_file(path)
Expand Down
5 changes: 1 addition & 4 deletions blockset-lib/src/app/add_entry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()])
Expand Down

0 comments on commit 188353d

Please sign in to comment.