diff --git a/src/examples/car-to-star.rs b/src/examples/car-to-star.rs index 5337a78..5d974ac 100644 --- a/src/examples/car-to-star.rs +++ b/src/examples/car-to-star.rs @@ -49,10 +49,22 @@ async fn main() -> Result<()> { let repo_commit: RepoCommit = serde_ipld_dagcbor::from_slice(commit_bytes)?; + let root_bytes = blocks + .get(&repo_commit.data) + .context("repo data cannot be null")?; + let root_node: RepoMstNode = + serde_ipld_dagcbor::from_slice(root_bytes).context("root must be an mst node")?; + + let star_data = if root_node.l.is_none() && root_node.e.is_empty() { + None + } else { + Some(repo_commit.data) + }; + let star_commit = StarCommit { did: repo_commit.did, version: repo_commit.version, - data: Some(repo_commit.data), + data: star_data, rev: repo_commit.rev, prev: repo_commit.prev, sig: repo_commit.sig, @@ -62,9 +74,14 @@ async fn main() -> Result<()> { serializer.write_header(&star_commit)?; println!("wrote header. Root: {}", repo_commit.data); - println!("writing tree..."); - let (nodes, records) = write_tree(repo_commit.data, &blocks, &mut serializer)?; - println!("wrote {nodes} nodes and {records} records."); + + if let Some(root_cid) = star_commit.data { + println!("writing tree..."); + let (nodes, records) = write_tree(root_cid, &blocks, &mut serializer)?; + println!("wrote {nodes} nodes and {records} records."); + } else { + println!("empty MST, no tree written."); + } serializer.finish()?; println!("Done!"); diff --git a/src/examples/star-debug.rs b/src/examples/star-debug.rs index 45f7c15..3560d9f 100644 --- a/src/examples/star-debug.rs +++ b/src/examples/star-debug.rs @@ -24,10 +24,10 @@ fn main() -> Result<(), Box> { println!(" Root: {:?}", c.data); } StarItem::Node(n) => { - // print_node(&n); + print_node(&n); } StarItem::Record { key, cid, .. } => { - // println!(" Record: key={}, cid={}", to_hex(&key), cid); + println!(" Record: key={}, cid={}", to_hex(&key), cid); } } } diff --git a/star-samples/empty.star b/star-samples/empty.star index 924b0a534e607c3d8c94c9e23ca5e658e63de27d..84ee8666fc8440e842233cbcfa9fc6f22c899a98 100644 GIT binary patch delta 23 ecmdnR*u%)G#n{2PWFl)FXL?y`QE_H|9y0(@hzBzO delta 69 zcmeBS+{MVM#kh@e=|t8#^OTgtlEfQY5vmM~g+dB*|NTq6TlUKK)Keylh7HY?SF7$T ac