Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion mithril-aggregator/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "mithril-aggregator"
version = "0.5.58"
version = "0.5.59"
description = "A Mithril Aggregator server"
authors = { workspace = true }
edition = { workspace = true }
Expand Down
21 changes: 7 additions & 14 deletions mithril-aggregator/src/snapshotter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,18 +94,16 @@ pub enum SnapshotError {
impl Snapshotter for CompressedArchiveSnapshotter {
fn snapshot(&self, archive_name: &str) -> StdResult<OngoingSnapshot> {
let archive_path = self.ongoing_snapshot_directory.join(archive_name);
let filesize = self.create_and_verify_archive(&archive_path).map_err(|err| {
let filesize = self.create_and_verify_archive(&archive_path).inspect_err(|_err| {
if archive_path.exists() {
if let Err(remove_error) = std::fs::remove_file(&archive_path) {
if let Err(remove_error) = fs::remove_file(&archive_path) {
warn!(
" > Post snapshotter.snapshot failure, could not remove temporary archive at path: path:{}, err: {}",
archive_path.display(),
remove_error
);
}
}

err
}).with_context(|| format!("CompressedArchiveSnapshotter can not create and verify archive: '{}'", archive_path.display()))?;

Ok(OngoingSnapshot {
Expand All @@ -123,15 +121,15 @@ impl CompressedArchiveSnapshotter {
compression_algorithm: SnapshotterCompressionAlgorithm,
) -> StdResult<CompressedArchiveSnapshotter> {
if ongoing_snapshot_directory.exists() {
std::fs::remove_dir_all(&ongoing_snapshot_directory).with_context(|| {
fs::remove_dir_all(&ongoing_snapshot_directory).with_context(|| {
format!(
"Can not remove snapshotter directory: '{}'.",
ongoing_snapshot_directory.display()
)
})?;
}

std::fs::create_dir(&ongoing_snapshot_directory).map_err(|e| {
fs::create_dir(&ongoing_snapshot_directory).map_err(|e| {
DependenciesBuilderError::Initialization {
message: format!(
"Can not create snapshotter directory: '{}'.",
Expand All @@ -149,7 +147,7 @@ impl CompressedArchiveSnapshotter {
}

fn get_file_size(filepath: &Path) -> StdResult<u64> {
let res = std::fs::metadata(filepath)
let res = fs::metadata(filepath)
.map_err(|e| SnapshotError::GeneralError(e.to_string()))?
.len();
Ok(res)
Expand Down Expand Up @@ -456,12 +454,7 @@ mod tests {
.unwrap(),
);

assert_eq!(
0,
std::fs::read_dir(pending_snapshot_directory)
.unwrap()
.count()
);
assert_eq!(0, fs::read_dir(pending_snapshot_directory).unwrap().count());
}

#[test]
Expand All @@ -487,7 +480,7 @@ mod tests {
let _ = snapshotter
.snapshot("whatever.tar.gz")
.expect_err("Snapshotter::snapshot should fail if the db is empty.");
let remaining_files: Vec<String> = std::fs::read_dir(&pending_snapshot_directory)
let remaining_files: Vec<String> = fs::read_dir(&pending_snapshot_directory)
.unwrap()
.map(|f| f.unwrap().file_name().to_str().unwrap().to_owned())
.collect();
Expand Down