From b03ec281bf3ca68ee67bb835b0f877f16de72db6 Mon Sep 17 00:00:00 2001 From: Dominik Csapak Date: Thu, 28 Jan 2021 12:59:44 +0100 Subject: [PATCH] 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 --- src/api2/config/changer.rs | 12 ++++++++++-- src/api2/config/drive.rs | 11 +++++++++-- 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/src/api2/config/changer.rs b/src/api2/config/changer.rs index 1b429659..8404d20b 100644 --- a/src/api2/config/changer.rs +++ b/src/api2/config/changer.rs @@ -59,8 +59,16 @@ pub fn create_changer( check_drive_path(&linux_changers, &path)?; - if config.sections.get(&name).is_some() { - bail!("Entry '{}' already exists", name); + let existing: Vec = config.convert_to_typed_array("changer")?; + + for changer in existing { + if changer.name == name { + bail!("Entry '{}' already exists", name); + } + + if changer.path == path { + bail!("Path '{}' already in use by '{}'", path, changer.name); + } } let item = ScsiTapeChanger { diff --git a/src/api2/config/drive.rs b/src/api2/config/drive.rs index 78ebecb3..7d7803d3 100644 --- a/src/api2/config/drive.rs +++ b/src/api2/config/drive.rs @@ -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 = 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)?;