]> git.proxmox.com Git - proxmox.git/commitdiff
rrd: feature-gate support for the v1 format
authorLukas Wagner <l.wagner@proxmox.com>
Wed, 31 Jan 2024 13:51:54 +0000 (14:51 +0100)
committerLukas Wagner <l.wagner@proxmox.com>
Thu, 1 Feb 2024 09:32:19 +0000 (10:32 +0100)
new users of this crate might not really need support for the v1
format.

Signed-off-by: Lukas Wagner <l.wagner@proxmox.com>
proxmox-rrd/Cargo.toml
proxmox-rrd/src/lib.rs
proxmox-rrd/src/rrd.rs
proxmox-rrd/tests/file_format_test.rs

index 630ecec395ac57ad49eb7441af4b8f952f024c71..5f8de386571a563a234af092b2be2f9a50ad29b4 100644 (file)
@@ -25,3 +25,7 @@ serde_json.workspace = true
 proxmox-schema = { workspace = true, features = [ "api-macro" ] }
 proxmox-sys.workspace = true
 proxmox-time.workspace = true
+
+[features]
+default = [ "rrd_v1" ]
+rrd_v1 = []
index 80b394383324fcbd7a1921b631093db1c6843547..65e0424792b7b72cff130ad9837d83253240af6e 100644 (file)
@@ -6,6 +6,7 @@
 //! * Stores data for different time resolution
 //! * Simple cache implementation with journal support
 
+#[cfg(feature = "rrd_v1")]
 mod rrd_v1;
 
 pub mod rrd;
index 0b8ac460b1aa3e4d4bb294efec493144d6bd9ae1..1aec9c799a74eca4150a239839113396667e94fe 100644 (file)
@@ -21,8 +21,6 @@ use serde::{Deserialize, Serialize};
 use proxmox_schema::api;
 use proxmox_sys::fs::{make_tmp_file, CreateOptions};
 
-use crate::rrd_v1;
-
 /// Proxmox RRD v2 file magic number
 // openssl::sha::sha256(b"Proxmox Round Robin Database file v2.0")[0..8];
 pub const PROXMOX_RRD_MAGIC_2_0: [u8; 8] = [224, 200, 228, 27, 239, 112, 122, 159];
@@ -366,15 +364,18 @@ impl RRD {
             bail!("not an rrd file - file is too small ({})", raw.len());
         }
 
-        let rrd = if raw[0..8] == rrd_v1::PROXMOX_RRD_MAGIC_1_0 {
-            let v1 = rrd_v1::RRDv1::from_raw(raw)?;
-            v1.to_rrd_v2()
-                .map_err(|err| format_err!("unable to convert from old V1 format - {}", err))?
-        } else if raw[0..8] == PROXMOX_RRD_MAGIC_2_0 {
-            serde_cbor::from_slice(&raw[8..])
-                .map_err(|err| format_err!("unable to decode RRD file - {}", err))?
-        } else {
-            bail!("not an rrd file - unknown magic number");
+        let rrd: RRD = match &raw[0..8] {
+            #[cfg(feature = "rrd_v1")]
+            magic if magic == crate::rrd_v1::PROXMOX_RRD_MAGIC_1_0 => {
+                let v1 = crate::rrd_v1::RRDv1::from_raw(raw)?;
+                v1.to_rrd_v2()
+                    .map_err(|err| format_err!("unable to convert from old V1 format - {err}"))?
+            }
+            magic if magic == PROXMOX_RRD_MAGIC_2_0 => {
+                serde_cbor::from_slice(&raw[8..])
+                    .map_err(|err| format_err!("unable to decode RRD file - {err}"))?
+            }
+            _ => bail!("not an rrd file - unknown magic number")
         };
 
         if rrd.source.last_update < 0.0 {
index 372a407776f42c7a59857bc3cab86461c2e070f4..e05c48537aa95d7a53bef8fc61a1632863eebf82 100644 (file)
@@ -20,12 +20,13 @@ fn compare_file(fn1: &str, fn2: &str) -> Result<(), Error> {
     Ok(())
 }
 
-const RRD_V1_FN: &str = "./tests/testdata/cpu.rrd_v1";
 const RRD_V2_FN: &str = "./tests/testdata/cpu.rrd_v2";
 
 // make sure we can load and convert RRD v1
 #[test]
+#[cfg(feature = "rrd_v1")]
 fn upgrade_from_rrd_v1() -> Result<(), Error> {
+    const RRD_V1_FN: &str = "./tests/testdata/cpu.rrd_v1";
     let rrd = RRD::load(Path::new(RRD_V1_FN), true)?;
 
     const RRD_V2_NEW_FN: &str = "./tests/testdata/cpu.rrd_v2.upgraded";