cleanup: factor out tape catalog path helpers
This commit is contained in:
parent
4f57f4ad84
commit
0d5e990a62
@ -2,7 +2,7 @@ use std::convert::TryFrom;
|
|||||||
use std::fs::File;
|
use std::fs::File;
|
||||||
use std::io::{Write, Read, BufReader, Seek, SeekFrom};
|
use std::io::{Write, Read, BufReader, Seek, SeekFrom};
|
||||||
use std::os::unix::io::AsRawFd;
|
use std::os::unix::io::AsRawFd;
|
||||||
use std::path::Path;
|
use std::path::{PathBuf, Path};
|
||||||
use std::collections::{HashSet, HashMap};
|
use std::collections::{HashSet, HashMap};
|
||||||
|
|
||||||
use anyhow::{bail, format_err, Error};
|
use anyhow::{bail, format_err, Error};
|
||||||
@ -95,20 +95,29 @@ impl MediaCatalog {
|
|||||||
Ok(catalogs)
|
Ok(catalogs)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Test if a catalog exists
|
pub fn catalog_path(base_path: &Path, uuid: &Uuid) -> PathBuf {
|
||||||
pub fn exists(base_path: &Path, uuid: &Uuid) -> bool {
|
|
||||||
let mut path = base_path.to_owned();
|
let mut path = base_path.to_owned();
|
||||||
path.push(uuid.to_string());
|
path.push(uuid.to_string());
|
||||||
path.set_extension("log");
|
path.set_extension("log");
|
||||||
path.exists()
|
path
|
||||||
|
}
|
||||||
|
|
||||||
|
fn tmp_catalog_path(base_path: &Path, uuid: &Uuid) -> PathBuf {
|
||||||
|
let mut path = base_path.to_owned();
|
||||||
|
path.push(uuid.to_string());
|
||||||
|
path.set_extension("tmp");
|
||||||
|
path
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Test if a catalog exists
|
||||||
|
pub fn exists(base_path: &Path, uuid: &Uuid) -> bool {
|
||||||
|
Self::catalog_path(base_path, uuid).exists()
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Destroy the media catalog (remove all files)
|
/// Destroy the media catalog (remove all files)
|
||||||
pub fn destroy(base_path: &Path, uuid: &Uuid) -> Result<(), Error> {
|
pub fn destroy(base_path: &Path, uuid: &Uuid) -> Result<(), Error> {
|
||||||
|
|
||||||
let mut path = base_path.to_owned();
|
let path = Self::catalog_path(base_path, uuid);
|
||||||
path.push(uuid.to_string());
|
|
||||||
path.set_extension("log");
|
|
||||||
|
|
||||||
match std::fs::remove_file(path) {
|
match std::fs::remove_file(path) {
|
||||||
Ok(()) => Ok(()),
|
Ok(()) => Ok(()),
|
||||||
@ -125,9 +134,7 @@ impl MediaCatalog {
|
|||||||
|
|
||||||
let uuid = &media_id.label.uuid;
|
let uuid = &media_id.label.uuid;
|
||||||
|
|
||||||
let mut path = base_path.to_owned();
|
let path = Self::catalog_path(base_path, uuid);
|
||||||
path.push(uuid.to_string());
|
|
||||||
path.set_extension("log");
|
|
||||||
|
|
||||||
let file = match std::fs::OpenOptions::new().read(true).open(&path) {
|
let file = match std::fs::OpenOptions::new().read(true).open(&path) {
|
||||||
Ok(file) => file,
|
Ok(file) => file,
|
||||||
@ -198,9 +205,7 @@ impl MediaCatalog {
|
|||||||
|
|
||||||
let uuid = &media_id.label.uuid;
|
let uuid = &media_id.label.uuid;
|
||||||
|
|
||||||
let mut path = base_path.to_owned();
|
let path = Self::catalog_path(base_path, uuid);
|
||||||
path.push(uuid.to_string());
|
|
||||||
path.set_extension("log");
|
|
||||||
|
|
||||||
let me = proxmox::try_block!({
|
let me = proxmox::try_block!({
|
||||||
|
|
||||||
@ -251,9 +256,7 @@ impl MediaCatalog {
|
|||||||
|
|
||||||
Self::create_basedir(base_path)?;
|
Self::create_basedir(base_path)?;
|
||||||
|
|
||||||
let mut tmp_path = base_path.to_owned();
|
let tmp_path = Self::tmp_catalog_path(base_path, uuid);
|
||||||
tmp_path.push(uuid.to_string());
|
|
||||||
tmp_path.set_extension("tmp");
|
|
||||||
|
|
||||||
let file = std::fs::OpenOptions::new()
|
let file = std::fs::OpenOptions::new()
|
||||||
.read(true)
|
.read(true)
|
||||||
@ -285,9 +288,7 @@ impl MediaCatalog {
|
|||||||
|
|
||||||
let uuid = &media_id.label.uuid;
|
let uuid = &media_id.label.uuid;
|
||||||
|
|
||||||
let mut tmp_path = base_path.to_owned();
|
let tmp_path = Self::tmp_catalog_path(base_path, uuid);
|
||||||
tmp_path.push(uuid.to_string());
|
|
||||||
tmp_path.set_extension("tmp");
|
|
||||||
|
|
||||||
let me = proxmox::try_block!({
|
let me = proxmox::try_block!({
|
||||||
|
|
||||||
@ -333,9 +334,7 @@ impl MediaCatalog {
|
|||||||
commit: bool,
|
commit: bool,
|
||||||
) -> Result<(), Error> {
|
) -> Result<(), Error> {
|
||||||
|
|
||||||
let mut tmp_path = base_path.to_owned();
|
let tmp_path = Self::tmp_catalog_path(base_path, uuid);
|
||||||
tmp_path.push(uuid.to_string());
|
|
||||||
tmp_path.set_extension("tmp");
|
|
||||||
|
|
||||||
if commit {
|
if commit {
|
||||||
let mut catalog_path = tmp_path.clone();
|
let mut catalog_path = tmp_path.clone();
|
||||||
|
Loading…
Reference in New Issue
Block a user