From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <d.csapak@proxmox.com>
Received: from firstgate.proxmox.com (firstgate.proxmox.com [212.224.123.68])
 (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)
 key-exchange X25519 server-signature RSA-PSS (2048 bits))
 (No client certificate requested)
 by lists.proxmox.com (Postfix) with ESMTPS id 395E470F0C
 for <pbs-devel@lists.proxmox.com>; Tue, 17 May 2022 08:52:49 +0200 (CEST)
Received: from firstgate.proxmox.com (localhost [127.0.0.1])
 by firstgate.proxmox.com (Proxmox) with ESMTP id 2EC952484B
 for <pbs-devel@lists.proxmox.com>; Tue, 17 May 2022 08:52:19 +0200 (CEST)
Received: from proxmox-new.maurer-it.com (proxmox-new.maurer-it.com
 [94.136.29.106])
 (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)
 key-exchange X25519 server-signature RSA-PSS (2048 bits))
 (No client certificate requested)
 by firstgate.proxmox.com (Proxmox) with ESMTPS id 6264E2483C
 for <pbs-devel@lists.proxmox.com>; Tue, 17 May 2022 08:52:18 +0200 (CEST)
Received: from proxmox-new.maurer-it.com (localhost.localdomain [127.0.0.1])
 by proxmox-new.maurer-it.com (Proxmox) with ESMTP id 3721C4366E
 for <pbs-devel@lists.proxmox.com>; Tue, 17 May 2022 08:52:18 +0200 (CEST)
From: Dominik Csapak <d.csapak@proxmox.com>
To: pbs-devel@lists.proxmox.com
Date: Tue, 17 May 2022 08:52:11 +0200
Message-Id: <20220517065215.327699-1-d.csapak@proxmox.com>
X-Mailer: git-send-email 2.30.2
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit
X-SPAM-LEVEL: Spam detection results:  0
 AWL 0.119 Adjusted score from AWL reputation of From: address
 BAYES_00                 -1.9 Bayes spam probability is 0 to 1%
 KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment
 SPF_HELO_NONE           0.001 SPF: HELO does not publish an SPF Record
 SPF_PASS               -0.001 SPF: sender matches SPF record
 T_SCC_BODY_TEXT_LINE    -0.01 -
 URIBL_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to URIBL was blocked. See
 http://wiki.apache.org/spamassassin/DnsBlocklists#dnsbl-block for more
 information. [mod.rs, backup.rs]
Subject: [pbs-devel] [PATCH proxmox-backup 1/5] tape/pool_writer: give
 proper types to 'contains_snapshot'
X-BeenThere: pbs-devel@lists.proxmox.com
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: Proxmox Backup Server development discussion
 <pbs-devel.lists.proxmox.com>
List-Unsubscribe: <https://lists.proxmox.com/cgi-bin/mailman/options/pbs-devel>, 
 <mailto:pbs-devel-request@lists.proxmox.com?subject=unsubscribe>
List-Archive: <http://lists.proxmox.com/pipermail/pbs-devel/>
List-Post: <mailto:pbs-devel@lists.proxmox.com>
List-Help: <mailto:pbs-devel-request@lists.proxmox.com?subject=help>
List-Subscribe: <https://lists.proxmox.com/cgi-bin/mailman/listinfo/pbs-devel>, 
 <mailto:pbs-devel-request@lists.proxmox.com?subject=subscribe>
X-List-Received-Date: Tue, 17 May 2022 06:52:49 -0000

instead of a string. The underlying catalog implementation has to
care about how this is formatted, not the external caller

Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
---
 src/api2/tape/backup.rs             | 12 ++++++++++--
 src/tape/media_catalog.rs           | 19 +++++++++++++++----
 src/tape/pool_writer/catalog_set.rs | 12 +++++++++---
 src/tape/pool_writer/mod.rs         |  9 +++++++--
 4 files changed, 41 insertions(+), 11 deletions(-)

