Compare commits
5 Commits
8618e563dc
...
8fa7fdb88b
| Author | SHA1 | Date | |
|---|---|---|---|
| 8fa7fdb88b | |||
| 75368d4c0c | |||
| 3aa326e737 | |||
| 744fd0f6c2 | |||
| a288bf58a5 |
@ -40,10 +40,7 @@ impl TryFrom<PathBuf> for FileNameInfo {
|
|||||||
match file_name.rsplit_once(b'.').filter(|(_, ending)| {
|
match file_name.rsplit_once(b'.').filter(|(_, ending)| {
|
||||||
//there are usually no file extensions which are just a number, but rather versions
|
//there are usually no file extensions which are just a number, but rather versions
|
||||||
// -> don't use split if ending is number
|
// -> don't use split if ending is number
|
||||||
match ending.to_str() {
|
!matches!(ending.to_str(), Some(ending) if ending.parse::<u32>().is_ok())
|
||||||
Some(ending) if ending.parse::<u32>().is_ok() => false,
|
|
||||||
_ => true,
|
|
||||||
}
|
|
||||||
}) {
|
}) {
|
||||||
Some((name, ending)) => (name, Some(ending.to_os_string())),
|
Some((name, ending)) => (name, Some(ending.to_os_string())),
|
||||||
None => (file_name, None),
|
None => (file_name, None),
|
||||||
@ -75,14 +72,12 @@ impl Display for FileNameInfo {
|
|||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub enum FileInfoError {
|
pub enum FileInfoError {
|
||||||
NotAFile,
|
NotAFile,
|
||||||
InvalidCharactersInFileName,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Display for FileInfoError {
|
impl Display for FileInfoError {
|
||||||
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
|
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
|
||||||
match self {
|
match self {
|
||||||
FileInfoError::NotAFile => write!(f, "Path doesn't point to a file"),
|
FileInfoError::NotAFile => write!(f, "Path doesn't point to a file"),
|
||||||
FileInfoError::InvalidCharactersInFileName => write!(f, "Invalid characters in file name"),
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
16
src/main.rs
16
src/main.rs
@ -259,7 +259,7 @@ fn main() -> Result<(), String> {
|
|||||||
.into_iter()
|
.into_iter()
|
||||||
.map(|file| {
|
.map(|file| {
|
||||||
FileNameInfo::try_from(file.clone())
|
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()))
|
.map_err(|e| format!("Bad file '{}': {e}", file.to_string_lossy()))
|
||||||
})
|
})
|
||||||
.collect::<Result<Vec<_>, _>>()?
|
.collect::<Result<Vec<_>, _>>()?
|
||||||
@ -295,7 +295,7 @@ fn main() -> Result<(), String> {
|
|||||||
actions: {
|
actions: {
|
||||||
let present_file_names: Vec<OsString> = match &server.address {
|
let present_file_names: Vec<OsString> = match &server.address {
|
||||||
ServerAddress::Ssh { ssh_address } => osstring_from_ssh_output(
|
ServerAddress::Ssh { ssh_address } => osstring_from_ssh_output(
|
||||||
ShellCmd::new("ls")
|
ShellCmd::new("ssh")
|
||||||
.arg(ssh_address)
|
.arg(ssh_address)
|
||||||
.arg(osf!("ls ") + &working_directory)
|
.arg(osf!("ls ") + &working_directory)
|
||||||
.collect_output()
|
.collect_output()
|
||||||
@ -359,7 +359,7 @@ fn main() -> Result<(), String> {
|
|||||||
if !present_file_names.iter().any(|file| *file == file_name) {
|
if !present_file_names.iter().any(|file| *file == file_name) {
|
||||||
vec![add_action] //file doesn't exist yet
|
vec![add_action] //file doesn't exist yet
|
||||||
} else {
|
} else {
|
||||||
vec![FileAction::new(&file_name, Action::Replace)
|
vec![FileAction::new(file, Action::Replace)
|
||||||
.expect("path points to file")]
|
.expect("path points to file")]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -387,12 +387,12 @@ fn main() -> Result<(), String> {
|
|||||||
let mut actions = present_file_names
|
let mut actions = present_file_names
|
||||||
.iter()
|
.iter()
|
||||||
.filter(|file| file_matcher.matches(file))
|
.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
|
//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")
|
FileAction::new(file, Action::Replace).expect("path points to file")
|
||||||
} else {
|
} else {
|
||||||
FileAction::new(file, Action::Delete).expect("path points to file")
|
FileAction::new(present_file, Action::Delete).expect("path points to file")
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.collect::<Vec<_>>();
|
.collect::<Vec<_>>();
|
||||||
@ -421,6 +421,10 @@ fn main() -> Result<(), String> {
|
|||||||
log!(logger, "The following actions will be performed: ");
|
log!(logger, "The following actions will be performed: ");
|
||||||
for server_actions in &actions {
|
for server_actions in &actions {
|
||||||
log!(logger, "{server_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 {
|
if !no_confirm {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user