src/client/backup_reader.rs: factor out download_fixed_index() helper

This commit is contained in:
Dietmar Maurer 2019-11-08 12:43:56 +01:00
parent c3d84a2281
commit 7205050059
2 changed files with 29 additions and 7 deletions

View File

@ -1095,14 +1095,8 @@ async fn restore_do(param: Value) -> Result<Value, Error> {
.map_err(|err| format_err!("unable to pipe data - {}", err))?;
}
} else if server_archive_name.ends_with(".fidx") {
let tmpfile = client.download(&server_archive_name, tmpfile).await?;
let index = FixedIndexReader::new(tmpfile)
.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 index = client.download_fixed_index(&manifest, &server_archive_name).await?;
let mut writer = if let Some(target) = target {
std::fs::OpenOptions::new()

View File

@ -162,4 +162,32 @@ impl BackupReader {
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)
}
}