dirstate-v2: check that root nodes are at the root before writing stable
authorRaphaël Gomès <rgomes@octobus.net>
Mon, 06 May 2024 13:07:02 +0200
branchstable
changeset 51617 f808fa119212
parent 51616 9dbbaecfc950
child 51618 ccf5c44092db
dirstate-v2: check that root nodes are at the root before writing More explanations in the previous changeset.
rust/hg-core/src/dirstate_tree/on_disk.rs
--- 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