diff options
author | Ben Morrison <ben@gbmor.dev> | 2020-05-28 02:58:57 -0400 |
---|---|---|
committer | Ben Morrison <ben@gbmor.dev> | 2020-05-28 02:58:57 -0400 |
commit | bb327d381e5626d96942a805e6a5f4d4a5a771d5 (patch) | |
tree | c7e86c2a6ea8dc67be2221e8517806f365aac088 /src/main.rs | |
parent | e4af0011c04e2861e4f890bcb7383f9c87e35126 (diff) | |
download | clinte-bb327d381e5626d96942a805e6a5f4d4a5a771d5.tar.gz |
extensive rewrite to use json for storage:
sqlite3 requires the directory where the database resides to be writeable by the user. This presents a problem on multiuser UNIX systems where they may want to limit areas where users have write access. This rewrite totally scraps the sqlite3 database in favor of a pretty simple json file consisting of an array of posts. flock(2) locking is used to synchronize access to the file and make sure two clients aren't trying to write to it at once. The locking is fairly granular right now, but later I may change it to using a single lock for the duration of execution since race conditions are *possible*, if unlikely for the purposes of clinte's intended use.
Diffstat (limited to 'src/main.rs')
-rw-r--r-- | src/main.rs | 14 |
1 files changed, 6 insertions, 8 deletions
diff --git a/src/main.rs b/src/main.rs index f6d136d..6c38431 100644 --- a/src/main.rs +++ b/src/main.rs @@ -21,17 +21,15 @@ fn main() { println!("a community notices system"); println!(); - let db = db::Conn::new(); - if *conf::DEBUG { log::info!("Startup completed in {:?}ms", start.elapsed().as_millis()); } if arg_matches.subcommand_matches("post").is_some() { log::info!("New post..."); - error::helper(posts::create(&db), "Error creating new post"); + error::helper(posts::create(), "Error creating new post"); } else if let Some(updmatch) = arg_matches.subcommand_matches("update") { - let id: u32 = if let Some(val) = updmatch.value_of("id") { + let id: usize = if let Some(val) = updmatch.value_of("id") { error::helper(val.parse(), "Couldn't parse ID") } else { 0 @@ -40,11 +38,11 @@ fn main() { log::info!("Updating post ..."); error::helper( - posts::update_handler(&db, id), + posts::update_handler(id), format!("Error updating post {}", id).as_ref(), ); } else if let Some(delmatch) = arg_matches.subcommand_matches("delete") { - let id: u32 = if let Some(val) = delmatch.value_of("id") { + let id: usize = if let Some(val) = delmatch.value_of("id") { error::helper(val.parse(), "Couldn't parse ID") } else { 0 @@ -53,10 +51,10 @@ fn main() { log::info!("Deleting post"); error::helper( - posts::delete_handler(&db, id), + posts::delete_handler(id), format!("Error deleting post {}", id).as_ref(), ); } - error::helper(posts::display(&db), "Error displaying posts"); + error::helper(posts::display(), "Error displaying posts"); } |