all lists on lists.proxmox.com
 help / color / mirror / Atom feed
* [pbs-devel] [PATCH proxmox-backup 1/2] api types: version: add helper for min version checks
@ 2024-11-28 12:49 Christian Ebner
  2024-11-28 12:49 ` [pbs-devel] [PATCH proxmox-backup 2/2] sync: push: use min version helper for api compatibility checks Christian Ebner
                   ` (2 more replies)
  0 siblings, 3 replies; 8+ messages in thread
From: Christian Ebner @ 2024-11-28 12:49 UTC (permalink / raw)
  To: pbs-devel

Add a helper method to the ApiVersion type to reduce possible errors
when comparing api versions for feature compatibility checks.

Signed-off-by: Christian Ebner <c.ebner@proxmox.com>
---
 pbs-api-types/src/version.rs | 33 +++++++++++++++++++++++++++++++++
 1 file changed, 33 insertions(+)

diff --git a/pbs-api-types/src/version.rs b/pbs-api-types/src/version.rs
index 80f87e372..5f8efb663 100644
--- a/pbs-api-types/src/version.rs
+++ b/pbs-api-types/src/version.rs
@@ -1,4 +1,5 @@
 //! Defines the types for the api version info endpoint
+use std::cmp::Ordering;
 use std::convert::TryFrom;
 
 use anyhow::{format_err, Context};
@@ -68,3 +69,35 @@ impl TryFrom<ApiVersionInfo> for ApiVersion {
         })
     }
 }
+
+impl ApiVersion {
+    pub fn new(
+        major: ApiVersionMajor,
+        minor: ApiVersionMinor,
+        release: ApiVersionRelease,
+        repoid: String,
+    ) -> Self {
+        Self {
+            major,
+            minor,
+            release,
+            repoid,
+        }
+    }
+
+    pub fn is_min_required(&self, version: ApiVersion) -> bool {
+        match (
+            version.major.cmp(&self.major),
+            version.minor.cmp(&self.minor),
+            version.release.cmp(&self.release),
+        ) {
+            (Ordering::Less, _, _) => true,
+            (Ordering::Greater, _, _) => false,
+            (Ordering::Equal, Ordering::Less, _) => true,
+            (Ordering::Equal, Ordering::Greater, _) => false,
+            (Ordering::Equal, Ordering::Equal, Ordering::Less) => true,
+            (Ordering::Equal, Ordering::Equal, Ordering::Equal) => true,
+            (Ordering::Equal, Ordering::Equal, Ordering::Greater) => false,
+        }
+    }
+}
-- 
2.39.5



_______________________________________________
pbs-devel mailing list
pbs-devel@lists.proxmox.com
https://lists.proxmox.com/cgi-bin/mailman/listinfo/pbs-devel


^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2024-11-28 16:09 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-11-28 12:49 [pbs-devel] [PATCH proxmox-backup 1/2] api types: version: add helper for min version checks Christian Ebner
2024-11-28 12:49 ` [pbs-devel] [PATCH proxmox-backup 2/2] sync: push: use min version helper for api compatibility checks Christian Ebner
2024-11-28 13:10 ` [pbs-devel] [PATCH proxmox-backup 1/2] api types: version: add helper for min version checks Thomas Lamprecht
2024-11-28 13:14   ` Christian Ebner
2024-11-28 13:18     ` Thomas Lamprecht
2024-11-28 13:49       ` Christian Ebner
2024-11-28 13:50         ` Thomas Lamprecht
2024-11-28 16:09 ` Christian Ebner

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.
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal