From fb98d062ef183dfe26b2da83f42d3359881ecc99 Mon Sep 17 00:00:00 2001 From: Andrew Rioux Date: Tue, 12 Sep 2023 19:55:37 -0400 Subject: [PATCH] fix: file operations acknowledge pwd now file operations (edit, download, upload) on the client did not work outside of the current working directory of the binary on the server, as they did not acknowledge the current working directory on the client --- .../src/commands/connect/shell.rs | 36 ++++++++++++++----- 1 file changed, 27 insertions(+), 9 deletions(-) diff --git a/sparse-05/sparse-05-client/src/commands/connect/shell.rs b/sparse-05/sparse-05-client/src/commands/connect/shell.rs index 29d4f06..f7d4f6b 100644 --- a/sparse-05/sparse-05-client/src/commands/connect/shell.rs +++ b/sparse-05/sparse-05-client/src/commands/connect/shell.rs @@ -120,12 +120,19 @@ async fn run_command( Ok(()) } -async fn edit_file(connection: Arc, remote_path: PathBuf) -> anyhow::Result<()> { +async fn edit_file( + cwd: &str, + connection: Arc, + remote_path: PathBuf, +) -> anyhow::Result<()> { let local_path = tempfile::NamedTempFile::new()?.into_temp_path(); + let mut remote_path_used = PathBuf::from(cwd); + remote_path_used.extend(&remote_path); + commands::download::download_file( Arc::clone(&connection), - remote_path.clone(), + remote_path_used.clone(), local_path.to_owned(), ) .await?; @@ -144,8 +151,12 @@ async fn edit_file(connection: Arc, remote_path: PathBuf) -> anyhow: .wait() .await?; - commands::upload::upload_file(Arc::clone(&connection), local_path.to_owned(), remote_path) - .await?; + commands::upload::upload_file( + Arc::clone(&connection), + local_path.to_owned(), + remote_path_used, + ) + .await?; Ok(()) } @@ -246,9 +257,14 @@ pub(super) async fn shell( }), _, ) => { - if let Err(e) = - commands::upload::upload_file(Arc::clone(&connection), local_file, remote_path) - .await + let mut remote_path_used = PathBuf::from(&cwd); + remote_path_used.extend(&remote_path); + if let Err(e) = commands::upload::upload_file( + Arc::clone(&connection), + local_file, + remote_path_used, + ) + .await { eprintln!("{e:?}") } @@ -260,9 +276,11 @@ pub(super) async fn shell( }), _, ) => { + let mut remote_path_used = PathBuf::from(&cwd); + remote_path_used.extend(&remote_file); if let Err(e) = commands::download::download_file( Arc::clone(&connection), - remote_file, + remote_path_used, local_path, ) .await @@ -272,7 +290,7 @@ pub(super) async fn shell( } (Ok(SparseCommands::EditFile { remote_path }), _) => { pause.store(true, Ordering::SeqCst); - if let Err(e) = edit_file(Arc::clone(&connection), remote_path).await { + if let Err(e) = edit_file(&cwd, Arc::clone(&connection), remote_path).await { eprintln!("{e:?}"); } pause.store(false, Ordering::Relaxed);