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