Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

container/commit: Actually return an error code #364

Merged
merged 1 commit into from
Sep 10, 2022

Conversation

cgwalters
Copy link
Member

I ended up rewriting a lot of this so we could more properly unit test it. But the problem here boils down to move || having moved the error counter into the closure, but since it's copy it made a new copy.

I ended up rewriting a lot of this so we could more properly
unit test it.  But the problem here boils down to `move ||` having
*moved* the error counter into the closure, but since it's copy
it made a new copy.
@cgwalters
Copy link
Member Author

I actually did this minimal fix first:

diff --git a/lib/src/commit.rs b/lib/src/commit.rs
index 3f30842..51cd977 100644
--- a/lib/src/commit.rs
+++ b/lib/src/commit.rs
@@ -39,15 +39,15 @@ pub(crate) async fn container_commit() -> Result<()> {
     println!("Checking /var for files");
     let var_path = Path::new("/var");
 
-    let mut error_count = 0;
-
     task::spawn_blocking(move || -> Result<()> {
-        validate_directories_only(var_path, &mut error_count)
+        let mut error_count = 0;
+        validate_directories_only(var_path, &mut error_count)?;
+        if error_count != 0 {
+            anyhow::bail!("Found content in /var");
+        }
+        Ok(())
     })
     .await??;
 
-    if error_count != 0 {
-        anyhow::bail!("Found content in /var");
-    }
     Ok(())
 }

but the desire to unit test this drove a larger rework.

Copy link
Member

@jmarrero jmarrero left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@jmarrero jmarrero merged commit 965f994 into ostreedev:main Sep 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants