diff options
author | Andy Wortman <ixineeringeverywhere@gmail.com> | 2017-11-11 03:25:04 -0800 |
---|---|---|
committer | Andy Wortman <ixineeringeverywhere@gmail.com> | 2017-11-11 03:25:04 -0800 |
commit | 44b4d324a0176033107789d1421549b24898ac8a (patch) | |
tree | 342631e076e07a6811854208f01d0bdc56021a50 /src/tw | |
parent | 6ec1028c9c541047f5e9d324bc14d37fccaa36e0 (diff) |
graceful shutdown, fix profile corruption bug
profile corruption was trailing json left by not truncating when profile shrinks in size
Diffstat (limited to 'src/tw')
-rw-r--r-- | src/tw/mod.rs | 25 |
1 files changed, 14 insertions, 11 deletions
diff --git a/src/tw/mod.rs b/src/tw/mod.rs index 767aae9..e2b8b03 100644 --- a/src/tw/mod.rs +++ b/src/tw/mod.rs @@ -23,6 +23,7 @@ pub mod user; use self::user::User; pub enum AppState { + Shutdown, Reconnect, Compose, View @@ -349,18 +350,20 @@ impl TwitterCache { } } pub fn store_cache(&mut self) { - if Path::new(TwitterCache::PROFILE_DIR).is_dir() { - let profile = OpenOptions::new() - .write(true) - .create(true) - .append(false) - .open(TwitterCache::PROFILE_CACHE) - .unwrap(); - serde_json::to_writer(profile, self).unwrap(); - } else { - self.display_info.status("No cache dir exists...".to_owned()); + if self.caching_permitted { + if Path::new(TwitterCache::PROFILE_DIR).is_dir() { + let profile = OpenOptions::new() + .write(true) + .create(true) + .append(false) + .truncate(true) // since this one can become smaller, lop off trailing characters + .open(TwitterCache::PROFILE_CACHE) + .unwrap(); + serde_json::to_writer(profile, self).unwrap(); + } else { + self.display_info.status("No cache dir exists...".to_owned()); + } } - // store cache } fn number_and_insert_tweet(&mut self, mut tw: Tweet) { if !self.tweets.contains_key(&tw.id.to_owned()) { |