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

lints: Add check for /usr/etc #944

Merged
merged 1 commit into from
Dec 9, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 30 additions & 1 deletion lib/src/lints.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use fn_error_context::context;
/// if it does not exist error.
#[context("Linting")]
pub(crate) fn lint(root: &Dir) -> Result<()> {
let lints = [check_var_run, check_kernel, check_parse_kargs];
let lints = [check_var_run, check_kernel, check_parse_kargs, check_usretc];
for lint in lints {
lint(&root)?;
}
Expand All @@ -32,6 +32,21 @@ fn check_var_run(root: &Dir) -> Result<()> {
Ok(())
}

fn check_usretc(root: &Dir) -> Result<()> {
let etc_exists = root.symlink_metadata_optional("etc")?.is_some();
// For compatibility/conservatism don't bomb out if there's no /etc.
if !etc_exists {
return Ok(());
}
// But having both /etc and /usr/etc is not something we want to support.
if root.symlink_metadata_optional("usr/etc")?.is_some() {
anyhow::bail!(
"Found /usr/etc - this is a bootc implementation detail and not supported to use in containers"
);
}
Ok(())
}

/// Validate that we can parse the /usr/lib/bootc/kargs.d files.
fn check_parse_kargs(root: &Dir) -> Result<()> {
let _args = crate::kargs::get_kargs_in_root(root, ARCH)?;
Expand Down Expand Up @@ -88,3 +103,17 @@ fn test_kargs() -> Result<()> {
assert!(check_parse_kargs(root).is_err());
Ok(())
}

#[test]
fn test_usr_etc() -> Result<()> {
let root = &fixture()?;
// This one should pass
check_usretc(root).unwrap();
root.create_dir_all("etc")?;
root.create_dir_all("usr/etc")?;
assert!(check_usretc(root).is_err());
root.remove_dir_all("etc")?;
// Now we should pass again
check_usretc(root).unwrap();
Ok(())
}
Loading