tape: show catalog status in media list

This commit is contained in:
Dietmar Maurer
2021-01-09 10:24:48 +01:00
parent c7926d8e8c
commit 0bf1c314da
4 changed files with 43 additions and 3 deletions

View File

@ -3,7 +3,7 @@ use std::fs::File;
use std::io::{Write, Read, BufReader, Seek, SeekFrom};
use std::os::unix::io::AsRawFd;
use std::path::Path;
use std::collections::HashMap;
use std::collections::{HashSet, HashMap};
use anyhow::{bail, format_err, Error};
use endian_trait::Endian;
@ -22,6 +22,7 @@ use proxmox::tools::{
};
use crate::{
tools::fs::read_subdir,
backup::BackupDir,
tape::{
MediaId,
@ -58,6 +59,22 @@ pub struct MediaCatalog {
impl MediaCatalog {
/// List media with catalogs
pub fn media_with_catalogs(base_path: &Path) -> Result<HashSet<Uuid>, Error> {
let mut catalogs = HashSet::new();
for entry in read_subdir(libc::AT_FDCWD, base_path)? {
let entry = entry?;
let name = unsafe { entry.file_name_utf8_unchecked() };
if !name.ends_with(".log") { continue; }
if let Ok(uuid) = Uuid::parse_str(&name[..(name.len()-4)]) {
catalogs.insert(uuid);
}
}
Ok(catalogs)
}
/// Test if a catalog exists
pub fn exists(base_path: &Path, uuid: &Uuid) -> bool {
let mut path = base_path.to_owned();