(
&mut self,
txn: &T,
)
| 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(¤t) { |
| 130 | affected_parents.insert(parent.to_string()); |
| 131 | } |
| 132 | if final_paths.get(¤t) == Some(inode) { |
| 133 | final_paths.remove(¤t); |
| 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 { |
no test coverage detected