]> git.ipfire.org Git - thirdparty/mkosi.git/commitdiff
More comprehensive tmpfile fix 1722/head
authorDaan De Meyer <daan.j.demeyer@gmail.com>
Tue, 1 Aug 2023 20:30:05 +0000 (22:30 +0200)
committerDaan De Meyer <daan.j.demeyer@gmail.com>
Tue, 1 Aug 2023 20:30:05 +0000 (22:30 +0200)
mkosi/__init__.py
mkosi/util.py

index d2ca7c625af1de495daa57229a51135f2ebf2436..1583054c1c41a4436fc783398d8bfa9da967bc85 100644 (file)
@@ -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):
index c1586a51a9172d9f44e6f1e94a139162438d9e15..a2490c1787d5312a6cb044c166db88db062a83fd 100644 (file)
@@ -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