Merge pull request #565 from rustic-rs/restore-existing

restore: Treat all existing contents correctly
This commit is contained in:
aawsome 2023-04-06 23:18:19 +02:00 committed by GitHub
commit 75985f1626
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 16 additions and 4 deletions

View File

@ -100,8 +100,19 @@ impl Node {
self.node_type == NodeType::Dir
}
pub fn is_symlink(&self) -> bool {
matches!(self.node_type, NodeType::Symlink { linktarget: _ })
pub fn is_file(&self) -> bool {
matches!(self.node_type, NodeType::File)
}
pub fn is_special(&self) -> bool {
matches!(
self.node_type,
NodeType::Symlink { linktarget: _ }
| NodeType::Dev { device: _ }
| NodeType::Chardev { device: _ }
| NodeType::Fifo
| NodeType::Socket
)
}
pub fn set_subtree(&mut self, id: Id) {

View File

@ -302,8 +302,9 @@ fn allocate_and_collect(
}
Ordering::Equal => {
// process existing node
if node.is_dir() != dst.file_type().unwrap().is_dir()
|| (node.is_symlink() != dst.file_type().unwrap().is_symlink())
if (node.is_dir() && !dst.file_type().unwrap().is_dir())
|| (node.is_file() && !dst.metadata().unwrap().is_file())
|| node.is_special()
{
// if types do not match, first remove the existing file
process_existing(dst)?;