[pbs-devel] [PATCH proxmox-backup v4 3/6] tape/inventory: add completion helper for tape snapshots
Dominik Csapak
d.csapak at proxmox.com
Mon May 10 11:27:57 CEST 2021
Signed-off-by: Dominik Csapak <d.csapak at proxmox.com>
---
src/tape/inventory.rs | 36 ++++++++++++++++++++++++++++++++++++
1 file changed, 36 insertions(+)
diff --git a/src/tape/inventory.rs b/src/tape/inventory.rs
index f9654538..4bb6d4f8 100644
--- a/src/tape/inventory.rs
+++ b/src/tape/inventory.rs
@@ -54,6 +54,7 @@ use crate::{
tape::{
TAPE_STATUS_DIR,
MediaSet,
+ MediaCatalog,
file_formats::{
MediaLabel,
MediaSetLabel,
@@ -850,3 +851,38 @@ pub fn complete_media_label_text(
inventory.map.values().map(|entry| entry.id.label.label_text.clone()).collect()
}
+
+pub fn complete_media_set_snapshots(_arg: &str, param: &HashMap<String, String>) -> Vec<String> {
+ let media_set_uuid: Uuid = match param.get("media-set").and_then(|s| s.parse().ok()) {
+ Some(uuid) => uuid,
+ None => return Vec::new(),
+ };
+ let status_path = Path::new(TAPE_STATUS_DIR);
+ let inventory = match Inventory::load(&status_path) {
+ Ok(inventory) => inventory,
+ Err(_) => return Vec::new(),
+ };
+
+ let mut res = Vec::new();
+ let media_ids = inventory.list_used_media().into_iter().filter(|media| {
+ match &media.media_set_label {
+ Some(label) => label.uuid == media_set_uuid,
+ None => false,
+ }
+ });
+
+ for media_id in media_ids {
+ let catalog = match MediaCatalog::open(status_path, &media_id, false, false) {
+ Ok(catalog) => catalog,
+ Err(_) => continue,
+ };
+
+ for (store, content) in catalog.content() {
+ for snapshot in content.snapshot_index.keys() {
+ res.push(format!("{}:{}", store, snapshot));
+ }
+ }
+ }
+
+ res
+}
--
2.20.1
More information about the pbs-devel
mailing list