Skip to content

Commit c0587d0

Browse files
committed
refactor: streamline compute_uncompressed_database_size
1 parent f9d5379 commit c0587d0

File tree

1 file changed

+2
-25
lines changed

1 file changed

+2
-25
lines changed

mithril-aggregator/src/artifact_builder/cardano_database.rs

Lines changed: 2 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -68,21 +68,7 @@ impl ArtifactBuilder<CardanoDbBeacon, CardanoDatabaseSnapshot> for CardanoDataba
6868
}
6969
}
7070

71-
/// Return the sum of the files size contained in the subdirectories 'immutable', 'ledger' and 'volatile'.
72-
fn compute_uncompressed_database_size(db_directory: &Path) -> StdResult<u64> {
73-
let subdirs = ["immutable", "ledger", "volatile"];
74-
75-
subdirs
76-
.iter()
77-
.map(|subdir| {
78-
let dir_path = db_directory.join(subdir);
79-
compute_fs_entry_size(&dir_path)
80-
.with_context(|| format!("Failed to read metadata for directory: {:?}", dir_path))
81-
})
82-
.sum()
83-
}
84-
85-
fn compute_fs_entry_size(path: &Path) -> StdResult<u64> {
71+
fn compute_uncompressed_database_size(path: &Path) -> StdResult<u64> {
8672
if path.is_file() {
8773
let metadata = std::fs::metadata(path)
8874
.with_context(|| format!("Failed to read metadata for file: {:?}", path))?;
@@ -98,7 +84,7 @@ fn compute_fs_entry_size(path: &Path) -> StdResult<u64> {
9884
let path = entry
9985
.with_context(|| format!("Failed to read directory entry in {:?}", path))?
10086
.path();
101-
directory_size += compute_fs_entry_size(&path)?;
87+
directory_size += compute_uncompressed_database_size(&path)?;
10288
}
10389

10490
return Ok(directory_size);
@@ -142,15 +128,6 @@ mod tests {
142128
let expected_total_size =
143129
(2 * 3 * immutable_file_size) + ledger_file_size + (2 * volatile_file_size);
144130

145-
std::fs::write(test_dir.join("non_computed_file.txt"), "file inside root").unwrap();
146-
let non_computed_dir = test_dir.join("non_computed_dir");
147-
std::fs::create_dir(&non_computed_dir).unwrap();
148-
std::fs::write(
149-
non_computed_dir.join("another_non_computed_file.txt"),
150-
"file inside a non computed directory",
151-
)
152-
.unwrap();
153-
154131
let total_size = compute_uncompressed_database_size(&test_dir).unwrap();
155132

156133
assert_eq!(expected_total_size, total_size);

0 commit comments

Comments
 (0)