SourceFileTransfer,
die,
install_grub,
- mkdir_last,
nspawn_params_for_blockdev_access,
partition,
patch_file,
def copy_path(oldpath: PathString, newpath: Path) -> None:
try:
- mkdir_last(newpath)
+ newpath.mkdir(exist_ok=True)
except FileExistsError:
# something that is not a directory already exists
newpath.unlink()
- mkdir_last(newpath)
+ newpath.mkdir()
for entry in os.scandir(oldpath):
newentry = newpath / entry.name
btrfs_subvol_create(root / "var/lib/machines", 0o700)
# We need an initialized machine ID for the build & boot logic to work
- mkdir_last(root / "etc", 0o755)
+ root.joinpath("etc").mkdir(mode=0o755, exist_ok=True)
root.joinpath("etc/machine-id").write_text(f"{args.machine_id}\n")
if not do_run_build_script and args.bootable:
if not args.bootable or args.bios_partno is not None or not args.with_unified_kernel_images:
return
- for d in ("etc", "etc/kernel", "etc/kernel/install.d"):
- mkdir_last(root / d, 0o755)
+ for subdir in ("etc", "etc/kernel", "etc/kernel/install.d"):
+ root.joinpath(subdir).mkdir(mode=0o755, exist_ok=True)
for f in ("50-dracut.install", "51-dracut-rescue.install", "90-loaderentry.install"):
root.joinpath("etc/kernel/install.d", f).symlink_to("/dev/null")
if args.output_dir is None:
return
- mkdir_last(args.output_dir, 0o755)
+ args.output_dir.mkdir(mode=0o755, exist_ok=True)
def make_build_dir(args: CommandLineArguments) -> None:
if args.build_dir is None:
return
- mkdir_last(args.build_dir, 0o755)
+ args.build_dir.mkdir(mode=0o755, exist_ok=True)
def setup_ssh(
def var_tmp(root: Path) -> Path:
- return mkdir_last(workspace(root) / "var-tmp")
-
-
-def mkdir_last(path: Path, mode: int = 0o777) -> Path:
- """Create directory path
-
- Only the final component will be created, so this is different than os.makedirs().
- """
- try:
- os.mkdir(path, mode)
- except FileExistsError:
- if not os.path.isdir(path):
- raise
- return path
+ p = workspace(root) / "var-tmp"
+ p.mkdir(exist_ok=True)
+ return p
def partition(loopdev: Path, partno: int) -> Path: