From: Dietmar Maurer <dietmar@proxmox.com>
To: pbs-devel@lists.proxmox.com
Subject: [pbs-devel] [PATCH proxmox-backup v3 1/4] cleanup: factor out tape catalog path helpers
Date: Wed, 28 Jul 2021 11:11:15 +0200 [thread overview]
Message-ID: <20210728091118.581161-2-dietmar@proxmox.com> (raw)
In-Reply-To: <20210728091118.581161-1-dietmar@proxmox.com>
---
src/tape/media_catalog.rs | 43 +++++++++++++++++++--------------------
1 file changed, 21 insertions(+), 22 deletions(-)
diff --git a/src/tape/media_catalog.rs b/src/tape/media_catalog.rs
index 086c8a7d..62c6acb3 100644
--- a/src/tape/media_catalog.rs
+++ b/src/tape/media_catalog.rs
@@ -2,7 +2,7 @@ use std::convert::TryFrom;
use std::fs::File;
use std::io::{Write, Read, BufReader, Seek, SeekFrom};
use std::os::unix::io::AsRawFd;
-use std::path::Path;
+use std::path::{PathBuf, Path};
use std::collections::{HashSet, HashMap};
use anyhow::{bail, format_err, Error};
@@ -95,20 +95,29 @@ impl MediaCatalog {
Ok(catalogs)
}
- /// Test if a catalog exists
- pub fn exists(base_path: &Path, uuid: &Uuid) -> bool {
+ pub fn catalog_path(base_path: &Path, uuid: &Uuid) -> PathBuf {
let mut path = base_path.to_owned();
path.push(uuid.to_string());
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)
pub fn destroy(base_path: &Path, uuid: &Uuid) -> Result<(), Error> {
- let mut path = base_path.to_owned();
- path.push(uuid.to_string());
- path.set_extension("log");
+ let path = Self::catalog_path(base_path, uuid);
match std::fs::remove_file(path) {
Ok(()) => Ok(()),
@@ -125,9 +134,7 @@ impl MediaCatalog {
let uuid = &media_id.label.uuid;
- let mut path = base_path.to_owned();
- path.push(uuid.to_string());
- path.set_extension("log");
+ let path = Self::catalog_path(base_path, uuid);
let file = match std::fs::OpenOptions::new().read(true).open(&path) {
Ok(file) => file,
@@ -198,9 +205,7 @@ impl MediaCatalog {
let uuid = &media_id.label.uuid;
- let mut path = base_path.to_owned();
- path.push(uuid.to_string());
- path.set_extension("log");
+ let path = Self::catalog_path(base_path, uuid);
let me = proxmox::try_block!({
@@ -251,9 +256,7 @@ impl MediaCatalog {
Self::create_basedir(base_path)?;
- let mut tmp_path = base_path.to_owned();
- tmp_path.push(uuid.to_string());
- tmp_path.set_extension("tmp");
+ let tmp_path = Self::tmp_catalog_path(base_path, uuid);
let file = std::fs::OpenOptions::new()
.read(true)
@@ -285,9 +288,7 @@ impl MediaCatalog {
let uuid = &media_id.label.uuid;
- let mut tmp_path = base_path.to_owned();
- tmp_path.push(uuid.to_string());
- tmp_path.set_extension("tmp");
+ let tmp_path = Self::tmp_catalog_path(base_path, uuid);
let me = proxmox::try_block!({
@@ -333,9 +334,7 @@ impl MediaCatalog {
commit: bool,
) -> Result<(), Error> {
- let mut tmp_path = base_path.to_owned();
- tmp_path.push(uuid.to_string());
- tmp_path.set_extension("tmp");
+ let tmp_path = Self::tmp_catalog_path(base_path, uuid);
if commit {
let mut catalog_path = tmp_path.clone();
--
2.30.2
next prev parent reply other threads:[~2021-07-28 9:11 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-07-28 9:11 [pbs-devel] [PATCH proxmox-backup v3 0/4] improve catalog handling Dietmar Maurer
2021-07-28 9:11 ` Dietmar Maurer [this message]
2021-07-28 9:11 ` [pbs-devel] [PATCH proxmox-backup v3 2/4] tape: lock media_catalog file to to get a consistent view with load_catalog Dietmar Maurer
2021-07-28 9:11 ` [pbs-devel] [PATCH proxmox-backup v3 3/4] tape: media_catalog: add snapshot list cache for catalog Dietmar Maurer
2021-07-28 9:11 ` [pbs-devel] [PATCH proxmox-backup v3 4/4] api2: tape: media: use MediaCatalog::snapshot_list for content listing Dietmar Maurer
2021-07-29 12:30 ` [pbs-devel] applied: [PATCH proxmox-backup v3 0/4] improve catalog handling Dietmar Maurer
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20210728091118.581161-2-dietmar@proxmox.com \
--to=dietmar@proxmox.com \
--cc=pbs-devel@lists.proxmox.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.