Skip to content

Commit

Permalink
fixed wrong file footer offset while dumping a bunch of empty files
Browse files Browse the repository at this point in the history
  • Loading branch information
ph0llux committed Nov 20, 2023
1 parent 6155f04 commit eb198ad
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions src/lib/io/zffwriter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -641,8 +641,22 @@ impl<R: Read> ZffWriter<R> {
break;
}
};
let current_offset = seek_value + written_bytes;
let current_chunk_number = self.current_object_encoder.current_chunk_number();

// check if the chunkmap is full - this lines are necessary to ensure
// the correct file footer offset is set while reading a bunch of empty files.
if chunkmap.is_full() {
if let Some(chunk_no) = chunkmap.chunkmap.keys().max() {
main_footer_chunk_map.insert(*chunk_no, self.current_segment_no);
segment_footer.chunk_map_table.insert(*chunk_no, seek_value + written_bytes);
segment_footer_len += 16; //append 16 bytes to segment footer len
}
written_bytes += output.write(&chunkmap.encode_directly())? as u64;
chunkmap.flush();
};

let current_offset = seek_value + written_bytes;

let data = match self.current_object_encoder.get_next_data(
current_offset,
self.current_segment_no,
Expand Down Expand Up @@ -696,8 +710,9 @@ impl<R: Read> ZffWriter<R> {
segment_footer_len += 16; //append 16 bytes to segment footer len
}
written_bytes += output.write(&chunkmap.encode_directly())? as u64;

chunkmap.flush();
chunkmap.add_chunk_entry(current_chunk_number, written_bytes);
chunkmap.add_chunk_entry(current_chunk_number, seek_value + written_bytes);
};
written_bytes += output.write(&data)? as u64;
}
Expand Down

0 comments on commit eb198ad

Please sign in to comment.