From 92c5cf42d1abbc31a1df66d6f12bd34764832014 Mon Sep 17 00:00:00 2001 From: Dominik Csapak Date: Wed, 27 Oct 2021 13:22:26 +0200 Subject: [PATCH] pbs-datastore: add protection info to BackupInfo and add necessary helper functions (protected_file/is_protected) Signed-off-by: Dominik Csapak Signed-off-by: Wolfgang Bumiller --- pbs-datastore/src/backup_info.rs | 20 ++++++++++++++++++-- tests/prune.rs | 2 +- 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/pbs-datastore/src/backup_info.rs b/pbs-datastore/src/backup_info.rs index 9d1ab991..b94b9779 100644 --- a/pbs-datastore/src/backup_info.rs +++ b/pbs-datastore/src/backup_info.rs @@ -92,7 +92,9 @@ impl BackupGroup { BackupDir::with_rfc3339(&self.backup_type, &self.backup_id, backup_time)?; let files = list_backup_files(l2_fd, backup_time)?; - list.push(BackupInfo { backup_dir, files }); + let protected = backup_dir.is_protected(base_path.to_owned()); + + list.push(BackupInfo { backup_dir, files, protected }); Ok(()) }, @@ -253,6 +255,17 @@ impl BackupDir { relative_path } + pub fn protected_file(&self, mut path: PathBuf) -> PathBuf { + path.push(self.relative_path()); + path.push(".protected"); + path + } + + pub fn is_protected(&self, base_path: PathBuf) -> bool { + let path = self.protected_file(base_path); + path.exists() + } + pub fn backup_time_to_string(backup_time: i64) -> Result { // fixme: can this fail? (avoid unwrap) Ok(proxmox_time::epoch_to_rfc3339_utc(backup_time)?) @@ -293,6 +306,8 @@ pub struct BackupInfo { pub backup_dir: BackupDir, /// List of data files pub files: Vec, + /// Protection Status + pub protected: bool, } impl BackupInfo { @@ -301,8 +316,9 @@ impl BackupInfo { path.push(backup_dir.relative_path()); let files = list_backup_files(libc::AT_FDCWD, &path)?; + let protected = backup_dir.is_protected(base_path.to_owned()); - Ok(BackupInfo { backup_dir, files }) + Ok(BackupInfo { backup_dir, files, protected }) } /// Finds the latest backup inside a backup group diff --git a/tests/prune.rs b/tests/prune.rs index 4853ee49..96c29f4a 100644 --- a/tests/prune.rs +++ b/tests/prune.rs @@ -42,7 +42,7 @@ fn create_info( files.push(String::from(MANIFEST_BLOB_NAME)); } - BackupInfo { backup_dir, files } + BackupInfo { backup_dir, files, protected: false } } #[test]