From 806793421ed62f4f69ea0dbc17404dbee251905e Mon Sep 17 00:00:00 2001 From: veeso Date: Sat, 22 Mar 2025 13:25:29 +0100 Subject: [PATCH] fix(bookmarks): Local directory path is not switching to what's specified in the bookmark closes #316 --- CHANGELOG.md | 4 ++++ src/activity_manager.rs | 19 ++++++++++++------- src/ui/activities/auth/misc.rs | 8 ++++++++ src/ui/activities/auth/update.rs | 3 +++ 4 files changed, 27 insertions(+), 7 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2ed93fb..33d9436 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -44,6 +44,10 @@ Released on ?? +- [issue 316](https://github.com/veeso/termscp/issues/316): Local directory path is not switching to what's specified in the bookmark. Now the local directory path is correctly set following this hierarchy: + 1. Local directory path specified for the host bridge + 2. Local directory path specified in the bookmark + 3. Working directory - [issue 317](https://github.com/veeso/termscp/issues/317): the return value of `--version` should be `0` - [issue 319](https://github.com/veeso/termscp/issues/319): fixed a crash when the local directory specified in the auth form does not exist - [issue 327](https://github.com/veeso/termscp/issues/327): fixed a panic when trying to go up from local directory on localhost in the auth form diff --git a/src/activity_manager.rs b/src/activity_manager.rs index 913d7d1..c48852b 100644 --- a/src/activity_manager.rs +++ b/src/activity_manager.rs @@ -90,13 +90,18 @@ impl ActivityManager { )), host_params.password.as_deref(), ), - Remote::None => self.set_host_params( - HostParams::HostBridge(HostBridgeParams::Localhost( - env::current_dir() - .map_err(|e| format!("Could not get current directory: {e}"))?, - )), - None, - ), + Remote::None => { + // local dir is remote_args.local_dir if set, otherwise current dir + let local_dir = remote_args + .local_dir + .unwrap_or_else(|| env::current_dir().unwrap()); + debug!("host bridge is None, setting local dir to {:?}", local_dir,); + + self.set_host_params( + HostParams::HostBridge(HostBridgeParams::Localhost(local_dir)), + None, + ) + } }?; // set remote diff --git a/src/ui/activities/auth/misc.rs b/src/ui/activities/auth/misc.rs index d24c02b..7de6194 100644 --- a/src/ui/activities/auth/misc.rs +++ b/src/ui/activities/auth/misc.rs @@ -83,8 +83,16 @@ impl AuthActivity { } fn collect_localhost_host_params(&self) -> Result { + // get remote local path + let remote_local_path = self.get_input_local_directory(FormTab::Remote); + + // Local path is: + // - the input local path if set + // - the remote local path if set + // - the current directory if neither is set let path = self .get_input_local_directory(FormTab::HostBridge) + .or(remote_local_path) .unwrap_or_else(|| env::current_dir().unwrap_or_default()); Ok(HostBridgeParams::Localhost(path)) diff --git a/src/ui/activities/auth/update.rs b/src/ui/activities/auth/update.rs index cfeb7ed..539cbf9 100644 --- a/src/ui/activities/auth/update.rs +++ b/src/ui/activities/auth/update.rs @@ -36,6 +36,9 @@ impl AuthActivity { return None; }; + debug!("Remote params: {:?}", remote_params); + debug!("Host bridge params: {:?}", host_bridge_params); + self.save_recent(); // Set file transfer params to context self.context_mut().set_remote_params(remote_params);