diff --git a/src/main.rs b/src/main.rs index bc62143..30dde00 100644 --- a/src/main.rs +++ b/src/main.rs @@ -15,7 +15,7 @@ use clap::{Parser, Subcommand, ValueEnum}; use lazy_regex::{lazy_regex, Lazy, Regex}; use server::{Server, ServerReference}; use std::cell::LazyCell; -use std::ffi::{OsStr, OsString}; +use std::ffi::OsStr; use std::hash::Hash; use std::io::Write; use std::iter::once; @@ -207,32 +207,35 @@ fn main() -> Result<(), String> { match &file_server { Some(file_server) => match &file_server.address { ServerAddress::Ssh { ssh_address } => { - //canonicalize remote files - //TODO only join when there are multiple paths - let joined_files = osf!("{{") - + files - .iter() - .map(|file| file.as_os_str()) - .collect::>() - .join(&OsString::from(",")) - + "}"; + //canonicalize remote files -> also makes sure they exist + files = files + .iter() + .map(|file| { + let output = ShellCmd::new("ssh") + .arg(ssh_address) + .arg(osf!("realpath -e ") + file_server.server_directory_path.join(file)) + .collect_full_output() + .map_err(|e| format!("Failed to canonicalize files: {e}"))?; - //TODO handle bad exit status - let realpath_output = ShellCmd::new("ssh") - .arg(ssh_address) - .arg(osf!("realpath ") + file_server.server_directory_path.join(joined_files)) - .collect_output() - .map_err(|e| format!("failed to canonicalize files to upload: {e}"))?; - files = realpath_output - .stdout - .split(|&b| b == b'\n') //split at line breaks - .map(|bytes| PathBuf::from(OsStr::from_bytes(bytes))) + if !output.status.success() { + Err(format!( + "Path doesn't match any files on file-server: {}", + file.to_string_lossy() + ))?; + } + + let denoted_files = output + .stdout + .split(|&b| b == b'\n') //split at line breaks + .map(|bytes| PathBuf::from(OsStr::from_bytes(bytes))) + .collect::>(); + + Ok(denoted_files) + }) + .collect::, String>>()? + .into_iter() + .flatten() .collect(); - log!(logger, debug, "canonical files: {files:?}"); - - for file in &files { - check_file_exists_on_server(file, ssh_address, &file_server.server_directory_path)?; - } } ServerAddress::Localhost => files .iter() @@ -565,6 +568,7 @@ where Ok(()) } +#[allow(dead_code)] fn check_file_exists_on_server( path: P, ssh_address: S,