Use replace action instead of explicit delete action where possible

This commit is contained in:
Leonard Steppy 2024-12-13 13:07:52 +01:00
parent 4f08fabd34
commit 9e8214d742

View File

@ -161,14 +161,29 @@ fn main() -> Result<(), String> {
}) })
.chain(once(add_action)) .chain(once(add_action))
.collect(), .collect(),
OldVersionPolicy::Delete => files OldVersionPolicy::Delete => {
.filter(|file| file_matcher.matches(file)) let mut actions: Vec<_> = files
.map(|file| FileAction { .filter(|file| file_matcher.matches(file))
file: PathBuf::from(file), .map(|file| {
kind: Action::Delete, //special case -> file has the same name as current file, then we just need to replace it
}) if file == file_name {
.chain(once(add_action)) FileAction {
.collect(), file: PathBuf::from(file),
kind: Action::Replace,
}
} else {
FileAction {
file: PathBuf::from(file),
kind: Action::Delete,
}
}
})
.collect();
if !actions.iter().any(|action| action.kind == Action::Replace) {
actions.push(add_action);
}
actions
},
} }
}, },
}) })