Skip to content

Commit

Permalink
Strengthen skipping last trio step when listing immutable files
Browse files Browse the repository at this point in the history
It will skip the file(s) with the highest number instead of simply
skipping the last three files.
  • Loading branch information
Alenar committed Jan 29, 2024
1 parent 3e4b8c6 commit e21a1a0
Showing 1 changed file with 39 additions and 2 deletions.
41 changes: 39 additions & 2 deletions mithril-common/src/digesters/immutable_file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -150,8 +150,18 @@ impl ImmutableFile {
}
files.sort();

// @todo: make the skip of the last 'trio' more robust
Ok(files.into_iter().rev().skip(3).rev().collect())
match files.last() {
// empty list
None => Ok(files),
// filter out the last immutable file(s)
Some(last_file) => {
let last_number = last_file.number;
Ok(files
.into_iter()
.filter(|f| f.number < last_number)
.collect())
}
}
}
}

Expand Down Expand Up @@ -324,4 +334,31 @@ mod tests {
let expected: Vec<&str> = entries.into_iter().rev().skip(5).rev().collect();
assert_eq!(expected, immutables_names);
}

#[test]
fn list_immutable_file_can_list_incomplete_trio() {
let target_dir = get_test_dir("list_immutable_file_can_list_incomplete_trio/immutable");
let entries = vec![
"21.chunk",
"21.primary",
"21.secondary",
"123.chunk",
"123.secondary",
"124.chunk",
"124.primary",
"125.primary",
"125.secondary",
"223.chunk",
"224.primary",
"225.secondary",
"226.chunk",
];
create_fake_files(&target_dir, &entries);
let immutables = ImmutableFile::list_completed_in_dir(target_dir.parent().unwrap())
.expect("ImmutableFile::list_in_dir Failed");
let immutables_names: Vec<String> = extract_filenames(&immutables);

let expected: Vec<&str> = entries.into_iter().rev().skip(1).rev().collect();
assert_eq!(expected, immutables_names);
}
}

0 comments on commit e21a1a0

Please sign in to comment.