nixenv: warn when removing the stats file fails

If the `nix` invocation fails, a stats file won't get created. We log a
warning, but it is generally safe to ignore this failure.
This commit is contained in:
Cole Helbling 2020-04-03 17:25:58 -07:00
parent 0db6f70714
commit 42b4bb2118
No known key found for this signature in database
GPG key ID: B37E0F2371016A4C

View file

@ -72,7 +72,13 @@ impl HydraNixEnv {
let outpath_stats = self.outpath_stats_path(); let outpath_stats = self.outpath_stats_path();
fs::remove_file(&outpath_nix).map_err(|e| Error::RemoveFile(outpath_nix, e))?; fs::remove_file(&outpath_nix).map_err(|e| Error::RemoveFile(outpath_nix, e))?;
fs::remove_file(&outpath_stats).map_err(|e| Error::RemoveFile(outpath_stats, e))?;
// Removing the stats file can fail if `nix` itself errored, for example
// when it fails to evaluate something. In this case, we can ignore (but
// warn about) the error.
if let Err(e) = fs::remove_file(&outpath_stats) {
warn!("Failed to remove file {:?}: {:?}", outpath_stats, e)
}
Ok(()) Ok(())
} }