Fix bug in path iteration leading to bug in gradual scans
This commit is contained in:
parent
e85c8c372d
commit
6b72672d29
@ -265,15 +265,7 @@ pub fn prepopulate_unmodified(
|
|||||||
);
|
);
|
||||||
|
|
||||||
// Pull out parent directories so our subset always contains the parents for their children.
|
// Pull out parent directories so our subset always contains the parents for their children.
|
||||||
let mut path_fragment = path.as_bytes();
|
for path_fragment in iterate_dirs_upwards(path.as_bytes()) {
|
||||||
while let Some((index, _)) = path_fragment
|
|
||||||
.iter()
|
|
||||||
.enumerate()
|
|
||||||
.rev()
|
|
||||||
.find(|(_idx, char_byte)| **char_byte == b'/')
|
|
||||||
{
|
|
||||||
path_fragment = &path_fragment[0..index];
|
|
||||||
|
|
||||||
if let Some(directory) = pruned_scan_entry_map.remove(path_fragment)
|
if let Some(directory) = pruned_scan_entry_map.remove(path_fragment)
|
||||||
{
|
{
|
||||||
prepopulated_scan_entry_map.insert(path_fragment, directory);
|
prepopulated_scan_entry_map.insert(path_fragment, directory);
|
||||||
@ -345,15 +337,7 @@ pub fn limit_scan_entry_map_to_size(
|
|||||||
accum_size += size_of_entry;
|
accum_size += size_of_entry;
|
||||||
|
|
||||||
// Pull out parent directories so our subset always contains the parents for their children.
|
// Pull out parent directories so our subset always contains the parents for their children.
|
||||||
let mut path_fragment = &path_bytes[..];
|
for path_fragment in iterate_dirs_upwards(&path_bytes) {
|
||||||
while let Some((index, _)) = path_fragment
|
|
||||||
.iter()
|
|
||||||
.enumerate()
|
|
||||||
.rev()
|
|
||||||
.find(|(_idx, char_byte)| **char_byte == b'/')
|
|
||||||
{
|
|
||||||
path_fragment = &path_bytes[0..index];
|
|
||||||
|
|
||||||
if let Some(directory) = unincluded_directories.remove(path_fragment) {
|
if let Some(directory) = unincluded_directories.remove(path_fragment) {
|
||||||
result.insert(path_fragment, directory);
|
result.insert(path_fragment, directory);
|
||||||
accum_size += 4096;
|
accum_size += 4096;
|
||||||
@ -375,6 +359,24 @@ pub fn limit_scan_entry_map_to_size(
|
|||||||
result
|
result
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Returns a list of all the parent paths of the given path (in bytes),
|
||||||
|
/// including the root, in order from leaf to root.
|
||||||
|
pub fn iterate_dirs_upwards(path_bytes: &[u8]) -> Vec<&[u8]> {
|
||||||
|
let mut result = Vec::new();
|
||||||
|
let mut path_fragment = &path_bytes[..];
|
||||||
|
while let Some((index, _)) = path_fragment
|
||||||
|
.iter()
|
||||||
|
.enumerate()
|
||||||
|
.rev()
|
||||||
|
.find(|(_idx, char_byte)| **char_byte == b'/')
|
||||||
|
{
|
||||||
|
path_fragment = &path_bytes[0..index];
|
||||||
|
result.push(path_fragment);
|
||||||
|
}
|
||||||
|
result.push(&path_bytes[0..0]);
|
||||||
|
result
|
||||||
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use crate::scan::limit_scan_entry_map_to_size;
|
use crate::scan::limit_scan_entry_map_to_size;
|
||||||
|
@ -417,7 +417,9 @@ pub fn assemble_tree_from_scan_entries(
|
|||||||
// note: for the root, this inserts the root file entry as a child called "" within a fake root 'directory'.
|
// note: for the root, this inserts the root file entry as a child called "" within a fake root 'directory'.
|
||||||
// That's fine. We'll patch this up later.
|
// That's fine. We'll patch this up later.
|
||||||
dirs.get_mut(parent_dir_name)
|
dirs.get_mut(parent_dir_name)
|
||||||
.context("bad PMap: parent not seen first")?
|
.with_context(|| {
|
||||||
|
format!("bad PMap: parent {parent_dir_name} not seen first")
|
||||||
|
})?
|
||||||
.insert(
|
.insert(
|
||||||
child_name.to_owned(),
|
child_name.to_owned(),
|
||||||
TreeNode::NormalFile {
|
TreeNode::NormalFile {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user