@@ -4,6 +4,7 @@ use anyhow::{Context, Result};
44use cap_std:: fs:: Dir ;
55use cap_std_ext:: { cap_std, dirext:: CapStdExtDirExt } ;
66use fn_error_context:: context;
7+ use ostree_ext:: container_utils:: is_ostree_booted_in;
78use rustix:: { fd:: AsFd , fs:: StatVfsMountFlags } ;
89
910const EDIT_UNIT : & str = "bootc-fstab-edit.service" ;
@@ -14,7 +15,7 @@ pub(crate) const BOOTC_EDITED_STAMP: &str = "Updated by bootc-fstab-edit.service
1415#[ context( "bootc generator" ) ]
1516pub ( crate ) fn fstab_generator_impl ( root : & Dir , unit_dir : & Dir ) -> Result < bool > {
1617 // Do nothing if not ostree-booted
17- if !root . try_exists ( "run/ostree-booted" ) ? {
18+ if !is_ostree_booted_in ( root ) ? {
1819 return Ok ( false ) ;
1920 }
2021
@@ -105,31 +106,37 @@ fn test_generator_no_fstab() -> Result<()> {
105106 Ok ( ( ) )
106107}
107108
108- #[ test]
109- fn test_generator_fstab ( ) -> Result < ( ) > {
110- let tempdir = fixture ( ) ?;
111- let unit_dir = & tempdir. open_dir ( "run/systemd/system" ) ?;
112- // Should still be a no-op
113- tempdir. atomic_write ( "etc/fstab" , "# Some dummy fstab" ) ?;
114- fstab_generator_impl ( & tempdir, & unit_dir) . unwrap ( ) ;
115- assert_eq ! ( unit_dir. entries( ) ?. count( ) , 0 ) ;
116-
117- // Also a no-op, not booted via ostree
118- tempdir. atomic_write ( "etc/fstab" , & format ! ( "# {FSTAB_ANACONDA_STAMP}" ) ) ?;
119- fstab_generator_impl ( & tempdir, & unit_dir) . unwrap ( ) ;
120- assert_eq ! ( unit_dir. entries( ) ?. count( ) , 0 ) ;
121-
122- // Now it should generate
123- tempdir. atomic_write ( "run/ostree-booted" , "ostree booted" ) ?;
124- fstab_generator_impl ( & tempdir, & unit_dir) . unwrap ( ) ;
125- assert_eq ! ( unit_dir. entries( ) ?. count( ) , 2 ) ;
126-
127- Ok ( ( ) )
128- }
109+ #[ cfg( test) ]
110+ mod test {
111+ use super :: * ;
112+
113+ use ostree_ext:: container_utils:: OSTREE_BOOTED ;
114+
115+ #[ test]
116+ fn test_generator_fstab ( ) -> Result < ( ) > {
117+ let tempdir = fixture ( ) ?;
118+ let unit_dir = & tempdir. open_dir ( "run/systemd/system" ) ?;
119+ // Should still be a no-op
120+ tempdir. atomic_write ( "etc/fstab" , "# Some dummy fstab" ) ?;
121+ fstab_generator_impl ( & tempdir, & unit_dir) . unwrap ( ) ;
122+ assert_eq ! ( unit_dir. entries( ) ?. count( ) , 0 ) ;
123+
124+ // Also a no-op, not booted via ostree
125+ tempdir. atomic_write ( "etc/fstab" , & format ! ( "# {FSTAB_ANACONDA_STAMP}" ) ) ?;
126+ fstab_generator_impl ( & tempdir, & unit_dir) . unwrap ( ) ;
127+ assert_eq ! ( unit_dir. entries( ) ?. count( ) , 0 ) ;
128+
129+ // Now it should generate
130+ tempdir. atomic_write ( OSTREE_BOOTED , "ostree booted" ) ?;
131+ fstab_generator_impl ( & tempdir, & unit_dir) . unwrap ( ) ;
132+ assert_eq ! ( unit_dir. entries( ) ?. count( ) , 2 ) ;
133+
134+ Ok ( ( ) )
135+ }
129136
130- #[ test]
131- fn test_generator_fstab_idempotent ( ) -> Result < ( ) > {
132- let anaconda_fstab = indoc:: indoc! { "
137+ #[ test]
138+ fn test_generator_fstab_idempotent ( ) -> Result < ( ) > {
139+ let anaconda_fstab = indoc:: indoc! { "
133140#
134141# /etc/fstab
135142# Created by anaconda on Tue Mar 19 12:24:29 2024
@@ -144,14 +151,15 @@ fn test_generator_fstab_idempotent() -> Result<()> {
144151UUID=715be2b7-c458-49f2-acec-b2fdb53d9089 / xfs ro 0 0
145152UUID=341c4712-54e8-4839-8020-d94073b1dc8b /boot xfs defaults 0 0
146153" } ;
147- let tempdir = fixture ( ) ?;
148- let unit_dir = & tempdir. open_dir ( "run/systemd/system" ) ?;
154+ let tempdir = fixture ( ) ?;
155+ let unit_dir = & tempdir. open_dir ( "run/systemd/system" ) ?;
149156
150- tempdir. atomic_write ( "etc/fstab" , anaconda_fstab) ?;
151- tempdir. atomic_write ( "run/ostree-booted" , "ostree booted" ) ?;
152- let updated = fstab_generator_impl ( & tempdir, & unit_dir) . unwrap ( ) ;
153- assert ! ( !updated) ;
154- assert_eq ! ( unit_dir. entries( ) ?. count( ) , 0 ) ;
157+ tempdir. atomic_write ( "etc/fstab" , anaconda_fstab) ?;
158+ tempdir. atomic_write ( OSTREE_BOOTED , "ostree booted" ) ?;
159+ let updated = fstab_generator_impl ( & tempdir, & unit_dir) . unwrap ( ) ;
160+ assert ! ( !updated) ;
161+ assert_eq ! ( unit_dir. entries( ) ?. count( ) , 0 ) ;
155162
156- Ok ( ( ) )
163+ Ok ( ( ) )
164+ }
157165}
0 commit comments