format_rlimit,
make_executable,
one_zero,
+ parents_below,
read_env_file,
read_os_release,
round_up,
if not p or p.exists():
continue
- p.mkdir()
+ p.mkdir(parents=True, exist_ok=True)
- # If we created the directory in a parent directory owned by the invoking user, make sure the directory itself
- # is owned by the invoking user as well.
- if INVOKING_USER.is_regular_user() and p.parent.stat().st_uid == INVOKING_USER.uid:
- os.chown(p, INVOKING_USER.uid, INVOKING_USER.gid)
+ # If we created the directory in a parent directory owned by the invoking user, make sure the directories we
+ # just created are owned by the invoking user as well.
+ if (
+ INVOKING_USER.is_regular_user() and
+ (q := next((parent for parent in p.parents if parent.stat().st_uid == INVOKING_USER.uid), None))
+ ):
+ for parent in parents_below(p, q):
+ os.chown(parent, INVOKING_USER.uid, INVOKING_USER.gid)
# Discard setuid/setgid bits as these are inherited and can leak into the image.
if config.build_dir:
from mkosi.log import complete_step, log_step
from mkosi.run import run
from mkosi.sandbox import Mount, SandboxProtocol, nosandbox
+from mkosi.util import parents_below
def loaded_modules() -> list[str]:
return set(nametofile[m] for m in mods if m in nametofile), set(firmware)
-def parents_below(path: Path, below: Path) -> list[Path]:
- parents = list(path.parents)
- return parents[:parents.index(below)]
-
-
def gen_required_kernel_modules(
root: Path,
kver: str,
os.umask(old)
+def parents_below(path: Path, below: Path) -> list[Path]:
+ parents = list(path.parents)
+ return parents[:parents.index(below)]
+
+
@contextlib.contextmanager
def resource_path(mod: ModuleType) -> Iterator[Path]: