From 42b4bb2118c10cc4e6aa277a6d5966790905d5c5 Mon Sep 17 00:00:00 2001 From: Cole Helbling Date: Fri, 3 Apr 2020 17:25:58 -0700 Subject: [PATCH 1/2] 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. --- ofborg/src/nixenv.rs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/ofborg/src/nixenv.rs b/ofborg/src/nixenv.rs index 756489c..6a9c197 100644 --- a/ofborg/src/nixenv.rs +++ b/ofborg/src/nixenv.rs @@ -72,7 +72,13 @@ impl HydraNixEnv { let outpath_stats = self.outpath_stats_path(); 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(()) } From 9736cf08fe3e347f4fdc5194440e410fcc506e9b Mon Sep 17 00:00:00 2001 From: Cole Helbling Date: Fri, 3 Apr 2020 17:37:21 -0700 Subject: [PATCH 2/2] nixenv: remove unnecessary single quotes The debug representation of a `PathBuf` provides double quotes already. --- ofborg/src/nixenv.rs | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/ofborg/src/nixenv.rs b/ofborg/src/nixenv.rs index 6a9c197..f499b37 100644 --- a/ofborg/src/nixenv.rs +++ b/ofborg/src/nixenv.rs @@ -136,12 +136,8 @@ impl Error { pub fn display(self) -> String { match self { Error::Io(e) => format!("Failed during the setup of executing nix-env: {:?}", e), - Error::CreateFile(path, err) => { - format!("Failed to create file '{:?}': {:?}", path, err) - } - Error::RemoveFile(path, err) => { - format!("Failed to remove file '{:?}': {:?}", path, err) - } + Error::CreateFile(path, err) => format!("Failed to create file {:?}: {:?}", path, err), + Error::RemoveFile(path, err) => format!("Failed to remove file {:?}: {:?}", path, err), Error::WriteFile(file, err) => { format!("Failed to write to file '{:?}': {:?}", file, err) }