summary refs log tree commit diff stats
path: root/src/posts.rs
diff options
context:
space:
mode:
authorBen Morrison <ben@gbmor.dev>2020-06-16 20:05:30 -0400
committerBen Morrison <ben@gbmor.dev>2020-06-16 20:14:37 -0400
commit0fe685c34c5cdbff278b70c98241b0aa7c5bd6ed (patch)
tree5468c2a6d278d901f28085d3b2f1b41a1df4f860 /src/posts.rs
parent40bb48bb701f88c902b912fb51fea88b5ae9a8b8 (diff)
downloadclinte-0fe685c34c5cdbff278b70c98241b0aa7c5bd6ed.tar.gz
moved hashing to shellscript to check for posts
removes dependency on sha2 crate and allows users
to choose their own hashing algorithm easily.

now copies clinte.json to $HOME/.clinte.json once
the posts are viewed. a shellscript can be used to
compare the hash of the global clinte.json to the
hash of the copy. an example script is supplied.

on `make install` the example script is installed
to /etc/profile.d/, where it will be run for users
on login.
Diffstat (limited to 'src/posts.rs')
-rw-r--r--src/posts.rs17
1 files changed, 16 insertions, 1 deletions
diff --git a/src/posts.rs b/src/posts.rs
index 0de3d52..1dfd167 100644
--- a/src/posts.rs
+++ b/src/posts.rs
@@ -1,5 +1,8 @@
 use std::io;
 
+#[cfg(not(test))]
+use std::{env, fs};
+
 use crate::conf;
 use crate::db;
 use crate::error;
@@ -83,7 +86,6 @@ pub fn display() -> error::Result<()> {
         .unwrap_or_else(|_| 80);
 
     let all = db::Posts::get_all(db::PATH);
-    all.hash()?;
 
     let mut postvec = Vec::new();
     all.posts().iter().enumerate().for_each(|(id, post)| {
@@ -117,6 +119,19 @@ pub fn display() -> error::Result<()> {
         }
     }
 
+    // copy the json file to the user's home directory
+    // so it can be compared to the global file to check
+    // for new posts.
+    // previously, I'd hashed it, but I feel like it's
+    // better to leave the hashing to UNIX utilities
+    // than to add a heavy-ish dependency.
+    #[cfg(not(test))]
+    {
+        let homedir = env::var("HOME")?;
+        let localdest = format!("{}/.clinte.json", homedir);
+        fs::copy(db::PATH, localdest)?;
+    }
+
     Ok(())
 }
 
committer Kartik Agaram <vc@akkartik.com> 2020-09-07 16:39:44 -0700 6746' href='/akkartik/mu/commit/html/404stream.mu.html?h=hlt&id=68df24fa778f7f5a2651a4623681f38dc920c490'>68df24fa ^
828bc320 ^
d3a9db3a ^
828bc320 ^


68df24fa ^

828bc320 ^
68df24fa ^
828bc320 ^
d3a9db3a ^
828bc320 ^
d3a9db3a ^
828bc320 ^

68df24fa ^

828bc320 ^
68df24fa ^
828bc320 ^
d3a9db3a ^
828bc320 ^



d3a9db3a ^
828bc320 ^
68df24fa ^

828bc320 ^


68df24fa ^

828bc320 ^

91a5f3e1 ^



d3a9db3a ^
91a5f3e1 ^









d3a9db3a ^
91a5f3e1 ^






828bc320 ^



1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131