Fix canonicalization of remote files
This commit is contained in:
parent
ffd8f71f8b
commit
2eb37aa07a
54
src/main.rs
54
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::<Vec<_>>()
|
||||
.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::<Vec<_>>();
|
||||
|
||||
Ok(denoted_files)
|
||||
})
|
||||
.collect::<Result<Vec<_>, 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<P, S, D>(
|
||||
path: P,
|
||||
ssh_address: S,
|
||||
|
||||
Loading…
Reference in New Issue
Block a user