[pbs-devel] [PATCH v3 proxmox-backup 07/20] api: datastore: add trash state filtering for snapshot listing

Christian Ebner c.ebner at proxmox.com
Tue May 13 15:52:34 CEST 2025


Allows to conditionally include, exclude or show trashed backup
snapshots only, the latter being used when displaying the contents of
the trash for given datastore.

Default to exclude snapshots marked as trash from the list.

Signed-off-by: Christian Ebner <c.ebner at proxmox.com>
---
 src/api2/admin/datastore.rs | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)

diff --git a/src/api2/admin/datastore.rs b/src/api2/admin/datastore.rs
index a59e39abe..d371a46b0 100644
--- a/src/api2/admin/datastore.rs
+++ b/src/api2/admin/datastore.rs
@@ -466,6 +466,10 @@ pub async fn delete_snapshot(
                 optional: true,
                 schema: BACKUP_ID_SCHEMA,
             },
+            "trash-state": {
+                type: TrashStateFilter,
+                optional: true,
+            },
         },
     },
     returns: pbs_api_types::ADMIN_DATASTORE_LIST_SNAPSHOTS_RETURN_TYPE,
@@ -481,14 +485,16 @@ pub async fn list_snapshots(
     ns: Option<BackupNamespace>,
     backup_type: Option<BackupType>,
     backup_id: Option<String>,
+    trash_state: Option<TrashStateFilter>,
     _param: Value,
     _info: &ApiMethod,
     rpcenv: &mut dyn RpcEnvironment,
 ) -> Result<Vec<SnapshotListItem>, Error> {
     let auth_id: Authid = rpcenv.get_auth_id().unwrap().parse()?;
+    let trash_state = trash_state.unwrap_or_default();
 
     tokio::task::spawn_blocking(move || unsafe {
-        list_snapshots_blocking(store, ns, backup_type, backup_id, auth_id)
+        list_snapshots_blocking(store, ns, backup_type, backup_id, auth_id, trash_state)
     })
     .await
     .map_err(|err| format_err!("failed to await blocking task: {err}"))?
@@ -501,6 +507,7 @@ unsafe fn list_snapshots_blocking(
     backup_type: Option<BackupType>,
     backup_id: Option<String>,
     auth_id: Authid,
+    trash_state: TrashStateFilter,
 ) -> Result<Vec<SnapshotListItem>, Error> {
     let ns = ns.unwrap_or_default();
 
@@ -627,7 +634,7 @@ unsafe fn list_snapshots_blocking(
             return Ok(snapshots);
         }
 
-        let group_backups = group.list_backups(TrashStateFilter::ExcludeTrash)?;
+        let group_backups = group.list_backups(trash_state)?;
 
         snapshots.extend(
             group_backups
-- 
2.39.5





More information about the pbs-devel mailing list