src/api2/backup.rs: aquire backup lock earlier in create_locked_backup_group()

This commit is contained in:
Dietmar Maurer
2020-07-30 10:48:33 +02:00
parent d2b0c78e23
commit 1fc82c41f2
3 changed files with 14 additions and 10 deletions

View File

@ -88,7 +88,10 @@ async move {
let env_type = rpcenv.env_type();
let backup_group = BackupGroup::new(backup_type, backup_id);
let owner = datastore.create_backup_group(&backup_group, &username)?;
// lock backup group to only allow one backup per group at a time
let (owner, _group_guard) = datastore.create_locked_backup_group(&backup_group, &username)?;
// permission check
if owner != username { // only the owner is allowed to create additional snapshots
bail!("backup owner check failed ({} != {})", username, owner);
@ -103,9 +106,6 @@ async move {
}
}
// lock backup group to only allow one backup per group at a time
let _group_guard = backup_group.lock(&datastore.base_path())?;
let (path, is_new) = datastore.create_backup_dir(&backup_dir)?;
if !is_new { bail!("backup directory already exists."); }