Skip to content

Commit

Permalink
add dashes to temporary directories for readability
Browse files Browse the repository at this point in the history
  • Loading branch information
behrmann committed May 22, 2024
1 parent 472c2b8 commit a300d52
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 10 deletions.
6 changes: 3 additions & 3 deletions mkosi/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -369,7 +369,7 @@ def mount_build_overlay(context: Context, volatile: bool = False) -> Iterator[Pa

@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)

Expand Down Expand Up @@ -3579,7 +3579,7 @@ def normalize_mtime(root: Path, mtime: Optional[int], directory: Path = Path("")
@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))
Expand Down Expand Up @@ -4180,7 +4180,7 @@ def prepend_to_environ_path(config: Config) -> Iterator[None]:
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():
Expand Down
12 changes: 6 additions & 6 deletions mkosi/qemu.py
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ def find_ovmf_firmware(config: Config, firmware: QemuFirmware) -> Optional[OvmfC

@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"],
Expand Down Expand Up @@ -329,7 +329,7 @@ def start_virtiofsd(config: Config, directory: PathString, *, name: str, selinux
# 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.
Expand Down Expand Up @@ -449,7 +449,7 @@ def start_journal_remote(config: Config, sockfd: int) -> Iterator[None]:
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(
Expand Down Expand Up @@ -563,7 +563,7 @@ def want_scratch(config: Config) -> bool:

@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()}", "")
Expand Down Expand Up @@ -595,7 +595,7 @@ def finalize_qemu_firmware(config: Config, kernel: Optional[Path]) -> QemuFirmwa


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:
Expand Down Expand Up @@ -1100,7 +1100,7 @@ def add_virtiofs_mount(
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}"]
Expand Down
2 changes: 1 addition & 1 deletion mkosi/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ def become_root() -> None:

pid = os.getpid()

with tempfile.NamedTemporaryFile(prefix="mkosi-uidmap-lock") as lockfile:
with tempfile.NamedTemporaryFile(prefix="mkosi-uidmap-lock-") as lockfile:
lock = Path(lockfile.name)

# We map the private UID range configured in /etc/subuid and /etc/subgid into the container using
Expand Down

0 comments on commit a300d52

Please sign in to comment.