From a4b1819449ee249efc295dbb788600acb4a899e6 Mon Sep 17 00:00:00 2001 From: sergey-shandar Date: Tue, 12 Mar 2024 04:03:08 -0700 Subject: [PATCH] 100% --- blockset-lib/src/app/add_entry.rs | 46 ++++++++++++++++++------------- 1 file changed, 27 insertions(+), 19 deletions(-) diff --git a/blockset-lib/src/app/add_entry.rs b/blockset-lib/src/app/add_entry.rs index 378692d9..f156bcd4 100644 --- a/blockset-lib/src/app/add_entry.rs +++ b/blockset-lib/src/app/add_entry.rs @@ -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 { + 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, @@ -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()]) }