datastore: replace manual path assembly by group/dir full_path

Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
This commit is contained in:
Thomas Lamprecht 2022-04-24 18:03:27 +02:00
parent df5c6a11cd
commit 4b77d300a2
2 changed files with 6 additions and 15 deletions

View File

@ -57,9 +57,7 @@ impl BackupGroup {
pub fn list_backups(&self) -> Result<Vec<BackupInfo>, Error> { pub fn list_backups(&self) -> Result<Vec<BackupInfo>, Error> {
let mut list = vec![]; let mut list = vec![];
let base_path = self.store.base_path(); let path = self.full_group_path();
let mut path = base_path.to_owned();
path.push(self.relative_group_path());
proxmox_sys::fs::scandir( proxmox_sys::fs::scandir(
libc::AT_FDCWD, libc::AT_FDCWD,
@ -99,8 +97,7 @@ impl BackupGroup {
pub fn last_successful_backup(&self) -> Result<Option<i64>, Error> { pub fn last_successful_backup(&self) -> Result<Option<i64>, Error> {
let mut last = None; let mut last = None;
let mut path = self.store.base_path(); let path = self.full_group_path();
path.push(self.relative_group_path());
proxmox_sys::fs::scandir( proxmox_sys::fs::scandir(
libc::AT_FDCWD, libc::AT_FDCWD,
@ -373,9 +370,7 @@ pub struct BackupInfo {
impl BackupInfo { impl BackupInfo {
pub fn new(backup_dir: BackupDir) -> Result<BackupInfo, Error> { pub fn new(backup_dir: BackupDir) -> Result<BackupInfo, Error> {
let base_path = backup_dir.store.base_path(); let path = backup_dir.full_path();
let mut path = base_path.clone();
path.push(backup_dir.relative_path());
let files = list_backup_files(libc::AT_FDCWD, &path)?; let files = list_backup_files(libc::AT_FDCWD, &path)?;
let protected = backup_dir.is_protected(); let protected = backup_dir.is_protected();

View File

@ -499,9 +499,7 @@ impl DataStore {
) -> Result<Option<i64>, Error> { ) -> Result<Option<i64>, Error> {
let backup_group = self.backup_group(backup_group.clone()); let backup_group = self.backup_group(backup_group.clone());
let base_path = self.base_path(); let group_path = backup_group.full_group_path();
let mut group_path = base_path.clone();
group_path.push(backup_group.relative_group_path());
if group_path.exists() { if group_path.exists() {
backup_group.last_successful_backup() backup_group.last_successful_backup()
@ -976,8 +974,7 @@ impl DataStore {
} }
pub fn load_blob(&self, backup_dir: &BackupDir, filename: &str) -> Result<DataBlob, Error> { pub fn load_blob(&self, backup_dir: &BackupDir, filename: &str) -> Result<DataBlob, Error> {
let mut path = self.base_path(); let mut path = backup_dir.full_path();
path.push(backup_dir.relative_path());
path.push(filename); path.push(filename);
proxmox_lang::try_block!({ proxmox_lang::try_block!({
@ -1066,8 +1063,7 @@ impl DataStore {
let blob = DataBlob::encode(manifest.as_bytes(), None, true)?; let blob = DataBlob::encode(manifest.as_bytes(), None, true)?;
let raw_data = blob.raw_data(); let raw_data = blob.raw_data();
let mut path = self.base_path(); let mut path = backup_dir.full_path();
path.push(backup_dir.relative_path());
path.push(MANIFEST_BLOB_NAME); path.push(MANIFEST_BLOB_NAME);
// atomic replace invalidates flock - no other writes past this point! // atomic replace invalidates flock - no other writes past this point!