api2/config/{drive, changer}: prevent adding same device multiple times

this check is not perfect since there are often multiple device
nodes per drive/changer, but from the scan api we should return always
the same, so for an api user this should be enough

Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
This commit is contained in:
Dominik Csapak
2021-01-28 12:59:44 +01:00
committed by Dietmar Maurer
parent cef4654ff4
commit b03ec281bf
2 changed files with 19 additions and 4 deletions

View File

@ -56,8 +56,15 @@ pub fn create_drive(param: Value) -> Result<(), Error> {
check_drive_path(&linux_drives, &item.path)?;
if config.sections.get(&item.name).is_some() {
bail!("Entry '{}' already exists", item.name);
let existing: Vec<LinuxTapeDrive> = config.convert_to_typed_array("linux")?;
for drive in existing {
if drive.name == item.name {
bail!("Entry '{}' already exists", item.name);
}
if drive.path == item.path {
bail!("Path '{}' already used in drive '{}'", item.path, drive.name);
}
}
config.set_data(&item.name, "linux", &item)?;