From 194dc0494012f2704079d41dfd9fc8fb116ea474 Mon Sep 17 00:00:00 2001 From: Mike Carson Date: Tue, 3 Dec 2024 14:53:28 -0500 Subject: [PATCH] chain inserts together to fix ownership issue --- registry/src/main.rs | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/registry/src/main.rs b/registry/src/main.rs index 50ac6cb..a71f971 100644 --- a/registry/src/main.rs +++ b/registry/src/main.rs @@ -293,8 +293,7 @@ fn prove(working_dir : &Option) -> Result<(Vec, HashMap Result<(), Error> { +fn commit(args: CommitArgs) -> Result<(), Error> { let uncommitted_path = get_working_dir(&args.c)?.join(STAGING_FILE); if !std::path::Path::new(uncommitted_path.to_str().unwrap()).exists() { return Err(Error::from(io::Error::new(io::ErrorKind::InvalidData, "No changes to prove and commit"))); @@ -320,12 +319,21 @@ fn commit(args : CommitArgs) -> Result<(), Error> { let filename = format!("{}.sdb", space); let path = path.join(filename); let db = Database::open(path.to_str().unwrap())?; - let mut tx = db.begin_write().unwrap(); + + // Collect all changes first let reader = TransactionReader(raw.as_slice()); - - for t in reader.iter() { - let key = t.subspace_hash.try_into().unwrap(); - tx.insert(key, t.owner.to_vec()).unwrap(); + let changes: Vec<_> = reader.iter() + .map(|t| { + let key = t.subspace_hash.try_into() + .map_err(|_| io::Error::new(io::ErrorKind::InvalidData, "Invalid subspace hash"))?; + Ok((key, t.owner.to_vec())) + }) + .collect::>()?; + + // Chain the inserts together + let mut tx = db.begin_write()?; + for (key, value) in changes { + tx = tx.insert(key, value)?; } tx.commit()?; }