Compare commits

...

5 Commits

2 changed files with 11 additions and 12 deletions

View File

@ -40,10 +40,7 @@ impl TryFrom<PathBuf> for FileNameInfo {
match file_name.rsplit_once(b'.').filter(|(_, ending)| {
//there are usually no file extensions which are just a number, but rather versions
// -> don't use split if ending is number
match ending.to_str() {
Some(ending) if ending.parse::<u32>().is_ok() => false,
_ => true,
}
!matches!(ending.to_str(), Some(ending) if ending.parse::<u32>().is_ok())
}) {
Some((name, ending)) => (name, Some(ending.to_os_string())),
None => (file_name, None),
@ -75,14 +72,12 @@ impl Display for FileNameInfo {
#[derive(Debug)]
pub enum FileInfoError {
NotAFile,
InvalidCharactersInFileName,
}
impl Display for FileInfoError {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
match self {
FileInfoError::NotAFile => write!(f, "Path doesn't point to a file"),
FileInfoError::InvalidCharactersInFileName => write!(f, "Invalid characters in file name"),
}
}
}

View File

@ -259,7 +259,7 @@ fn main() -> Result<(), String> {
.into_iter()
.map(|file| {
FileNameInfo::try_from(file.clone())
.map(|info| (PathBuf::from(&file), info))
.map(|info| (file.clone(), info))
.map_err(|e| format!("Bad file '{}': {e}", file.to_string_lossy()))
})
.collect::<Result<Vec<_>, _>>()?
@ -295,7 +295,7 @@ fn main() -> Result<(), String> {
actions: {
let present_file_names: Vec<OsString> = match &server.address {
ServerAddress::Ssh { ssh_address } => osstring_from_ssh_output(
ShellCmd::new("ls")
ShellCmd::new("ssh")
.arg(ssh_address)
.arg(osf!("ls ") + &working_directory)
.collect_output()
@ -359,7 +359,7 @@ fn main() -> Result<(), String> {
if !present_file_names.iter().any(|file| *file == file_name) {
vec![add_action] //file doesn't exist yet
} else {
vec![FileAction::new(&file_name, Action::Replace)
vec![FileAction::new(file, Action::Replace)
.expect("path points to file")]
}
}
@ -387,12 +387,12 @@ fn main() -> Result<(), String> {
let mut actions = present_file_names
.iter()
.filter(|file| file_matcher.matches(file))
.map(|file| {
.map(|present_file| {
//special case -> file has the same name as current file, then we just need to replace it
if *file == file_name {
if *present_file == file_name {
FileAction::new(file, Action::Replace).expect("path points to file")
} else {
FileAction::new(file, Action::Delete).expect("path points to file")
FileAction::new(present_file, Action::Delete).expect("path points to file")
}
})
.collect::<Vec<_>>();
@ -421,6 +421,10 @@ fn main() -> Result<(), String> {
log!(logger, "The following actions will be performed: ");
for server_actions in &actions {
log!(logger, "{server_actions}");
log!(logger, debug, "Detailed file actions: ");
for file_action in &server_actions.actions {
log!(logger, debug, "{file_action:?}");
}
}
if !no_confirm {