From: Daan De Meyer Date: Tue, 1 Aug 2023 20:30:05 +0000 (+0200) Subject: More comprehensive tmpfile fix X-Git-Tag: v15~48^2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=refs%2Fpull%2F1722%2Fhead;p=thirdparty%2Fmkosi.git More comprehensive tmpfile fix --- 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