@contextlib.contextmanager
def finalize_scripts(config: Config, scripts: Mapping[str, Sequence[PathString]]) -> Iterator[Path]:
- with tempfile.TemporaryDirectory(prefix="mkosi-scripts") as d:
+ with tempfile.TemporaryDirectory(prefix="mkosi-scripts-") as d:
# Make sure than when mkosi-as-caller is used the scripts can still be accessed.
os.chmod(d, 0o755)
@contextlib.contextmanager
def setup_workspace(args: Args, config: Config) -> Iterator[Path]:
with contextlib.ExitStack() as stack:
- workspace = Path(tempfile.mkdtemp(dir=config.workspace_dir_or_default(), prefix="mkosi-workspace"))
+ workspace = Path(tempfile.mkdtemp(dir=config.workspace_dir_or_default(), prefix="mkosi-workspace-"))
# Discard setuid/setgid bits as these are inherited and can leak into the image.
workspace.chmod(stat.S_IMODE(workspace.stat().st_mode) & ~(stat.S_ISGID|stat.S_ISUID))
stack.callback(lambda: rmtree(workspace, sandbox=config.sandbox))
yield
return
- with tempfile.TemporaryDirectory(prefix="mkosi.path") as d:
+ with tempfile.TemporaryDirectory(prefix="mkosi.path-") as d:
for path in config.extra_search_paths:
if not path.is_dir():
@contextlib.contextmanager
def start_swtpm(config: Config) -> Iterator[Path]:
- with tempfile.TemporaryDirectory(prefix="mkosi-swtpm") as state:
+ with tempfile.TemporaryDirectory(prefix="mkosi-swtpm-") as state:
# swtpm_setup is noisy and doesn't have a --quiet option so we pipe it's stdout to /dev/null.
run(
["swtpm_setup", "--tpm-state", state, "--tpm2", "--pcr-banks", "sha256", "--config", "/dev/null"],
# We create the socket ourselves and pass the fd to virtiofsd to avoid race conditions where we start qemu
# before virtiofsd has had the chance to create the socket (or where we try to chown it first).
with (
- tempfile.TemporaryDirectory(prefix="mkosi-virtiofsd") as context,
+ tempfile.TemporaryDirectory(prefix="mkosi-virtiofsd-") as context,
socket.socket(socket.AF_UNIX, socket.SOCK_STREAM) as sock,
):
# Make sure virtiofsd can access the socket in this directory.
run(["chattr", "+C", d], check=False, stderr=subprocess.DEVNULL if not ARG_DEBUG.get() else None)
INVOKING_USER.chown(d)
- with tempfile.NamedTemporaryFile(mode="w", prefix="mkosi-journal-remote-config") as f:
+ with tempfile.NamedTemporaryFile(mode="w", prefix="mkosi-journal-remote-config-") as f:
# Make sure we capture all the logs by bumping the limits. We set MaxFileSize=4G because with the compact mode
# enabled the files cannot grow any larger anyway.
f.write(
@contextlib.contextmanager
def generate_scratch_fs(config: Config) -> Iterator[Path]:
- with tempfile.NamedTemporaryFile(dir="/var/tmp", prefix="mkosi-scratch") as scratch:
+ with tempfile.NamedTemporaryFile(dir="/var/tmp", prefix="mkosi-scratch-") as scratch:
scratch.truncate(1024**4)
fs = config.distribution.filesystem()
extra = config.environment.get(f"SYSTEMD_REPART_MKFS_OPTIONS_{fs.upper()}", "")
def finalize_firmware_variables(config: Config, ovmf: OvmfConfig, stack: contextlib.ExitStack) -> tuple[Path, str]:
- ovmf_vars = stack.enter_context(tempfile.NamedTemporaryFile(prefix="mkosi-ovmf-vars"))
+ ovmf_vars = stack.enter_context(tempfile.NamedTemporaryFile(prefix="mkosi-ovmf-vars-"))
if config.qemu_firmware_variables in (None, Path("custom"), Path("microsoft")):
ovmf_vars_format = ovmf.vars_format
else:
if config.architecture.supports_smbios(firmware):
cmdline += ["-smbios", f"type=11,value=io.systemd.credential.binary:{k}={payload}"]
elif config.architecture.supports_fw_cfg():
- f = stack.enter_context(tempfile.NamedTemporaryFile(prefix="mkosi-fw-cfg", mode="w"))
+ f = stack.enter_context(tempfile.NamedTemporaryFile(prefix="mkosi-fw-cfg-", mode="w"))
f.write(v)
f.flush()
cmdline += ["-fw_cfg", f"name=opt/io.systemd.credentials/{k},file={f.name}"]