From b0fe985cd625bc7828a16dda0c8664b31e5f9841 Mon Sep 17 00:00:00 2001 From: Daan De Meyer Date: Tue, 1 Aug 2023 22:30:05 +0200 Subject: [PATCH] More comprehensive tmpfile fix --- mkosi/__init__.py | 4 ---- mkosi/util.py | 6 ++++++ 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/mkosi/__init__.py b/mkosi/__init__.py index d2ca7c625..1583054c1 100644 --- a/mkosi/__init__.py +++ b/mkosi/__init__.py @@ -1628,10 +1628,6 @@ def build_image(args: MkosiArgs, config: MkosiConfig) -> None: # Make sure tmpfiles' aging doesn't interfere with our workspace # while we are working on it. with MkosiState(args, config) as state, scopedenv({"TMPDIR" : str(state.workspace)}): - # python caches the default temporary directory so when we modify TMPDIR we have to make sure it gets - # recalculated (see https://docs.python.org/3/library/tempfile.html#tempfile.tempdir). - tempfile.tempdir = None - install_package_manager_trees(state) with mount_image(state): diff --git a/mkosi/util.py b/mkosi/util.py index c1586a51a..a2490c178 100644 --- a/mkosi/util.py +++ b/mkosi/util.py @@ -15,6 +15,7 @@ import re import resource import stat import sys +import tempfile from collections.abc import Iterable, Iterator, Mapping from pathlib import Path from typing import Any, Callable, Optional, TypeVar @@ -187,7 +188,12 @@ def scopedenv(env: Mapping[str, Any]) -> Iterator[None]: old = copy.copy(os.environ) os.environ |= env + # python caches the default temporary directory so when we might modify TMPDIR we have to make sure it + # gets recalculated (see https://docs.python.org/3/library/tempfile.html#tempfile.tempdir). + tempfile.tempdir = None + try: yield finally: os.environ = old + tempfile.tempdir = None -- 2.47.2