perf(backup): verify file contents during restore staging

This commit is contained in:
Tunglies
2026-12-01 22:58:36 +08:00
parent bc000a8e39
commit fe523dc34d
+5 -1
View File
@@ -40,6 +40,7 @@ pub struct ValidatedBackup<R: Read + Seek> {
}
impl<R: Read + Seek> ValidatedBackup<R> {
/// Checks the archive layout. Extract into staging to validate file contents before restore.
pub fn open(source: R, reserved_names: &[&str]) -> Result<Self, ArchiveError> {
let mut zip = ZipArchive::new(source)?;
for index in 0..zip.len() {
@@ -60,7 +61,10 @@ impl<R: Read + Seek> ValidatedBackup<R> {
return Err(ArchiveError::ReservedEntry);
}
}
io::copy(&mut entry, &mut io::sink())?;
// ZIP extraction skips directory payloads.
if entry.is_dir() {
io::copy(&mut entry, &mut io::sink())?;
}
}
Ok(Self { zip })
}