aboutsummaryrefslogtreecommitdiff
path: root/src/tw
diff options
context:
space:
mode:
authoriximeow <me@iximeow.net>2017-11-11 03:25:04 -0800
committeriximeow <me@iximeow.net>2017-11-11 03:25:04 -0800
commit1277e05c931608f7f07a41dff6bae92b8d262299 (patch)
tree342631e076e07a6811854208f01d0bdc56021a50 /src/tw
parentbfc3232b5dae3ac8fa0fba3f50d771d75beda08a (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.rs25
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()) {