From e8913fea128aefe21ea386030ad1dbdb964529bd Mon Sep 17 00:00:00 2001 From: Dietmar Maurer Date: Thu, 11 Mar 2021 12:59:57 +0100 Subject: [PATCH] tape: write_chunk_archive - do not consume partially written chunk at EOT So that it is re-written to the next tape. --- src/tape/helpers/snapshot_reader.rs | 1 - src/tape/pool_writer.rs | 11 ++++++++--- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/src/tape/helpers/snapshot_reader.rs b/src/tape/helpers/snapshot_reader.rs index c8deb58a..21033d10 100644 --- a/src/tape/helpers/snapshot_reader.rs +++ b/src/tape/helpers/snapshot_reader.rs @@ -96,7 +96,6 @@ impl SnapshotReader { /// Note: The iterator returns a `Result`, and the iterator state is /// undefined after the first error. So it make no sense to continue /// iteration after the first error. -#[derive(Clone)] pub struct SnapshotChunkIterator<'a> { snapshot_reader: &'a SnapshotReader, todo_list: Vec, diff --git a/src/tape/pool_writer.rs b/src/tape/pool_writer.rs index e2ff9bd7..105fe695 100644 --- a/src/tape/pool_writer.rs +++ b/src/tape/pool_writer.rs @@ -418,14 +418,17 @@ fn write_chunk_archive<'a>( let mut leom = false; loop { - let digest = match chunk_iter.next() { + let digest = match chunk_iter.peek() { None => break, - Some(digest) => digest?, + Some(Ok(digest)) => *digest, + Some(Err(err)) => bail!("{}", err), }; + if media_catalog.contains_chunk(&digest) || chunk_index.contains(&digest) || media_set_catalog.contains_chunk(&digest) { + chunk_iter.next(); // consume continue; } @@ -433,11 +436,13 @@ fn write_chunk_archive<'a>( //println!("CHUNK {} size {}", proxmox::tools::digest_to_hex(&digest), blob.raw_size()); match writer.try_write_chunk(&digest, &blob) { - Ok(true) => { + Ok(true) => { + chunk_iter.next(); // consume chunk_index.insert(digest); chunk_list.push(digest); } Ok(false) => { + // Note; we do not consume the chunk (no chunk_iter.next()) leom = true; break; }