Skip to content

Commit

Permalink
Sync written files (#1447)
Browse files Browse the repository at this point in the history
Dropping a file will ignore errors in synchronizing in-memory
(meta)data to disk. Calling `sync_all` gives instead a result on
which to panic.
  • Loading branch information
fpoli authored Aug 22, 2023
1 parent 46c5f56 commit a0681ee
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 2 deletions.
1 change: 1 addition & 0 deletions jni-gen/systest/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ fn main() {
let fname = deps_dir.path().join("asm.jar");
let mut dest = File::create(fname.clone()).unwrap();
copy(&mut response.into_reader(), &mut dest).unwrap();
dest.sync_all().unwrap();
fname.to_str().unwrap().to_string()
}
};
Expand Down
2 changes: 2 additions & 0 deletions prusti-launch/src/bin/prusti-rustc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ fn process(mut args: Vec<String>) -> Result<(), i32> {
for arg in cmd.get_args() {
writeln!(file, "{}", arg.to_str().unwrap()).unwrap();
}
file.sync_all().unwrap();
}
if let Ok(path) = env::var("PRUSTI_RUSTC_LOG_ENV") {
let mut file = std::fs::File::create(path).unwrap();
Expand All @@ -125,6 +126,7 @@ fn process(mut args: Vec<String>) -> Result<(), i32> {
)
.unwrap();
}
file.sync_all().unwrap();
}

let exit_status = cmd.status().unwrap_or_else(|e| {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ pub fn backtranslate(
let label_markers = translator.get_label_markers(true);
let mut file = std::fs::File::create(path).unwrap();
serde_json::to_writer_pretty(&mut file, &label_markers).unwrap();
file.sync_all().unwrap();
}

let counterexample_entry_vec = translator.process_entries(position_manager, &label_markers);
Expand Down
1 change: 1 addition & 0 deletions smt-log-analyzer/src/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -667,6 +667,7 @@ impl State {
self.traced_quantifier_triggers.as_ref().unwrap().as_bytes(),
)
.unwrap();
file.sync_all().unwrap();
}
}

Expand Down
1 change: 1 addition & 0 deletions viper-sys/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ fn main() {
let fname = deps_dir.path().join("asm.jar");
let mut dest = File::create(fname.clone()).unwrap();
copy(&mut response.into_reader(), &mut dest).unwrap();
dest.sync_all().unwrap();
fname.to_str().unwrap().to_string()
}
};
Expand Down
11 changes: 9 additions & 2 deletions viper/src/cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,15 @@ impl PersistentCache {
match fs::File::create(cache_loc) {
Ok(f) => {
info!("Saving cache to \"{}\"", cache_loc.display());
bincode::serialize_into(&mut io::BufWriter::new(f), &ResultCache::from(self))
.unwrap_or_else(|e| error!("Failed to write cache: {e}"));
let mut cache_buffer = io::BufWriter::new(f);
bincode::serialize_into(&mut cache_buffer, &ResultCache::from(self))
.unwrap_or_else(|e| error!("Failed to serialize the cache: {e}"));
match cache_buffer.into_inner() {
Err(e) => error!("Failed to flush the cache file: {e}"),
Ok(f) => f
.sync_all()
.unwrap_or_else(|e| error!("Failed to sync the cache file to disk: {e}")),
}
}
Err(e) => error!("Failed to create cache file: {e}"),
}
Expand Down

0 comments on commit a0681ee

Please sign in to comment.