src/client/backup_reader.rs: factor out download_fixed_index() helper
This commit is contained in:
parent
c3d84a2281
commit
7205050059
@ -1095,14 +1095,8 @@ async fn restore_do(param: Value) -> Result<Value, Error> {
|
|||||||
.map_err(|err| format_err!("unable to pipe data - {}", err))?;
|
.map_err(|err| format_err!("unable to pipe data - {}", err))?;
|
||||||
}
|
}
|
||||||
} else if server_archive_name.ends_with(".fidx") {
|
} else if server_archive_name.ends_with(".fidx") {
|
||||||
let tmpfile = client.download(&server_archive_name, tmpfile).await?;
|
|
||||||
|
|
||||||
let index = FixedIndexReader::new(tmpfile)
|
let index = client.download_fixed_index(&manifest, &server_archive_name).await?;
|
||||||
.map_err(|err| format_err!("unable to read fixed index '{}' - {}", archive_name, err))?;
|
|
||||||
|
|
||||||
// Note: do not use values stored in index (not trusted) - instead, computed them again
|
|
||||||
let (csum, size) = index.compute_csum();
|
|
||||||
manifest.verify_file(&server_archive_name, &csum, size)?;
|
|
||||||
|
|
||||||
let mut writer = if let Some(target) = target {
|
let mut writer = if let Some(target) = target {
|
||||||
std::fs::OpenOptions::new()
|
std::fs::OpenOptions::new()
|
||||||
|
@ -162,4 +162,32 @@ impl BackupReader {
|
|||||||
|
|
||||||
Ok(index)
|
Ok(index)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Download fixed index file
|
||||||
|
///
|
||||||
|
/// This creates a temorary file in /tmp (using O_TMPFILE). The index is verified using
|
||||||
|
/// the provided manifest.
|
||||||
|
pub async fn download_fixed_index(
|
||||||
|
&self,
|
||||||
|
manifest: &BackupManifest,
|
||||||
|
name: &str,
|
||||||
|
) -> Result<FixedIndexReader, Error> {
|
||||||
|
|
||||||
|
let tmpfile = std::fs::OpenOptions::new()
|
||||||
|
.write(true)
|
||||||
|
.read(true)
|
||||||
|
.custom_flags(libc::O_TMPFILE)
|
||||||
|
.open("/tmp")?;
|
||||||
|
|
||||||
|
let tmpfile = self.download(name, tmpfile).await?;
|
||||||
|
|
||||||
|
let index = FixedIndexReader::new(tmpfile)
|
||||||
|
.map_err(|err| format_err!("unable to read fixed index '{}' - {}", name, err))?;
|
||||||
|
|
||||||
|
// Note: do not use values stored in index (not trusted) - instead, computed them again
|
||||||
|
let (csum, size) = index.compute_csum();
|
||||||
|
manifest.verify_file(name, &csum, size)?;
|
||||||
|
|
||||||
|
Ok(index)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user