diff --git a/src/api2/tape/backup.rs b/src/api2/tape/backup.rs
index c7d042fb..ba08994f 100644
--- a/src/api2/tape/backup.rs
+++ b/src/api2/tape/backup.rs
@@ -496,7 +496,11 @@ fn backup_worker(
             if let Some(info) = snapshot_list.pop() {
                 let rel_path =
                     print_ns_and_snapshot(info.backup_dir.backup_ns(), info.backup_dir.as_ref());
-                if pool_writer.contains_snapshot(datastore_name, &rel_path) {
+                if pool_writer.contains_snapshot(
+                    datastore_name,
+                    &info.backup_dir.backup_ns(),
+                    info.backup_dir.as_ref(),
+                ) {
                     task_log!(worker, "skip snapshot {}", rel_path);
                     continue;
                 }
@@ -517,7 +521,11 @@ fn backup_worker(
                 let rel_path =
                     print_ns_and_snapshot(info.backup_dir.backup_ns(), info.backup_dir.as_ref());
 
-                if pool_writer.contains_snapshot(datastore_name, &rel_path) {
+                if pool_writer.contains_snapshot(
+                    datastore_name,
+                    &info.backup_dir.backup_ns(),
+                    info.backup_dir.as_ref(),
+                ) {
                     task_log!(worker, "skip snapshot {}", rel_path);
                     continue;
                 }
diff --git a/src/tape/media_catalog.rs b/src/tape/media_catalog.rs
index 85128f80..38fdcc6e 100644
--- a/src/tape/media_catalog.rs
+++ b/src/tape/media_catalog.rs
@@ -411,10 +411,16 @@ impl MediaCatalog {
     }
 
     /// Test if the catalog already contain a snapshot
-    pub fn contains_snapshot(&self, store: &str, snapshot: &str) -> bool {
+    pub fn contains_snapshot(
+        &self,
+        store: &str,
+        ns: &BackupNamespace,
+        snapshot: &BackupDir,
+    ) -> bool {
+        let path = print_ns_and_snapshot(ns, snapshot);
         match self.content.get(store) {
             None => false,
-            Some(content) => content.snapshot_index.contains_key(snapshot),
+            Some(content) => content.snapshot_index.contains_key(&path),
         }
     }
 
@@ -960,9 +966,14 @@ impl MediaSetCatalog {
     }
 
     /// Test if the catalog already contain a snapshot
-    pub fn contains_snapshot(&self, store: &str, snapshot: &str) -> bool {
+    pub fn contains_snapshot(
+        &self,
+        store: &str,
+        ns: &BackupNamespace,
+        snapshot: &BackupDir,
+    ) -> bool {
         for catalog in self.catalog_list.values() {
-            if catalog.contains_snapshot(store, snapshot) {
+            if catalog.contains_snapshot(store, ns, snapshot) {
                 return true;
             }
         }
diff --git a/src/tape/pool_writer/catalog_set.rs b/src/tape/pool_writer/catalog_set.rs
index 1acc108a..d588df18 100644
--- a/src/tape/pool_writer/catalog_set.rs
+++ b/src/tape/pool_writer/catalog_set.rs
@@ -29,13 +29,19 @@ impl CatalogSet {
     }
 
     /// Test if the catalog already contains a snapshot
-    pub fn contains_snapshot(&self, store: &str, snapshot: &str) -> bool {
+    pub fn contains_snapshot(
+        &self,
+        store: &str,
+        ns: &pbs_api_types::BackupNamespace,
+        snapshot: &pbs_api_types::BackupDir,
+    ) -> bool {
         if let Some(ref catalog) = self.catalog {
-            if catalog.contains_snapshot(store, snapshot) {
+            if catalog.contains_snapshot(store, ns, snapshot) {
                 return true;
             }
         }
-        self.media_set_catalog.contains_snapshot(store, snapshot)
+        self.media_set_catalog
+            .contains_snapshot(store, ns, snapshot)
     }
 
     /// Test if the catalog already contains a chunk
diff --git a/src/tape/pool_writer/mod.rs b/src/tape/pool_writer/mod.rs
index d00c16e6..b2ff8620 100644
--- a/src/tape/pool_writer/mod.rs
+++ b/src/tape/pool_writer/mod.rs
@@ -100,11 +100,16 @@ impl PoolWriter {
         Ok(())
     }
 
-    pub fn contains_snapshot(&self, store: &str, snapshot: &str) -> bool {
+    pub fn contains_snapshot(
+        &self,
+        store: &str,
+        ns: &pbs_api_types::BackupNamespace,
+        snapshot: &pbs_api_types::BackupDir,
+    ) -> bool {
         self.catalog_set
             .lock()
             .unwrap()
-            .contains_snapshot(store, snapshot)
+            .contains_snapshot(store, ns, snapshot)
     }
 
     /// Eject media and drop PoolWriterState (close drive)
-- 
2.30.2