From 95b273a7b6d833beb33724c956f6abc0b1b37922 Mon Sep 17 00:00:00 2001 From: Rich FitzJohn Date: Mon, 9 Jun 2025 11:16:18 +0100 Subject: [PATCH 1/6] Add additional metadata --- Cargo.toml | 2 +- src/config.rs | 19 ++++++++++++++++++- 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index b6ee070..5e11e3b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "outpack" -version = "0.3.2" +version = "0.3.3" edition = "2021" rust-version = "1.70" build = "build.rs" diff --git a/src/config.rs b/src/config.rs index bcbfd57..56ddc51 100644 --- a/src/config.rs +++ b/src/config.rs @@ -6,13 +6,22 @@ use std::result::Result; use crate::hash::HashAlgorithm; +#[derive(Serialize, Deserialize, Debug, PartialEq)] +pub struct Empty {} + #[derive(Serialize, Deserialize, Debug, PartialEq)] pub struct Location { // Practically, doing anything with locations (therefore needing // access to the "type" and "args" fields) is going to require we // know how to deserialise into a union type; for example // https://stackoverflow.com/q/66964692 + // + // However, we need to support the 'local' type, which takes no + // arguments, so implement enough here to be able to write one. pub name: String, + #[serde(rename = "type")] + pub loc_type: String, + pub args: Empty, } #[derive(Serialize, Deserialize, Debug, PartialEq)] @@ -48,7 +57,12 @@ impl Config { use_file_store, require_complete_tree, }; - let location: Vec = Vec::new(); + let local = Location { + name: String::from("local"), + loc_type: String::from("local"), + args: Empty {}, + }; + let location: Vec = vec![local]; Ok(Config { core, location }) } } @@ -86,6 +100,9 @@ mod tests { #[test] fn can_write_config() { let cfg = Config::new(None, true, true).unwrap(); + assert_eq!(cfg.location.len(), 1); + assert_eq!(cfg.location[0].name, String::from("local")); + assert_eq!(cfg.location[0].loc_type, String::from("local")); let tmp = tempfile::TempDir::new().unwrap(); let path = tmp.path(); fs::create_dir_all(path.join(".outpack")).unwrap(); From 93448ae2e69beed4571db1fef90d920e5e641fc9 Mon Sep 17 00:00:00 2001 From: Rich FitzJohn Date: Mon, 9 Jun 2025 17:28:24 +0100 Subject: [PATCH 2/6] Apply suggestions from code review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Paul LiƩtar --- src/config.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/config.rs b/src/config.rs index 56ddc51..12cb4c6 100644 --- a/src/config.rs +++ b/src/config.rs @@ -21,7 +21,7 @@ pub struct Location { pub name: String, #[serde(rename = "type")] pub loc_type: String, - pub args: Empty, + pub args: HashMap, } #[derive(Serialize, Deserialize, Debug, PartialEq)] @@ -101,8 +101,8 @@ mod tests { fn can_write_config() { let cfg = Config::new(None, true, true).unwrap(); assert_eq!(cfg.location.len(), 1); - assert_eq!(cfg.location[0].name, String::from("local")); - assert_eq!(cfg.location[0].loc_type, String::from("local")); + assert_eq!(cfg.location[0].name, "local"); + assert_eq!(cfg.location[0].loc_type, "local"); let tmp = tempfile::TempDir::new().unwrap(); let path = tmp.path(); fs::create_dir_all(path.join(".outpack")).unwrap(); From 2ed34415fcc09133e9ab6fe055b1f3fd402005ec Mon Sep 17 00:00:00 2001 From: Rich FitzJohn Date: Mon, 9 Jun 2025 17:34:19 +0100 Subject: [PATCH 3/6] Small tweaks after review comments --- Cargo.toml | 2 +- src/config.rs | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 5e11e3b..b6ee070 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "outpack" -version = "0.3.3" +version = "0.3.2" edition = "2021" rust-version = "1.70" build = "build.rs" diff --git a/src/config.rs b/src/config.rs index 12cb4c6..f957200 100644 --- a/src/config.rs +++ b/src/config.rs @@ -1,4 +1,5 @@ use serde::{Deserialize, Serialize}; +use std::collections::HashMap; use std::fs; use std::io::Error; use std::path::Path; @@ -60,7 +61,7 @@ impl Config { let local = Location { name: String::from("local"), loc_type: String::from("local"), - args: Empty {}, + args: HashMap::new(), }; let location: Vec = vec![local]; Ok(Config { core, location }) From 433685f31d233d4cf58f9dbc6895d00639a7f73e Mon Sep 17 00:00:00 2001 From: Rich FitzJohn Date: Mon, 9 Jun 2025 17:39:59 +0100 Subject: [PATCH 4/6] Fix demo config --- tests/example/.outpack/config.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/example/.outpack/config.json b/tests/example/.outpack/config.json index 5b86215..737018a 100644 --- a/tests/example/.outpack/config.json +++ b/tests/example/.outpack/config.json @@ -10,12 +10,12 @@ { "name": "local", "type": "local", - "args": [] + "args": {} }, { "name": "another", "type": "file", - "args": [] + "args": {} } ] } From d14e0074a770872ffd86f10090bb806d6f410f2c Mon Sep 17 00:00:00 2001 From: Rich FitzJohn Date: Mon, 9 Jun 2025 17:40:32 +0100 Subject: [PATCH 5/6] Fix bad config --- tests/bad-example/.outpack/config.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/bad-example/.outpack/config.json b/tests/bad-example/.outpack/config.json index c1289e4..8141910 100644 --- a/tests/bad-example/.outpack/config.json +++ b/tests/bad-example/.outpack/config.json @@ -10,7 +10,7 @@ { "name": "another", "type": "file", - "args": [] + "args": {} } ] } From 8c902c044fbb58ed415d97cabea0e0c28a939cae Mon Sep 17 00:00:00 2001 From: Rich FitzJohn Date: Mon, 9 Jun 2025 17:40:46 +0100 Subject: [PATCH 6/6] Drop empty struct --- src/config.rs | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/config.rs b/src/config.rs index f957200..2a7de3f 100644 --- a/src/config.rs +++ b/src/config.rs @@ -7,9 +7,6 @@ use std::result::Result; use crate::hash::HashAlgorithm; -#[derive(Serialize, Deserialize, Debug, PartialEq)] -pub struct Empty {} - #[derive(Serialize, Deserialize, Debug, PartialEq)] pub struct Location { // Practically, doing anything with locations (therefore needing