Avoid lossy strings when renaming and matching files
This commit is contained in:
parent
d1924aa758
commit
c143b29a3d
@ -72,7 +72,12 @@ pub enum Action {
|
||||
}
|
||||
|
||||
impl Action {
|
||||
pub fn rename<S>(new_name: S) -> Self where S: AsRef<OsStr> {
|
||||
Self::Rename {new_name: new_name.as_ref().to_owned()}
|
||||
pub fn rename<S>(new_name: S) -> Self
|
||||
where
|
||||
S: AsRef<OsStr>,
|
||||
{
|
||||
Self::Rename {
|
||||
new_name: new_name.as_ref().to_owned(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
43
src/main.rs
43
src/main.rs
@ -355,28 +355,29 @@ fn main() -> Result<(), String> {
|
||||
.expect("path points to file")]
|
||||
}
|
||||
}
|
||||
OldVersionPolicy::Archive => {
|
||||
//TODO avoid lossy match
|
||||
present_file_names
|
||||
.iter()
|
||||
.filter(|file| file_matcher.matches(file))
|
||||
.map(|file| {
|
||||
FileAction::new(
|
||||
file,
|
||||
Action::rename(format!(
|
||||
"{}{}",
|
||||
file.to_string_lossy(),
|
||||
file.to_string_lossy().chars().last().unwrap_or('1')
|
||||
)),
|
||||
)
|
||||
.expect("path points to file")
|
||||
})
|
||||
.chain(once(add_action))
|
||||
.collect()
|
||||
},
|
||||
OldVersionPolicy::Archive => present_file_names
|
||||
.iter()
|
||||
.filter(|file| file_matcher.matches(file))
|
||||
.map(|file| {
|
||||
FileAction::new(
|
||||
file,
|
||||
Action::rename(
|
||||
osf!(file)
|
||||
+ file
|
||||
.to_string_lossy()
|
||||
.chars()
|
||||
.last()
|
||||
.unwrap_or('1')
|
||||
.to_string(),
|
||||
),
|
||||
)
|
||||
.expect("path points to file")
|
||||
})
|
||||
.chain(once(add_action))
|
||||
.collect(),
|
||||
OldVersionPolicy::Delete => {
|
||||
//TODO avoid lossy match
|
||||
let mut actions = present_file_names.iter()
|
||||
let mut actions = present_file_names
|
||||
.iter()
|
||||
.filter(|file| file_matcher.matches(file))
|
||||
.map(|file| {
|
||||
//special case -> file has the same name as current file, then we just need to replace it
|
||||
|
||||
Loading…
Reference in New Issue
Block a user