From 0927f937a764ba6a672e01eacc3b93e6efb13d82 Mon Sep 17 00:00:00 2001 From: weisd Date: Fri, 16 Jan 2026 17:11:54 +0800 Subject: [PATCH] fix: Fix BitrotWriter encode writer implementation (#1531) --- crates/ecstore/src/erasure_coding/bitrot.rs | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/crates/ecstore/src/erasure_coding/bitrot.rs b/crates/ecstore/src/erasure_coding/bitrot.rs index 72d17731..13426765 100644 --- a/crates/ecstore/src/erasure_coding/bitrot.rs +++ b/crates/ecstore/src/erasure_coding/bitrot.rs @@ -108,7 +108,6 @@ pin_project! { inner: W, hash_algo: HashAlgorithm, shard_size: usize, - buf: Vec, finished: bool, } } @@ -124,7 +123,6 @@ where inner, hash_algo, shard_size, - buf: Vec::new(), finished: false, } } @@ -159,19 +157,19 @@ where if hash_algo.size() > 0 { let hash = hash_algo.hash_encode(buf); - self.buf.extend_from_slice(hash.as_ref()); + if hash.as_ref().is_empty() { + error!("bitrot writer write hash error: hash is empty"); + return Err(std::io::Error::new(std::io::ErrorKind::InvalidInput, "hash is empty")); + } + self.inner.write_all(hash.as_ref()).await?; } - self.buf.extend_from_slice(buf); + self.inner.write_all(buf).await?; - self.inner.write_all(&self.buf).await?; - - // self.inner.flush().await?; + self.inner.flush().await?; let n = buf.len(); - self.buf.clear(); - Ok(n) }