]>
git.proxmox.com Git - proxmox-backup.git/blob - src/tape/pool_writer/catalog_set.rs
1 use anyhow
::{bail, Error}
;
3 use proxmox_uuid
::Uuid
;
12 /// Helper to build and query sets of catalogs
14 /// Similar to MediaSetCatalog, but allows to modify the last catalog.
15 pub struct CatalogSet
{
17 pub media_set_catalog
: MediaSetCatalog
,
18 // catalog to modify (latest in set)
19 pub catalog
: Option
<MediaCatalog
>,
24 /// Create empty instance
25 pub fn new() -> Self {
27 media_set_catalog
: MediaSetCatalog
::new(),
32 /// Add catalog to the read-only set
33 pub fn append_read_only_catalog(&mut self, catalog
: MediaCatalog
) -> Result
<(), Error
> {
34 self.media_set_catalog
.append_catalog(catalog
)
37 /// Test if the catalog already contains a snapshot
38 pub fn contains_snapshot(&self, store
: &str, snapshot
: &str) -> bool
{
39 if let Some(ref catalog
) = self.catalog
{
40 if catalog
.contains_snapshot(store
, snapshot
) {
44 self.media_set_catalog
.contains_snapshot(store
, snapshot
)
47 /// Test if the catalog already contains a chunk
48 pub fn contains_chunk(&self, store
: &str, digest
: &[u8;32]) -> bool
{
49 if let Some(ref catalog
) = self.catalog
{
50 if catalog
.contains_chunk(store
, digest
) {
54 self.media_set_catalog
.contains_chunk(store
, digest
)
57 /// Add a new catalog, move the old on to the read-only set
58 pub fn append_catalog(&mut self, new_catalog
: MediaCatalog
) -> Result
<(), Error
> {
60 // append current catalog to read-only set
61 if let Some(catalog
) = self.catalog
.take() {
62 self.media_set_catalog
.append_catalog(catalog
)?
;
65 // remove read-only version from set (in case it is there)
66 self.media_set_catalog
.remove_catalog(&new_catalog
.uuid());
68 self.catalog
= Some(new_catalog
);
73 /// Register a snapshot
74 pub fn register_snapshot(
76 uuid
: Uuid
, // Uuid form MediaContentHeader
80 ) -> Result
<(), Error
> {
82 Some(ref mut catalog
) => {
83 catalog
.register_snapshot(uuid
, file_number
, store
, snapshot
)?
;
85 None
=> bail
!("no catalog loaded - internal error"),
90 /// Register a chunk archive
91 pub fn register_chunk_archive(
93 uuid
: Uuid
, // Uuid form MediaContentHeader
96 chunk_list
: &[[u8; 32]],
97 ) -> Result
<(), Error
> {
99 Some(ref mut catalog
) => {
100 catalog
.register_chunk_archive(uuid
, file_number
, store
, chunk_list
)?
;
102 None
=> bail
!("no catalog loaded - internal error"),
107 /// Commit the catalog changes
108 pub fn commit(&mut self) -> Result
<(), Error
> {
109 if let Some(ref mut catalog
) = self.catalog
{