summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--cli/src/main.rs13
1 files changed, 8 insertions, 5 deletions
diff --git a/cli/src/main.rs b/cli/src/main.rs
index 8f9cccf..f853bd2 100644
--- a/cli/src/main.rs
+++ b/cli/src/main.rs
@@ -72,11 +72,8 @@ impl Store {
fn write(&self) -> std::io::Result<()> {
for post in &self.posts {
- let mut h = XxHash64::default();
- post.hash(&mut h);
- let h = h.finish();
let mut path = self.root.clone();
- path.push(format!("{}", h));
+ path.push(format!("{}", post.id()));
post.write(&path)?;
}
Ok(())
@@ -99,6 +96,12 @@ impl Post {
fn open<P: AsRef<Path>>(p: &P) -> Option<Self> {
fs::read_to_string(p).ok().as_ref().and_then(|s| serde_json::from_str(s).ok())
}
+
+ fn id(&self) -> u64 {
+ let mut h = XxHash64::default();
+ self.hash(&mut h);
+ h.finish()
+ }
}
fn main() {
@@ -113,5 +116,5 @@ fn main() {
// post.write(&"test").unwrap();
let store = Store::open(PathBuf::from("store")).unwrap();
// println!("{:#?}", store);
- store.write();
+ store.write().unwrap();
}