From 3ee27b48fd83810d3a361a25033dabcb89428e6a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Philipp=20Kr=C3=BCger?= Date: Thu, 18 Apr 2024 10:31:58 +0200 Subject: [PATCH] fix: Don't merge equal files --- wnfs/src/public/directory.rs | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/wnfs/src/public/directory.rs b/wnfs/src/public/directory.rs index d541aeb3..17e5a7fb 100644 --- a/wnfs/src/public/directory.rs +++ b/wnfs/src/public/directory.rs @@ -942,12 +942,18 @@ impl PublicDirectory { let our_node = occupied.get_mut().resolve_value_mut(store).await?; match (our_node, other_node) { (PublicNode::File(our_file), PublicNode::File(other_file)) => { + let our_cid = our_file.store(store).await?; + let other_cid = other_file.store(store).await?; + if our_cid == other_cid { + continue; // No need to merge, the files are equal + } + let mut path = current_path.to_vec(); path.push(name.clone()); file_tie_breaks.insert(path); - let our_cid = our_file.userland.resolve_cid(store).await?; - let other_cid = other_file.userland.resolve_cid(store).await?; + let our_content_cid = our_file.userland.resolve_cid(store).await?; + let other_content_cid = other_file.userland.resolve_cid(store).await?; let file = our_file.prepare_next_merge(store).await?; if other_file.previous.len() > 1 { @@ -958,7 +964,7 @@ impl PublicDirectory { file.previous.insert(other_file.store(store).await?); } - if our_cid.hash().digest() > other_cid.hash().digest() { + if our_content_cid.hash().digest() > other_content_cid.hash().digest() { file.userland = other_file.userland.clone(); file.metadata = other_file.metadata.clone(); }