@@ -4,6 +4,7 @@ use anyhow::{Context, Result};
4
4
use cap_std:: fs:: Dir ;
5
5
use cap_std_ext:: { cap_std, dirext:: CapStdExtDirExt } ;
6
6
use fn_error_context:: context;
7
+ use ostree_ext:: container_utils:: is_ostree_booted_in;
7
8
use rustix:: { fd:: AsFd , fs:: StatVfsMountFlags } ;
8
9
9
10
const EDIT_UNIT : & str = "bootc-fstab-edit.service" ;
@@ -14,7 +15,7 @@ pub(crate) const BOOTC_EDITED_STAMP: &str = "Updated by bootc-fstab-edit.service
14
15
#[ context( "bootc generator" ) ]
15
16
pub ( crate ) fn fstab_generator_impl ( root : & Dir , unit_dir : & Dir ) -> Result < bool > {
16
17
// Do nothing if not ostree-booted
17
- if !root . try_exists ( "run/ostree-booted" ) ? {
18
+ if !is_ostree_booted_in ( root ) ? {
18
19
return Ok ( false ) ;
19
20
}
20
21
@@ -105,31 +106,37 @@ fn test_generator_no_fstab() -> Result<()> {
105
106
Ok ( ( ) )
106
107
}
107
108
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
+ }
129
136
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! { "
133
140
#
134
141
# /etc/fstab
135
142
# Created by anaconda on Tue Mar 19 12:24:29 2024
@@ -144,14 +151,15 @@ fn test_generator_fstab_idempotent() -> Result<()> {
144
151
UUID=715be2b7-c458-49f2-acec-b2fdb53d9089 / xfs ro 0 0
145
152
UUID=341c4712-54e8-4839-8020-d94073b1dc8b /boot xfs defaults 0 0
146
153
" } ;
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" ) ?;
149
156
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 ) ;
155
162
156
- Ok ( ( ) )
163
+ Ok ( ( ) )
164
+ }
157
165
}
0 commit comments