@@ -144,7 +144,7 @@ def create_parser() -> argparse.ArgumentParser:
144
144
return parser
145
145
146
146
147
- def process_crypttab (staging_dir : str ) -> list [str ]:
147
+ def process_crypttab (staging_dir : Path ) -> list [str ]:
148
148
cmdline = []
149
149
150
150
# Generate crypttab with all the x-initrd.attach entries
@@ -160,10 +160,10 @@ def process_crypttab(staging_dir: str) -> list[str]:
160
160
)
161
161
]
162
162
if crypttab :
163
- with (Path ( staging_dir ) / "crypttab" ).open ("w" ) as f :
163
+ with (staging_dir / "crypttab" ).open ("w" ) as f :
164
164
f .write ("# Automatically generated by mkosi-initrd\n " )
165
165
f .write ("\n " .join (crypttab ))
166
- cmdline += ["--extra-tree" , f"{ staging_dir } / crypttab:/etc/crypttab" ]
166
+ cmdline += ["--extra-tree" , f"{ staging_dir / ' crypttab' } :/etc/crypttab" ]
167
167
except PermissionError :
168
168
logging .warning ("Permission denied to access /etc/crypttab, the initrd may be unbootable" )
169
169
@@ -180,18 +180,18 @@ def add_raid_config() -> list[str]:
180
180
return cmdline
181
181
182
182
183
- def initrd_finalize (staging_dir : str , output : str , output_dir : str ) -> None :
183
+ def initrd_finalize (staging_dir : Path , output : str , output_dir : Optional [ Path ] ) -> None :
184
184
if output_dir :
185
185
with umask (~ 0o700 ) if os .getuid () == 0 else cast (umask , contextlib .nullcontext ()):
186
186
Path (output_dir ).mkdir (parents = True , exist_ok = True )
187
187
else :
188
- output_dir = os . fspath ( Path .cwd () )
188
+ output_dir = Path .cwd ()
189
189
190
- log_notice (f"Copying { staging_dir } / { output } to { output_dir } / { output } " )
190
+ log_notice (f"Copying { staging_dir / output } to { output_dir / output } " )
191
191
# mkosi symlinks the expected output image, so dereference it
192
192
copy_tree (
193
- Path ( f" { staging_dir } / { output } " ).resolve (),
194
- Path ( f" { output_dir } / { output } " ) ,
193
+ ( staging_dir / output ).resolve (),
194
+ output_dir / output ,
195
195
)
196
196
197
197
@@ -208,7 +208,8 @@ def initrd_common_args(parser: argparse.ArgumentParser) -> None:
208
208
"--output-dir" ,
209
209
metavar = "DIR" ,
210
210
help = "Output directory" ,
211
- default = "" ,
211
+ default = None ,
212
+ type = Path ,
212
213
)
213
214
parser .add_argument (
214
215
"--debug" ,
@@ -349,7 +350,7 @@ def main() -> None:
349
350
350
351
cmdline += [f"--sandbox-tree={ sandbox_tree } " ]
351
352
352
- cmdline += process_crypttab (staging_dir )
353
+ cmdline += process_crypttab (Path ( staging_dir ) )
353
354
354
355
if Path ("/etc/kernel/cmdline" ).exists ():
355
356
cmdline += ["--kernel-command-line" , Path ("/etc/kernel/cmdline" ).read_text ()]
@@ -364,7 +365,7 @@ def main() -> None:
364
365
env = os .environ | ({"MKOSI_DNF" : dnf .resolve ().name } if (dnf := find_binary ("dnf" )) else {}),
365
366
)
366
367
367
- initrd_finalize (staging_dir , args .output , args .output_dir )
368
+ initrd_finalize (Path ( staging_dir ) , args .output , args .output_dir )
368
369
369
370
370
371
if __name__ == "__main__" :
0 commit comments