diff --git a/Cargo.toml b/Cargo.toml index 2927ba7..4d17f54 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -11,3 +11,7 @@ clap = "4.4.2" ion-rs = "0.18.1" ion-schema = "0.9.1" thiserror = "1.0.48" + +[[bin]] +name = "usysconf" +path = "src/bin/usysconf/main.rs" diff --git a/src/cli/mod.rs b/src/bin/usysconf/cli/mod.rs similarity index 100% rename from src/cli/mod.rs rename to src/bin/usysconf/cli/mod.rs diff --git a/src/main.rs b/src/bin/usysconf/main.rs similarity index 92% rename from src/main.rs rename to src/bin/usysconf/main.rs index 7d04e86..8b76db9 100644 --- a/src/main.rs +++ b/src/bin/usysconf/main.rs @@ -3,6 +3,7 @@ // SPDX-License-Identifier: MPL-2.0 mod cli; +mod pathtimes; fn main() -> Result<(), cli::Error> { cli::process() diff --git a/src/bin/usysconf/pathtimes.rs b/src/bin/usysconf/pathtimes.rs new file mode 100644 index 0000000..bd18ca1 --- /dev/null +++ b/src/bin/usysconf/pathtimes.rs @@ -0,0 +1,30 @@ +use std::collections::HashMap; +use std::io::{Read, Write}; + +type Path = String; +type Mtime = i64; + +#[derive(Default)] +pub struct PathTimes { + map: HashMap, +} + +impl PathTimes { + pub fn new(source: impl Read) -> Result { + Ok(Self { + map: bincode::deserialize_from(source)?, + }) + } + + pub fn update(&mut self, path: Path, mtime: Mtime) { + self.map.insert(path, mtime); + } + + pub fn get(&self, path: &Path) -> Option { + self.map.get(path).copied() + } + + pub fn save(&mut self, writer: impl Write) -> Result<(), bincode::Error> { + bincode::serialize_into(writer, &self.map) + } +}