Skip to content

Commit c40c08c

Browse files
Don't make file longer if you're not at the end.
Closes #72
1 parent 098e9e6 commit c40c08c

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

src/volume_mgr.rs

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -659,14 +659,18 @@ where
659659
.map_err(Error::DeviceError)?;
660660
written += to_copy;
661661
file.current_cluster = current_cluster;
662-
let to_copy = i32::try_from(to_copy).map_err(|_| Error::ConversionError)?;
663-
// TODO: Should we do this once when the whole file is written?
664-
file.update_length(file.length + (to_copy as u32));
665-
file.seek_from_current(to_copy).unwrap();
666-
file.entry.attributes.set_archive(true);
667-
file.entry.mtime = self.timesource.get_timestamp();
662+
663+
let to_copy = to_copy as u32;
664+
let new_offset = file.current_offset + to_copy;
665+
if new_offset > file.length {
666+
// We made it longer
667+
file.update_length(new_offset);
668+
}
669+
file.seek_from_start(new_offset).unwrap();
668670
// Entry update deferred to file close, for performance.
669671
}
672+
file.entry.attributes.set_archive(true);
673+
file.entry.mtime = self.timesource.get_timestamp();
670674
Ok(written)
671675
}
672676

0 commit comments

Comments
 (0)