@@ -139,6 +139,16 @@ const LINTS: &[Lint] = &[
139
139
sensitive build system information.
140
140
"# } ,
141
141
} ,
142
+ Lint {
143
+ name : "nonempty-boot" ,
144
+ ty : LintType :: Warning ,
145
+ f : check_boot,
146
+ description : indoc ! { r#"
147
+ The `/boot` directory should be present, but empty. The kernel
148
+ content should be in /usr/lib/modules instead in the container image.
149
+ Any content here in the container image will be masked at runtime.
150
+ "# } ,
151
+ } ,
142
152
] ;
143
153
144
154
pub ( crate ) fn lint_list ( output : impl std:: io:: Write ) -> Result < ( ) > {
@@ -351,6 +361,25 @@ fn check_varlog(root: &Dir) -> LintResult {
351
361
lint_err ( format ! ( "Found non-empty logfile: {first}{others}" ) )
352
362
}
353
363
364
+ fn check_boot ( root : & Dir ) -> LintResult {
365
+ let Some ( d) = root. open_dir_optional ( "boot" ) ? else {
366
+ return lint_err ( format ! ( "Missing /boot directory" ) ) ;
367
+ } ;
368
+ let mut entries = d. entries ( ) ?;
369
+ let Some ( ent) = entries. next ( ) else {
370
+ return lint_ok ( ) ;
371
+ } ;
372
+ let ent = ent?;
373
+ let first = ent. file_name ( ) ;
374
+ let others = entries. count ( ) ;
375
+ let others = if others > 0 {
376
+ format ! ( " (and {others} more)" )
377
+ } else {
378
+ "" . into ( )
379
+ } ;
380
+ lint_err ( format ! ( "Found non-empty /boot: {first:?}{others}" ) )
381
+ }
382
+
354
383
#[ cfg( test) ]
355
384
mod tests {
356
385
use super :: * ;
@@ -365,6 +394,7 @@ mod tests {
365
394
root. create_dir_all ( "usr/lib/modules/5.7.2" ) ?;
366
395
root. write ( "usr/lib/modules/5.7.2/vmlinuz" , "vmlinuz" ) ?;
367
396
397
+ root. create_dir ( "boot" ) ?;
368
398
root. create_dir ( "sysroot" ) ?;
369
399
root. symlink_contents ( "sysroot/ostree" , "ostree" ) ?;
370
400
@@ -473,6 +503,19 @@ mod tests {
473
503
Ok ( ( ) )
474
504
}
475
505
506
+ #[ test]
507
+ fn test_boot ( ) -> Result < ( ) > {
508
+ let root = & passing_fixture ( ) ?;
509
+ check_boot ( & root) . unwrap ( ) . unwrap ( ) ;
510
+ root. create_dir ( "boot/somesubdir" ) ?;
511
+ let Err ( e) = check_boot ( & root) . unwrap ( ) else {
512
+ unreachable ! ( )
513
+ } ;
514
+ assert ! ( e. to_string( ) . contains( "somesubdir" ) ) ;
515
+
516
+ Ok ( ( ) )
517
+ }
518
+
476
519
#[ test]
477
520
fn test_non_utf8 ( ) {
478
521
use std:: { ffi:: OsStr , os:: unix:: ffi:: OsStrExt } ;
0 commit comments