From 5b0ab2488e2792c98d5788c96bdcb21651961522 Mon Sep 17 00:00:00 2001 From: Alexander Weiss Date: Wed, 5 Apr 2023 17:39:22 +0200 Subject: [PATCH] restore: Treat all existing contents correctly --- src/backend/node.rs | 15 +++++++++++++-- src/commands/restore.rs | 5 +++-- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/src/backend/node.rs b/src/backend/node.rs index 12f78a6..7e4f200 100644 --- a/src/backend/node.rs +++ b/src/backend/node.rs @@ -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) { diff --git a/src/commands/restore.rs b/src/commands/restore.rs index 4e0141b..04119d5 100644 --- a/src/commands/restore.rs +++ b/src/commands/restore.rs @@ -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)?;