MCPcopy Create free account
hub / github.com/atomicdotdev/atomic / derive_directory_occupancy

Method derive_directory_occupancy

atomic-repository/src/tracking/tree_ops.rs:106–182  ·  view source on GitHub ↗
(
        &mut self,
        txn: &T,
    )

Source from the content-addressed store, hash-verified

104 }
105
106 fn derive_directory_occupancy<T: TreeTxnT + PathClaimTxnT>(
107 &mut self,
108 txn: &T,
109 ) -> Result<(), TreeProjectionError> {
110 let mut final_paths = HashMap::<String, Inode>::new();
111 for entry in txn
112 .iter_tree()
113 .map_err(|error| TreeProjectionError::Database(error.to_string()))?
114 {
115 let (path, inode) =
116 entry.map_err(|error| TreeProjectionError::Database(error.to_string()))?;
117 final_paths.insert(path, inode);
118 }
119
120 let mut affected_parents = HashSet::<String>::new();
121 for (inode, entry) in &self.entries {
122 if entry.path.is_none() {
123 continue;
124 }
125 if let Some(current) = txn
126 .get_path(*inode)
127 .map_err(|error| TreeProjectionError::Database(error.to_string()))?
128 {
129 if let Some(parent) = direct_parent(&current) {
130 affected_parents.insert(parent.to_string());
131 }
132 if final_paths.get(&current) == Some(inode) {
133 final_paths.remove(&current);
134 }
135 }
136 }
137 // Remove every previous binding before installing destinations. This
138 // must not depend on HashMap iteration order for overlapping moves.
139 for (inode, entry) in &self.entries {
140 let Some(desired) = &entry.path else {
141 continue;
142 };
143 if let Some(path) = desired {
144 if let Some(parent) = direct_parent(path) {
145 affected_parents.insert(parent.to_string());
146 }
147 final_paths.insert(path.clone(), *inode);
148 }
149 }
150
151 for parent in affected_parents {
152 let Some(inode) = final_paths.get(&parent).copied() else {
153 continue;
154 };
155 let planned_kind = self.entries.get(&inode).and_then(|entry| entry.kind);
156 let is_directory = planned_kind == Some(TreeProjectionKind::Directory)
157 || txn
158 .is_directory(inode)
159 .map_err(|error| TreeProjectionError::Database(error.to_string()))?;
160 let empty = !final_paths
161 .keys()
162 .any(|path| direct_parent(path) == Some(parent.as_str()));
163 if !is_directory && empty {

Callers 1

planMethod · 0.80

Calls 12

direct_parentFunction · 0.85
explicit_emptyFunction · 0.85
explicit_with_childrenFunction · 0.85
is_noneMethod · 0.80
getMethod · 0.65
removeMethod · 0.65
iter_treeMethod · 0.45
insertMethod · 0.45
get_pathMethod · 0.45
cloneMethod · 0.45
is_directoryMethod · 0.45
as_strMethod · 0.45

Tested by

no test coverage detected