From 74e6d4222a7f70253f1d69eb8e7cf94114827852 Mon Sep 17 00:00:00 2001 From: Sebastian Thiel Date: Wed, 6 Dec 2023 07:49:27 +0100 Subject: assure `device_id` is taken from the final CWD (#186) (#110) --- src/main.rs | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/src/main.rs b/src/main.rs index ca16302..a655ea1 100644 --- a/src/main.rs +++ b/src/main.rs @@ -49,7 +49,7 @@ fn main() -> Result<()> { let res = TerminalApp::initialize( &mut terminal, walk_options, - paths_from(input, !opt.stay_on_filesystem)?, + extract_paths_maybe_set_cwd(input, !opt.stay_on_filesystem)?, Interaction::Full, )? .map(|(keys_rx, mut app)| { @@ -101,7 +101,7 @@ fn main() -> Result<()> { walk_options, !no_total, !no_sort, - paths_from(input, !opt.stay_on_filesystem)?, + extract_paths_maybe_set_cwd(input, !opt.stay_on_filesystem)?, )?; if statistics { writeln!(io::stderr(), "{:?}", stats).ok(); @@ -117,7 +117,7 @@ fn main() -> Result<()> { walk_options, true, true, - paths_from(opt.input, !opt.stay_on_filesystem)?, + extract_paths_maybe_set_cwd(opt.input, !opt.stay_on_filesystem)?, )? .0 } @@ -126,15 +126,17 @@ fn main() -> Result<()> { process::exit(res.to_exit_code()); } -fn paths_from(mut paths: Vec, cross_filesystems: bool) -> Result, io::Error> { - let device_id = std::env::current_dir() - .ok() - .and_then(|cwd| crossdev::init(&cwd).ok()); - +fn extract_paths_maybe_set_cwd( + mut paths: Vec, + cross_filesystems: bool, +) -> Result, io::Error> { if paths.len() == 1 { std::env::set_current_dir(&paths[0])?; - paths.remove(0); + paths.clear(); } + let device_id = std::env::current_dir() + .ok() + .and_then(|cwd| crossdev::init(&cwd).ok()); if paths.is_empty() { cwd_dirlist().map(|paths| match device_id { -- cgit v1.2.3