datastore: move blob loading into BackupDir impl and adapt call sites
data blobs can only appear in a BackupDir (snapshot) in the backup hierachy, so makes more sense that it lives in there. As it wasn't widely used anyway it's easy to move the single non-package call site over to the new one directly and drop the implementation from Datastore completely. Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
This commit is contained in:
parent
f03649b8f3
commit
1eef52c206
|
@ -11,7 +11,7 @@ use pbs_api_types::{BackupType, GroupFilter, BACKUP_DATE_REGEX, BACKUP_FILE_REGE
|
|||
use pbs_config::{open_backup_lockfile, BackupLockGuard};
|
||||
|
||||
use crate::manifest::{MANIFEST_BLOB_NAME, MANIFEST_LOCK_NAME};
|
||||
use crate::DataStore;
|
||||
use crate::{DataStore, DataBlob};
|
||||
|
||||
/// BackupGroup is a directory containing a list of BackupDir
|
||||
#[derive(Clone)]
|
||||
|
@ -345,6 +345,18 @@ impl BackupDir {
|
|||
proxmox_time::epoch_to_rfc3339_utc(backup_time)
|
||||
}
|
||||
|
||||
/// load a `DataBlob` from this snapshot's backup dir.
|
||||
pub fn load_blob(&self, filename: &str) -> Result<DataBlob, Error> {
|
||||
let mut path = self.full_path();
|
||||
path.push(filename);
|
||||
|
||||
proxmox_lang::try_block!({
|
||||
let mut file = std::fs::File::open(&path)?;
|
||||
DataBlob::load_from_reader(&mut file)
|
||||
})
|
||||
.map_err(|err| format_err!("unable to load blob '{:?}' - {}", path, err))
|
||||
}
|
||||
|
||||
/// Returns the filename to lock a manifest
|
||||
///
|
||||
/// Also creates the basedir. The lockfile is located in
|
||||
|
|
|
@ -913,17 +913,6 @@ impl DataStore {
|
|||
self.inner.chunk_store.insert_chunk(chunk, digest)
|
||||
}
|
||||
|
||||
pub fn load_blob(&self, backup_dir: &BackupDir, filename: &str) -> Result<DataBlob, Error> {
|
||||
let mut path = backup_dir.full_path();
|
||||
path.push(filename);
|
||||
|
||||
proxmox_lang::try_block!({
|
||||
let mut file = std::fs::File::open(&path)?;
|
||||
DataBlob::load_from_reader(&mut file)
|
||||
})
|
||||
.map_err(|err| format_err!("unable to load blob '{:?}' - {}", path, err))
|
||||
}
|
||||
|
||||
pub fn stat_chunk(&self, digest: &[u8; 32]) -> Result<std::fs::Metadata, Error> {
|
||||
let (chunk_path, _digest_str) = self.inner.chunk_store.chunk_path(digest);
|
||||
std::fs::metadata(chunk_path).map_err(Error::from)
|
||||
|
@ -948,7 +937,7 @@ impl DataStore {
|
|||
|
||||
/// Load the manifest without a lock. Must not be written back.
|
||||
pub fn load_manifest(&self, backup_dir: &BackupDir) -> Result<(BackupManifest, u64), Error> {
|
||||
let blob = self.load_blob(backup_dir, MANIFEST_BLOB_NAME)?;
|
||||
let blob = backup_dir.load_blob(MANIFEST_BLOB_NAME)?;
|
||||
let raw_size = blob.raw_size();
|
||||
let manifest = BackupManifest::try_from(blob)?;
|
||||
Ok((manifest, raw_size))
|
||||
|
|
|
@ -41,11 +41,10 @@ impl VerifyWorker {
|
|||
}
|
||||
|
||||
fn verify_blob(
|
||||
datastore: Arc<DataStore>,
|
||||
backup_dir: &BackupDir,
|
||||
info: &FileInfo,
|
||||
) -> Result<(), Error> {
|
||||
let blob = datastore.load_blob(backup_dir, &info.filename)?;
|
||||
let blob = backup_dir.load_blob(&info.filename)?;
|
||||
|
||||
let raw_size = blob.raw_size();
|
||||
if raw_size != info.size {
|
||||
|
@ -399,7 +398,7 @@ pub fn verify_backup_dir_with_lock(
|
|||
match archive_type(&info.filename)? {
|
||||
ArchiveType::FixedIndex => verify_fixed_index(verify_worker, backup_dir, info),
|
||||
ArchiveType::DynamicIndex => verify_dynamic_index(verify_worker, backup_dir, info),
|
||||
ArchiveType::Blob => verify_blob(verify_worker.datastore.clone(), backup_dir, info),
|
||||
ArchiveType::Blob => verify_blob(backup_dir, info),
|
||||
}
|
||||
});
|
||||
|
||||
|
|
Loading…
Reference in New Issue