diff options
| author | Nathan Jaremko | 2018-05-16 22:36:50 -0400 |
|---|---|---|
| committer | Nathan Jaremko | 2018-05-16 22:36:50 -0400 |
| commit | e394ea52b04a99ba55719a7a9764bca3ebb591d2 (patch) | |
| tree | c35a6d094d89eeec8adeb4e352d8d1c9cb010f7a /src/structs.rs | |
| parent | 0b9e9f9092b72b24ce1ec1fc058107f296c64838 (diff) | |
| download | podcast-e394ea52b04a99ba55719a7a9764bca3ebb591d2.tar.bz2 | |
Attempt to fix windows rename bug
Diffstat (limited to 'src/structs.rs')
| -rw-r--r-- | src/structs.rs | 16 |
1 files changed, 10 insertions, 6 deletions
diff --git a/src/structs.rs b/src/structs.rs index 03a9932..0caed73 100644 --- a/src/structs.rs +++ b/src/structs.rs @@ -67,9 +67,11 @@ impl State { path.push(".subscriptions"); if path.exists() { let mut s = String::new(); - let mut file = File::open(&path).chain_err(|| UNABLE_TO_OPEN_FILE)?; - file.read_to_string(&mut s) - .chain_err(|| UNABLE_TO_READ_FILE_TO_STRING)?; + { + let mut file = File::open(&path).chain_err(|| UNABLE_TO_OPEN_FILE)?; + file.read_to_string(&mut s) + .chain_err(|| UNABLE_TO_READ_FILE_TO_STRING)?; + } let mut state: State = match serde_json::from_str(&s) { Ok(val) => val, // This will happen if the struct has changed between versions @@ -132,9 +134,11 @@ impl State { let mut path = get_podcast_dir()?; path.push(".subscriptions.tmp"); let serialized = serde_json::to_string(self).chain_err(|| "unable to serialize state")?; - let mut file = File::create(&path).chain_err(|| UNABLE_TO_CREATE_FILE)?; - file.write_all(serialized.as_bytes()) - .chain_err(|| UNABLE_TO_WRITE_FILE)?; + { + let mut file = File::create(&path).chain_err(|| UNABLE_TO_CREATE_FILE)?; + file.write_all(serialized.as_bytes()) + .chain_err(|| UNABLE_TO_WRITE_FILE)?; + } fs::rename(&path, get_sub_file()?).chain_err(|| "unable to rename file")?; Ok(()) } |
