tape: merge MediaStateDatabase into Inventory
This commit is contained in:
@ -34,7 +34,6 @@ use crate::{
|
||||
tape::{
|
||||
TAPE_STATUS_DIR,
|
||||
Inventory,
|
||||
MediaStateDatabase,
|
||||
PoolWriter,
|
||||
MediaPool,
|
||||
SnapshotReader,
|
||||
@ -154,12 +153,10 @@ fn update_media_online_status(drive: &str) -> Result<bool, Error> {
|
||||
|
||||
let status_path = Path::new(TAPE_STATUS_DIR);
|
||||
let mut inventory = Inventory::load(status_path)?;
|
||||
let mut state_db = MediaStateDatabase::load(status_path)?;
|
||||
|
||||
update_changer_online_status(
|
||||
&config,
|
||||
&mut inventory,
|
||||
&mut state_db,
|
||||
&changer_name,
|
||||
&changer_id_list,
|
||||
)?;
|
||||
|
@ -20,7 +20,6 @@ use crate::{
|
||||
ElementStatus,
|
||||
OnlineStatusMap,
|
||||
Inventory,
|
||||
MediaStateDatabase,
|
||||
linux_tape_changer_list,
|
||||
mtx_status,
|
||||
mtx_status_to_online_set,
|
||||
@ -57,14 +56,13 @@ pub async fn get_status(name: String) -> Result<Vec<MtxStatusEntry>, Error> {
|
||||
}).await??;
|
||||
|
||||
let state_path = Path::new(TAPE_STATUS_DIR);
|
||||
let inventory = Inventory::load(state_path)?;
|
||||
let mut inventory = Inventory::load(state_path)?;
|
||||
|
||||
let mut map = OnlineStatusMap::new(&config)?;
|
||||
let online_set = mtx_status_to_online_set(&status, &inventory);
|
||||
map.update_online_status(&name, online_set)?;
|
||||
|
||||
let mut state_db = MediaStateDatabase::load(state_path)?;
|
||||
state_db.update_online_status(&map)?;
|
||||
inventory.update_online_status(&map)?;
|
||||
|
||||
let mut list = Vec::new();
|
||||
|
||||
|
@ -48,7 +48,6 @@ use crate::{
|
||||
MediaChange,
|
||||
MediaPool,
|
||||
Inventory,
|
||||
MediaStateDatabase,
|
||||
MediaCatalog,
|
||||
MediaId,
|
||||
mtx_load,
|
||||
@ -421,7 +420,7 @@ fn write_media_label(
|
||||
MediaCatalog::overwrite(status_path, &media_id, false)?;
|
||||
|
||||
let mut inventory = Inventory::load(status_path)?;
|
||||
inventory.store(media_id.clone())?;
|
||||
inventory.store(media_id.clone(), false)?;
|
||||
|
||||
drive.rewind()?;
|
||||
|
||||
@ -542,12 +541,10 @@ pub async fn inventory(
|
||||
let state_path = Path::new(TAPE_STATUS_DIR);
|
||||
|
||||
let mut inventory = Inventory::load(state_path)?;
|
||||
let mut state_db = MediaStateDatabase::load(state_path)?;
|
||||
|
||||
update_changer_online_status(
|
||||
&config,
|
||||
&mut inventory,
|
||||
&mut state_db,
|
||||
&changer_name,
|
||||
&changer_id_list,
|
||||
)?;
|
||||
@ -630,9 +627,8 @@ pub fn update_inventory(
|
||||
let state_path = Path::new(TAPE_STATUS_DIR);
|
||||
|
||||
let mut inventory = Inventory::load(state_path)?;
|
||||
let mut state_db = MediaStateDatabase::load(state_path)?;
|
||||
|
||||
update_changer_online_status(&config, &mut inventory, &mut state_db, &changer_name, &changer_id_list)?;
|
||||
update_changer_online_status(&config, &mut inventory, &changer_name, &changer_id_list)?;
|
||||
|
||||
for changer_id in changer_id_list.iter() {
|
||||
if changer_id.starts_with("CLN") {
|
||||
@ -668,7 +664,7 @@ pub fn update_inventory(
|
||||
continue;
|
||||
}
|
||||
worker.log(format!("inventorize media '{}' with uuid '{}'", changer_id, media_id.label.uuid));
|
||||
inventory.store(media_id)?;
|
||||
inventory.store(media_id, false)?;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -743,9 +739,8 @@ fn barcode_label_media_worker(
|
||||
let state_path = Path::new(TAPE_STATUS_DIR);
|
||||
|
||||
let mut inventory = Inventory::load(state_path)?;
|
||||
let mut state_db = MediaStateDatabase::load(state_path)?;
|
||||
|
||||
update_changer_online_status(&config, &mut inventory, &mut state_db, &changer_name, &changer_id_list)?;
|
||||
update_changer_online_status(&config, &mut inventory, &changer_name, &changer_id_list)?;
|
||||
|
||||
if changer_id_list.is_empty() {
|
||||
bail!("changer device does not list any media labels");
|
||||
@ -921,7 +916,7 @@ pub fn catalog_media(
|
||||
let status_path = Path::new(TAPE_STATUS_DIR);
|
||||
|
||||
let mut inventory = Inventory::load(status_path)?;
|
||||
inventory.store(media_id.clone())?;
|
||||
inventory.store(media_id.clone(), false)?;
|
||||
|
||||
let pool = match media_id.media_set_label {
|
||||
None => {
|
||||
|
@ -28,7 +28,6 @@ use crate::{
|
||||
tape::{
|
||||
TAPE_STATUS_DIR,
|
||||
Inventory,
|
||||
MediaStateDatabase,
|
||||
MediaPool,
|
||||
MediaCatalog,
|
||||
update_online_status,
|
||||
@ -118,11 +117,10 @@ pub async fn list_media(pool: Option<String>) -> Result<Vec<MediaListEntry>, Err
|
||||
if pool.is_none() {
|
||||
|
||||
let inventory = Inventory::load(status_path)?;
|
||||
let state_db = MediaStateDatabase::load(status_path)?;
|
||||
|
||||
for media_id in inventory.list_unassigned_media() {
|
||||
|
||||
let (mut status, location) = state_db.status_and_location(&media_id.label.uuid);
|
||||
let (mut status, location) = inventory.status_and_location(&media_id.label.uuid);
|
||||
|
||||
if status == MediaStatus::Unknown {
|
||||
status = MediaStatus::Writable;
|
||||
@ -184,9 +182,6 @@ pub fn destroy_media(changer_id: String, force: Option<bool>,) -> Result<(), Err
|
||||
|
||||
inventory.remove_media(&uuid)?;
|
||||
|
||||
let mut state_db = MediaStateDatabase::load(status_path)?;
|
||||
state_db.remove_media(&uuid)?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user