Skip to content

Commit

Permalink
100%
Browse files Browse the repository at this point in the history
  • Loading branch information
sergey-shandar committed Mar 12, 2024
1 parent 6dd48d5 commit a4b1819
Showing 1 changed file with 27 additions and 19 deletions.
46 changes: 27 additions & 19 deletions blockset-lib/src/app/add_entry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,32 @@ use super::{
invalid_input, is_to_posix_eol,
};

fn add_file_or_dir<'a, T: Io, S: 'a + TreeAdd>(
io: &'a T,
storage: &'a impl Fn(&'a T) -> S,
to_posix_eol: bool,
display_new: bool,
path: String,
) -> io::Result<String> {
let mut add = Add {
io,
storage,
to_posix_eol,
display_new,
status: StatusLine::new(io),
p: State {
total: 0,
current: 0,
},
};
if io.metadata(&path)?.is_dir() {
add.add_dir(&path)
} else {
add.p.total = io.metadata(&path)?.len();
add.add_file(&path)
}
}

pub fn add_entry<'a, T: Io, S: 'a + TreeAdd>(
io: &'a T,
a: &mut T::Args,
Expand All @@ -23,24 +49,6 @@ pub fn add_entry<'a, T: Io, S: 'a + TreeAdd>(
path.pop();
}
let to_posix_eol = is_to_posix_eol(a)?;
let k = {
let mut add = Add {
io,
storage,
to_posix_eol,
display_new,
status: StatusLine::new(io),
p: State {
total: 0,
current: 0,
},
};
if io.metadata(&path)?.is_dir() {
add.add_dir(&path)?
} else {
add.p.total = io.metadata(&path)?.len();
add.add_file(&path)?
}
};
let k = add_file_or_dir(io, storage, to_posix_eol, display_new, path)?;
io.stdout().println([k.as_str()])
}

0 comments on commit a4b1819

Please sign in to comment.