From a921c99eb63586d2f6c1d5a8a4e74c32a2d11411 Mon Sep 17 00:00:00 2001 From: Till Wegmueller Date: Mon, 22 Dec 2025 20:11:08 +0100 Subject: [PATCH] Reorder struct fields for consistency and align with Rust formatting standards. --- libips/src/repository/catalog.rs | 52 ++++++++++++++++++-------------- 1 file changed, 29 insertions(+), 23 deletions(-) diff --git a/libips/src/repository/catalog.rs b/libips/src/repository/catalog.rs index e49ec1f..25ff843 100644 --- a/libips/src/repository/catalog.rs +++ b/libips/src/repository/catalog.rs @@ -125,10 +125,6 @@ pub struct UpdateLogInfo { /// Catalog attributes #[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)] pub struct CatalogAttrs { - /// Optional signature information - #[serde(rename = "_SIGNATURE", skip_serializing_if = "Option::is_none")] - pub signature: Option>, - /// Creation timestamp in ISO-8601 'basic format' date in UTC pub created: String, @@ -153,6 +149,10 @@ pub struct CatalogAttrs { /// Catalog version pub version: u32, + + /// Optional signature information + #[serde(rename = "_SIGNATURE", skip_serializing_if = "Option::is_none")] + pub signature: Option>, } impl CatalogAttrs { @@ -206,13 +206,13 @@ pub struct PackageVersionEntry { /// Catalog part (base, dependency, summary) #[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)] pub struct CatalogPart { - /// Optional signature information - #[serde(rename = "_SIGNATURE", skip_serializing_if = "Option::is_none")] - pub signature: Option>, - /// Packages by publisher and stem #[serde(flatten)] pub packages: HashMap>>, + + /// Optional signature information + #[serde(rename = "_SIGNATURE", skip_serializing_if = "Option::is_none")] + pub signature: Option>, } impl CatalogPart { @@ -276,13 +276,11 @@ impl CatalogPart { pub fn load>(path: P) -> Result { let path_ref = path.as_ref(); let json = fs::File::open(path_ref)?; - + // Try to parse the JSON directly match serde_json::from_reader(json) { Ok(part) => Ok(part), - Err(e) => { - Err(CatalogError::JsonSerializationError(e)) - } + Err(e) => Err(CatalogError::JsonSerializationError(e)), } } } @@ -322,12 +320,12 @@ pub struct PackageUpdateEntry { /// Update log #[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)] pub struct UpdateLog { + /// Updates by publisher and stem + pub updates: HashMap>>, + /// Optional signature information #[serde(rename = "_SIGNATURE", skip_serializing_if = "Option::is_none")] pub signature: Option>, - - /// Updates by publisher and stem - pub updates: HashMap>>, } impl UpdateLog { @@ -387,7 +385,7 @@ impl UpdateLog { pub struct CatalogManager { /// Path to the catalog directory catalog_dir: PathBuf, - + /// Publisher name publisher: String, @@ -596,27 +594,35 @@ mod tests { #[test] fn test_load_sample_catalog() { // Path is relative to the crate root (libips) - let path = PathBuf::from("../sample_data/sample-repo/publisher/openindiana.org/catalog/catalog.base.C"); - + let path = PathBuf::from( + "../sample_data/sample-repo/publisher/openindiana.org/catalog/catalog.base.C", + ); + // Only run this test if the sample data exists if path.exists() { println!("Testing with sample catalog at {:?}", path); match CatalogPart::load(&path) { Ok(part) => { println!("Successfully loaded catalog part"); - + // Verify we loaded the correct data structure // The sample file has "openindiana.org" as a key - assert!(part.packages.contains_key("openindiana.org"), "Catalog should contain openindiana.org publisher"); - + assert!( + part.packages.contains_key("openindiana.org"), + "Catalog should contain openindiana.org publisher" + ); + let packages = part.packages.get("openindiana.org").unwrap(); println!("Found {} packages for openindiana.org", packages.len()); assert!(packages.len() > 0, "Should have loaded packages"); - }, + } Err(e) => panic!("Failed to load catalog part: {}", e), } } else { - println!("Sample data not found at {:?}, skipping test. This is expected in some CI environments.", path); + println!( + "Sample data not found at {:?}, skipping test. This is expected in some CI environments.", + path + ); } } }