diff options
| author | Nathan Jaremko | 2017-07-25 00:35:02 -0400 |
|---|---|---|
| committer | Nathan Jaremko | 2017-07-25 00:35:02 -0400 |
| commit | 7c40d1d07eb32e7e7fe923241b38ed7057338dc1 (patch) | |
| tree | 68ef9fc79a6f37f265195f1865eaf8299f6d15d8 /src | |
| parent | 404c468a4c51b07c27e92ccd952f647db11a6369 (diff) | |
| download | podcast-7c40d1d07eb32e7e7fe923241b38ed7057338dc1.tar.bz2 | |
Cleanup
Diffstat (limited to 'src')
| -rw-r--r-- | src/main.rs | 4 | ||||
| -rw-r--r-- | src/structs.rs | 14 |
2 files changed, 12 insertions, 6 deletions
diff --git a/src/main.rs b/src/main.rs index 800c867..338c7b2 100644 --- a/src/main.rs +++ b/src/main.rs @@ -19,7 +19,9 @@ use clap::{Arg, App, SubCommand}; use structs::*; fn main() { - let mut state = State::new(); + let mut state = State::new().expect( + ".subscription file couldn't be parsed...I probably changed the format...sorry", + ); let config = Config::new(); let matches = App::new("podcast") .version("1.0") diff --git a/src/structs.rs b/src/structs.rs index bb42cdb..d620c43 100644 --- a/src/structs.rs +++ b/src/structs.rs @@ -34,6 +34,9 @@ impl Config { delete_limit = val; } } + } else { + let mut file = File::create(&path).unwrap(); + file.write_all(b"auto_download_limit: 1").unwrap(); } Config { auto_download_limit: download_limit, @@ -67,13 +70,14 @@ pub struct State { } impl State { - pub fn new() -> State { + pub fn new() -> Result<State, serde_json::Error> { let mut path = get_podcast_dir(); + DirBuilder::new().recursive(true).create(&path).unwrap(); path.push(".subscriptions"); if path.exists() { let mut s = String::new(); File::open(&path).unwrap().read_to_string(&mut s).unwrap(); - let mut state: State = serde_json::from_str(&s).unwrap(); + let mut state: State = serde_json::from_str(&s)?; // Check if a day has passed (86400 seconds) if state .last_run_time @@ -83,12 +87,12 @@ impl State { update_rss(&mut state); } state.last_run_time = Utc::now(); - state + Ok(state) } else { - State { + Ok(State { last_run_time: Utc::now(), subs: Vec::new(), - } + }) } } |
