]> git.proxmox.com Git - proxmox-backup.git/commitdiff
tape: write_chunk_archive - do not consume partially written chunk at EOT
authorDietmar Maurer <dietmar@proxmox.com>
Thu, 11 Mar 2021 11:59:57 +0000 (12:59 +0100)
committerDietmar Maurer <dietmar@proxmox.com>
Fri, 12 Mar 2021 06:14:50 +0000 (07:14 +0100)
So that it is re-written to the next tape.

src/tape/helpers/snapshot_reader.rs
src/tape/pool_writer.rs

index c8deb58a325c5ae73dea3da0ecf8de705a719831..21033d100e3224131b4bc690c347c1fbf0551157 100644 (file)
@@ -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<String>,
index e2ff9bd76a8301bbfcf968d18bba6b36b01db960..105fe695ae089639a0f0491e893c6cf4d74cf8ad 100644 (file)
@@ -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;
             }