Skip to content
This repository has been archived by the owner on Jan 11, 2024. It is now read-only.

Commit

Permalink
FM-360: Fix manifest parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
aakoshh committed Nov 27, 2023
1 parent 3e18f68 commit 5671362
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 9 deletions.
2 changes: 1 addition & 1 deletion fendermint/vm/snapshot/src/manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -399,7 +399,7 @@ mod tests {
assert_eq!(snapshot.manifest.state_params, state_params);
assert_eq!(
snapshot.snapshot_dir.as_path(),
temp_dir.path().join(format!("snapshot-0"))
temp_dir.path().join("snapshot-0")
);

let _ = std::fs::File::open(snapshot.snapshot_dir.join("manifest.json"))
Expand Down
26 changes: 18 additions & 8 deletions fendermint/vm/snapshot/src/manifest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,22 +63,32 @@ pub fn list_manifests(snapshot_dir: impl AsRef<Path>) -> anyhow::Result<Vec<Snap

// Collect all manifest file paths.
let mut manifests = Vec::new();
for entry in contents.filter_map(|r| r.ok()) {
if let Ok(metadata) = entry.metadata() {
if metadata.is_dir() {
let manifest_path = entry.path().join(MANIFEST_FILE_NAME);
if manifest_path.exists() {
manifests.push((entry.path(), manifest_path))
for entry in contents {
match entry {
Ok(entry) => match entry.metadata() {
Ok(metadata) => {
if metadata.is_dir() {
let manifest_path = entry.path().join(MANIFEST_FILE_NAME);
if manifest_path.exists() {
manifests.push((entry.path(), manifest_path))
}
}
}
Err(e) => {
tracing::error!(error =? e, "faulty entry metadata");
}
},
Err(e) => {
tracing::error!(error =? e, "faulty snapshot entry");
}
}
}

// Parse manifests
let mut items = Vec::new();
for (snapshot_dir, manifest) in manifests {
let f = std::fs::File::open(&manifest).context("failed to open manifest")?;
match serde_json::from_reader(f) {
let json = std::fs::read_to_string(&manifest).context("failed to open manifest")?;
match serde_json::from_str(&json) {
Ok(manifest) => items.push(SnapshotItem {
snapshot_dir,
manifest,
Expand Down

0 comments on commit 5671362

Please sign in to comment.