Skip to content

Commit a89fe65

Browse files
authored
Merge pull request #944 from cgwalters/lint-usretc
lints: Add check for /usr/etc
2 parents cb99e15 + b53971a commit a89fe65

File tree

1 file changed

+30
-1
lines changed

1 file changed

+30
-1
lines changed

lib/src/lints.rs

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ use fn_error_context::context;
1515
/// if it does not exist error.
1616
#[context("Linting")]
1717
pub(crate) fn lint(root: &Dir) -> Result<()> {
18-
let lints = [check_var_run, check_kernel, check_parse_kargs];
18+
let lints = [check_var_run, check_kernel, check_parse_kargs, check_usretc];
1919
for lint in lints {
2020
lint(&root)?;
2121
}
@@ -32,6 +32,21 @@ fn check_var_run(root: &Dir) -> Result<()> {
3232
Ok(())
3333
}
3434

35+
fn check_usretc(root: &Dir) -> Result<()> {
36+
let etc_exists = root.symlink_metadata_optional("etc")?.is_some();
37+
// For compatibility/conservatism don't bomb out if there's no /etc.
38+
if !etc_exists {
39+
return Ok(());
40+
}
41+
// But having both /etc and /usr/etc is not something we want to support.
42+
if root.symlink_metadata_optional("usr/etc")?.is_some() {
43+
anyhow::bail!(
44+
"Found /usr/etc - this is a bootc implementation detail and not supported to use in containers"
45+
);
46+
}
47+
Ok(())
48+
}
49+
3550
/// Validate that we can parse the /usr/lib/bootc/kargs.d files.
3651
fn check_parse_kargs(root: &Dir) -> Result<()> {
3752
let _args = crate::kargs::get_kargs_in_root(root, ARCH)?;
@@ -88,3 +103,17 @@ fn test_kargs() -> Result<()> {
88103
assert!(check_parse_kargs(root).is_err());
89104
Ok(())
90105
}
106+
107+
#[test]
108+
fn test_usr_etc() -> Result<()> {
109+
let root = &fixture()?;
110+
// This one should pass
111+
check_usretc(root).unwrap();
112+
root.create_dir_all("etc")?;
113+
root.create_dir_all("usr/etc")?;
114+
assert!(check_usretc(root).is_err());
115+
root.remove_dir_all("etc")?;
116+
// Now we should pass again
117+
check_usretc(root).unwrap();
118+
Ok(())
119+
}

0 commit comments

Comments
 (0)