Skip to content

Commit

Permalink
fix: ensure that a new offset file ends with the zero data file length (
Browse files Browse the repository at this point in the history
  • Loading branch information
joshieDo authored and emhane committed Jun 13, 2024
1 parent c3bd3c5 commit a6dfa07
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions crates/storage/nippy-jar/src/writer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -130,10 +130,19 @@ impl<H: NippyJarHeader> NippyJarWriter<H> {
}

let mut offsets_file = OpenOptions::new().read(true).write(true).open(offsets)?;
if is_created {
let mut buf = Vec::with_capacity(1 + OFFSET_SIZE_BYTES as usize);

// First byte of the offset file is the size of one offset in bytes
offsets_file.write_all(&[OFFSET_SIZE_BYTES])?;
offsets_file.seek(SeekFrom::End(0))?;
// First byte of the offset file is the size of one offset in bytes
buf.write_all(&[OFFSET_SIZE_BYTES])?;

// The last offset should always represent the data file len, which is 0 on
// creation.
buf.write_all(&[0; OFFSET_SIZE_BYTES as usize])?;

offsets_file.write_all(&buf)?;
offsets_file.seek(SeekFrom::End(0))?;
}

Ok((data_file, offsets_file, is_created))
}
Expand Down

0 comments on commit a6dfa07

Please sign in to comment.