Skip to content

Commit c8272db

Browse files
committed
persisting root cid after all operations
1 parent 58f25a4 commit c8272db

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

crates/fula-cli/src/handlers/batch.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,11 @@ pub async fn delete_objects(
5656

5757
bucket.flush().await?;
5858

59+
// Persist the bucket registry so the updated root CID survives restarts
60+
if let Err(e) = state.bucket_manager.persist_registry().await {
61+
tracing::warn!(error = %e, "Failed to persist bucket registry after batch delete");
62+
}
63+
5964
// Build response
6065
let xml_response = if quiet && errors.is_empty() {
6166
// Quiet mode - only return errors

crates/fula-cli/src/handlers/object.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,11 @@ pub async fn put_object(
9797
e
9898
})?;
9999

100+
// Persist the bucket registry so the new root CID survives restarts
101+
if let Err(e) = state.bucket_manager.persist_registry().await {
102+
tracing::warn!(error = %e, "Failed to persist bucket registry after put_object");
103+
}
104+
100105
// Pin the BUCKET ROOT CID to ensure tree structure survives GC.
101106
// This recursively pins all tree nodes AND all referenced object data.
102107
// NOTE: Pinning is async (fire-and-forget) to avoid blocking the response.
@@ -346,6 +351,11 @@ pub async fn delete_object(
346351
bucket.delete_object(&key).await?;
347352
bucket.flush().await?;
348353

354+
// Persist the bucket registry so the updated root CID survives restarts
355+
if let Err(e) = state.bucket_manager.persist_registry().await {
356+
tracing::warn!(error = %e, "Failed to persist bucket registry after delete_object");
357+
}
358+
349359
Ok(StatusCode::NO_CONTENT.into_response())
350360
}
351361

@@ -408,6 +418,11 @@ pub async fn copy_object(
408418
dest_bucket_handle.put_object(dest_key, dest_metadata.clone()).await?;
409419
dest_bucket_handle.flush().await?;
410420

421+
// Persist the bucket registry so the updated root CID survives restarts
422+
if let Err(e) = state.bucket_manager.persist_registry().await {
423+
tracing::warn!(error = %e, "Failed to persist bucket registry after copy_object");
424+
}
425+
411426
let xml_response = xml::copy_object_result(
412427
dest_metadata.last_modified,
413428
&dest_metadata.etag,

0 commit comments

Comments
 (0)