fix(vfs): V-06 — sparse writes zero-fill gaps between previous end of file and seek offset
This commit is contained in:
@@ -1057,6 +1057,34 @@ impl DavFile for CarrierFile {
|
||||
fn write_bytes(&mut self, buf: Bytes) -> FsFuture<'_, ()> {
|
||||
self.touch();
|
||||
Box::pin(async move {
|
||||
// V-06: Sparse Writes — Lücke zwischen bisherigem Dateiende und Cursor mit Nullen füllen
|
||||
if self.cursor > self.file_size {
|
||||
let target = self.cursor;
|
||||
while self.file_size < target {
|
||||
let block_idx = (self.file_size / CARRIER_BLOCK_PAYLOAD_SIZE as u64) as usize;
|
||||
let offset_in_block = (self.file_size % CARRIER_BLOCK_PAYLOAD_SIZE as u64) as usize;
|
||||
let space_in_block = CARRIER_BLOCK_PAYLOAD_SIZE - offset_in_block;
|
||||
let to_pad = ((target - self.file_size) as usize).min(space_in_block);
|
||||
|
||||
let block_data = self.ensure_block_loaded(block_idx)?;
|
||||
if block_data.len() < offset_in_block + to_pad {
|
||||
block_data.resize(offset_in_block + to_pad, 0);
|
||||
}
|
||||
|
||||
let mut is_full = false;
|
||||
if let Some((_, ref d, ref mut dirty)) = self.cached_block {
|
||||
*dirty = true;
|
||||
is_full = d.len() >= CARRIER_BLOCK_PAYLOAD_SIZE;
|
||||
}
|
||||
|
||||
self.file_size += to_pad as u64;
|
||||
|
||||
if is_full {
|
||||
self.flush_cached_block()?;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
let mut src = &buf[..];
|
||||
|
||||
while !src.is_empty() {
|
||||
|
||||
Reference in New Issue
Block a user