diff options
| author | Nathan Jaremko | 2017-07-26 16:47:13 -0400 |
|---|---|---|
| committer | Nathan Jaremko | 2017-07-26 16:47:13 -0400 |
| commit | 4ff4a4e802595f2fac1175c6cb62bb49c6ffda64 (patch) | |
| tree | bd5f826e1f01c99c474c6e48ac667780e5e42f3d /src/structs.rs | |
| parent | cd7b8cb559199c609331b5851076f5a0ed9e1d54 (diff) | |
| download | podcast-4ff4a4e802595f2fac1175c6cb62bb49c6ffda64.tar.bz2 | |
Transfer all work from chromebook
Diffstat (limited to 'src/structs.rs')
| -rw-r--r-- | src/structs.rs | 19 |
1 files changed, 8 insertions, 11 deletions
diff --git a/src/structs.rs b/src/structs.rs index 45191ea..2ea385e 100644 --- a/src/structs.rs +++ b/src/structs.rs @@ -61,14 +61,10 @@ pub struct State { impl State { pub fn new() -> Result<State, String> { - let mut path = get_podcast_dir(); - if let Err(err) = DirBuilder::new().recursive(true).create(&path) { - return Err(format!( - "Couldn't create directory: {}\nReason: {}", - path.to_str().unwrap(), - err - )) + if let Err(err) = create_directories() { + return Err(format!("{}", err)) } + let mut path = get_podcast_dir(); path.push(".subscriptions"); if path.exists() { let mut s = String::new(); @@ -76,7 +72,7 @@ impl State { match serde_json::from_str(&s) { Ok(val) => { let mut state: State = val; - // Check if a day has passed (86400 seconds) + // Check if a day has passed (86400 seconds) if state .last_run_time .signed_duration_since(Utc::now()) @@ -86,8 +82,10 @@ impl State { } state.last_run_time = Utc::now(); Ok(state) - }, - Err(_) => Err(format!("Failed to parse .subscriptions ... I probably changed the schema ... sorry")) + } + Err(_) => Err(format!( + "Failed to parse .subscriptions ... I probably changed the schema ... sorry" + )), } } else { Ok(State { @@ -122,7 +120,6 @@ impl State { pub fn save(&self) -> Result<(), io::Error> { let mut path = get_podcast_dir(); - DirBuilder::new().recursive(true).create(&path).unwrap(); path.push(".subscriptions.tmp"); let serialized = serde_json::to_string(self)?; let mut file = File::create(&path)?; |
