From: "Fabian Grünbichler" <f.gruenbichler@proxmox.com>
To: pbs-devel@lists.proxmox.com
Subject: [pbs-devel] [PATCH proxmox-backup] (List)SyncDirection: extract match check into impl fn
Date: Tue, 26 Nov 2024 10:20:29 +0100 [thread overview]
Message-ID: <20241126092029.207319-1-f.gruenbichler@proxmox.com> (raw)
In-Reply-To: <20241125174012.678523-1-c.ebner@proxmox.com>
in case we add another direction or another call site, doing it without a
wildcard match arm seems cleaner.
Signed-off-by: Fabian Grünbichler <f.gruenbichler@proxmox.com>
---
small cleanup as potential follow-up
src/api2/admin/sync.rs | 16 ++++++++++++----
src/api2/config/sync.rs | 11 +++--------
2 files changed, 15 insertions(+), 12 deletions(-)
diff --git a/src/api2/admin/sync.rs b/src/api2/admin/sync.rs
index 965be8d06..089e6f50d 100644
--- a/src/api2/admin/sync.rs
+++ b/src/api2/admin/sync.rs
@@ -47,6 +47,16 @@ impl From<SyncDirection> for ListSyncDirection {
}
}
+impl ListSyncDirection {
+ /// Checks whether a `ListSyncDirection` matches a given `SyncDirection`
+ pub fn matches(&self, other: SyncDirection) -> bool {
+ if *self == ListSyncDirection::All {
+ return true;
+ }
+ *self == other.into()
+ }
+}
+
#[api(
input: {
properties: {
@@ -94,10 +104,8 @@ pub fn list_config_sync_jobs(
_ => {}
}
- match &sync_direction {
- ListSyncDirection::Pull if direction != SyncDirection::Pull => continue,
- ListSyncDirection::Push if direction != SyncDirection::Push => continue,
- _ => {}
+ if !sync_direction.matches(direction) {
+ continue;
}
if !check_sync_job_read_access(&user_info, &auth_id, &job) {
diff --git a/src/api2/config/sync.rs b/src/api2/config/sync.rs
index e8a1ad076..bc012744a 100644
--- a/src/api2/config/sync.rs
+++ b/src/api2/config/sync.rs
@@ -15,9 +15,9 @@ use pbs_api_types::{
};
use pbs_config::sync;
+use crate::api2::admin::sync::ListSyncDirection;
use pbs_config::CachedUserInfo;
use pbs_datastore::check_backup_owner;
-use crate::api2::admin::sync::ListSyncDirection;
pub fn check_sync_job_read_access(
user_info: &CachedUserInfo,
@@ -185,13 +185,8 @@ pub fn list_sync_jobs(
let list = list
.into_iter()
.filter(|sync_job| {
- let direction = sync_job.sync_direction.unwrap_or_default();
- match &sync_direction {
- ListSyncDirection::Pull if direction != SyncDirection::Pull => return false,
- ListSyncDirection::Push if direction != SyncDirection::Push => return false,
- _ => {}
- }
- check_sync_job_read_access(&user_info, &auth_id, sync_job)
+ sync_direction.matches(sync_job.sync_direction.unwrap_or_default())
+ && check_sync_job_read_access(&user_info, &auth_id, sync_job)
})
.collect();
Ok(list)
--
2.39.5
_______________________________________________
pbs-devel mailing list
pbs-devel@lists.proxmox.com
https://lists.proxmox.com/cgi-bin/mailman/listinfo/pbs-devel
next prev parent reply other threads:[~2024-11-26 9:21 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-11-25 17:40 [pbs-devel] [PATCH proxmox-backup 0/4] use same config section type for all sync jobs Christian Ebner
2024-11-25 17:40 ` [pbs-devel] [PATCH proxmox-backup 1/4] config: sync: use same config section type `sync` for push and pull Christian Ebner
2024-11-25 17:40 ` [pbs-devel] [PATCH proxmox-backup 2/4] api: admin/config: introduce sync direction as job config parameter Christian Ebner
2024-11-25 17:40 ` [pbs-devel] [PATCH proxmox-backup 3/4] bin: show direction in sync job list output Christian Ebner
2024-11-25 17:40 ` [pbs-devel] [PATCH proxmox-backup 4/4] api types: drop unused config type helpers for sync direction Christian Ebner
2024-11-26 9:20 ` Fabian Grünbichler [this message]
2024-11-26 9:21 ` [pbs-devel] [PATCH proxmox-backup 0/4] use same config section type for all sync jobs Fabian Grünbichler
2024-11-26 14:47 ` [pbs-devel] [PATCH proxmox-backup] sync jobs: remove superfluous direction property Dominik Csapak
2024-11-26 14:50 ` [pbs-devel] [PATCH proxmox-backup 0/4] use same config section type for all sync jobs Dominik Csapak
2024-11-26 15:04 ` [pbs-devel] applied-series: " Thomas Lamprecht
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=20241126092029.207319-1-f.gruenbichler@proxmox.com \
--to=f.gruenbichler@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.