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
This commit is contained in:
Andrew Rioux 2023-09-12 19:55:37 -04:00
parent 726e6dff13
commit fb98d062ef
Signed by: andrew.rioux
GPG Key ID: 9B8BAC47C17ABB94

View File

@ -120,12 +120,19 @@ async fn run_command(
Ok(())
}
async fn edit_file(connection: Arc<Connection>, remote_path: PathBuf) -> anyhow::Result<()> {
async fn edit_file(
cwd: &str,
connection: Arc<Connection>,
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<Connection>, 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);