diff rust/hg-core/src/dirstate_tree/on_disk.rs @ 51617:f808fa119212 stable

dirstate-v2: check that root nodes are at the root before writing More explanations in the previous changeset.
author Raphaël Gomès <rgomes@octobus.net>
date Mon, 06 May 2024 13:07:02 +0200
parents 9dbbaecfc950
children 918ceb5a3d25
line wrap: on
line diff
--- a/rust/hg-core/src/dirstate_tree/on_disk.rs	Mon May 06 13:02:52 2024 +0200
+++ b/rust/hg-core/src/dirstate_tree/on_disk.rs	Mon May 06 13:07:02 2024 +0200
@@ -640,7 +640,20 @@
         out: Vec::with_capacity(size_guess),
     };
 
-    let root_nodes = writer.write_nodes(dirstate_map.root.as_ref())?;
+    let root_nodes = dirstate_map.root.as_ref();
+    for node in root_nodes.iter() {
+        // Catch some corruptions before we write to disk
+        let full_path = node.full_path(dirstate_map.on_disk)?;
+        let base_name = node.base_name(dirstate_map.on_disk)?;
+        if full_path != base_name {
+            let explanation = format!(
+                "Dirstate root node '{}' is not at the root",
+                full_path
+            );
+            return Err(HgError::corrupted(explanation).into());
+        }
+    }
+    let root_nodes = writer.write_nodes(root_nodes)?;
 
     let unreachable_bytes = if append {
         dirstate_map.unreachable_bytes