api: tape: don't allow duplicate media label-texts
quite a few parts of our code assumes that the label-text is unique in the inventory, which leads to rather unexpected behaviour when having more than one tape with the same label-text, e.g. a `proxmox-tape media destroy <LABEL>` destroys the first one in the config (same with moving to vault, etc.) since having multiple tapes with the same human readable name is always confusing, simply disallow that here Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
This commit is contained in:
parent
47b8c553b3
commit
3bf382f411
@ -539,6 +539,14 @@ fn write_media_label(
|
||||
label: MediaLabel,
|
||||
pool: Option<String>,
|
||||
) -> Result<(), Error> {
|
||||
let mut inventory = Inventory::new(TAPE_STATUS_DIR);
|
||||
inventory.reload()?;
|
||||
if inventory
|
||||
.find_media_by_label_text(&label.label_text)?
|
||||
.is_some()
|
||||
{
|
||||
bail!("Media with label '{}' already exists", label.label_text);
|
||||
}
|
||||
drive.label_tape(&label)?;
|
||||
if let Some(ref pool) = pool {
|
||||
task_log!(
|
||||
@ -562,8 +570,6 @@ fn write_media_label(
|
||||
|
||||
// Create the media catalog
|
||||
MediaCatalog::overwrite(TAPE_STATUS_DIR, &media_id, false)?;
|
||||
|
||||
let mut inventory = Inventory::new(TAPE_STATUS_DIR);
|
||||
inventory.store(media_id.clone(), false)?;
|
||||
|
||||
drive.rewind()?;
|
||||
|
Loading…
x
Reference in New Issue
Block a user