From 0a8e8c29642b6f73d1fae0349ec5c512f4c77182 Mon Sep 17 00:00:00 2001 From: J Robert Ray Date: Tue, 18 Jun 2024 17:34:37 -0700 Subject: [PATCH] Fix spfs info failing when using fuse Like the same situation as the previous commit, `spfs info` may not be able to read refs of objects in the runtime layer stack. Rather than this failing the whole `info` command, report the size of the layer as unknown. Signed-off-by: J Robert Ray --- crates/spfs-cli/main/src/cmd_info.rs | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/crates/spfs-cli/main/src/cmd_info.rs b/crates/spfs-cli/main/src/cmd_info.rs index b3a7348c75..afb0a862a7 100644 --- a/crates/spfs-cli/main/src/cmd_info.rs +++ b/crates/spfs-cli/main/src/cmd_info.rs @@ -6,6 +6,7 @@ use std::collections::VecDeque; use clap::Args; use colored::*; +use futures::TryFutureExt; use miette::Result; use spfs::env::SPFS_DIR; use spfs::find_path::ObjectPathEntry; @@ -230,12 +231,18 @@ impl CmdInfo { println!(" {}: {}", "editable".bright_blue(), runtime.status.editable); println!("{}:", "stack (top-down)".bright_blue()); for digest in runtime.status.stack.to_top_down() { - print!(" - {}, ", self.format_digest(digest, repo).await?); - let object = repo.read_ref(digest.to_string().as_str()).await?; - println!( - "Size: {}", - self.human_readable(object.calculate_object_size(repo).await?), - ); + // Don't print anything until we know nothing in here is going to + // fail, so output doesn't get scrambled up. + let formatted_digest = self.format_digest(digest, repo).await?; + // Items in the stack may not be present in the local repo, + // therefore print "unknown" if the size cannot be determined. + let object_size = repo + .read_ref(digest.to_string().as_str()) + .and_then(|obj| async move { obj.calculate_object_size(repo).await }) + .await + .map(|size| self.human_readable(size)) + .unwrap_or_else(|_| "unknown".to_string()); + println!(" - {formatted_digest}, Size: {object_size}",); } println!();