run(cmdline)
-def acl_toggle_remove(root: Path, uid: int, *, allow: bool) -> None:
+def acl_toggle_remove(config: MkosiConfig, root: Path, uid: int, *, allow: bool) -> None:
+ if not config.acl:
+ return
+
ret = run(
[
"setfacl",
with complete_step("Installing cache copies"):
unlink_try_hard(final)
shutil.move(state.root, final)
- acl_toggle_remove(final, state.uid, allow=True)
+ acl_toggle_remove(state.config, final, state.uid, allow=True)
if state.config.build_script:
unlink_try_hard(build)
shutil.move(state.build_overlay, build)
- acl_toggle_remove(build, state.uid, allow=True)
+ acl_toggle_remove(state.config, build, state.uid, allow=True)
def dir_size(path: PathString) -> int:
default=[],
help="Append extra entries to the kernel command line when booting the image",
)
+ group.add_argument(
+ "--acl",
+ metavar="BOOL",
+ action=BooleanAction,
+ help="Set ACLs on generated directories to permit the user running mkosi to remove them",
+ )
group = parser.add_argument_group("Additional configuration options")
group.add_argument(
with complete_step("Copying cached trees"):
copy_path(final, state.root)
- acl_toggle_remove(state.root, state.uid, allow=False)
+ acl_toggle_remove(state.config, state.root, state.uid, allow=False)
if state.config.build_script:
copy_path(build, state.build_overlay)
- acl_toggle_remove(state.build_overlay, state.uid, allow=False)
+ acl_toggle_remove(state.config, state.build_overlay, state.uid, allow=False)
return True
save_manifest(state, manifest)
if state.config.cache_path:
- acl_toggle_remove(state.config.cache_path, state.uid, allow=True)
+ acl_toggle_remove(state.config, state.config.cache_path, state.uid, allow=True)
for p in state.config.output_paths():
if state.staging.joinpath(p.name).exists():
if p != state.config.output or state.config.output_format != OutputFormat.directory:
os.chown(p, state.uid, state.gid)
else:
- acl_toggle_remove(p, uid, allow=True)
+ acl_toggle_remove(state.config, p, uid, allow=True)
if p in (state.config.output, state.config.output_split_kernel):
compress_output(state.config, p, uid=state.uid, gid=state.gid)
if p.name.startswith(state.config.output.name):
compress_output(state.config, p, uid=state.uid, gid=state.gid)
+ print_output_size(config)
+
def check_root() -> None:
if os.getuid() != 0:
uid, _ = current_user_uid_gid()
if config.output_format == OutputFormat.directory:
- acl_toggle_remove(config.output, uid, allow=False)
+ acl_toggle_remove(config, config.output, uid, allow=False)
try:
run(cmdline, stdout=sys.stdout)
finally:
if config.output_format == OutputFormat.directory:
- acl_toggle_remove(config.output, uid, allow=True)
+ acl_toggle_remove(config, config.output, uid, allow=True)
def find_qemu_binary(config: MkosiConfig) -> str:
check_outputs(config)
if needs_build(config) or config.verb == Verb.clean:
- unlink_output(config)
+ def target() -> None:
+ if os.getuid() != 0:
+ become_root()
+ unlink_output(config)
+
+ fork_and_wait(target)
if needs_build(config):
def target() -> None:
if config.auto_bump:
bump_image_version(config)
- print_output_size(config)
-
with suppress_stacktrace():
if config.verb in (Verb.shell, Verb.boot):
run_shell(config)