From a07e3727707e4cc6b3192e535f07abcc7d6469a6 Mon Sep 17 00:00:00 2001 From: Harmen Stoppels Date: Fri, 13 Dec 2024 19:49:32 +0100 Subject: [PATCH] filter_file: make tempfile later (#48108) * filter_file: make tempfile later * also add a `.` after the filename --- lib/spack/llnl/util/filesystem.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/lib/spack/llnl/util/filesystem.py b/lib/spack/llnl/util/filesystem.py index 806a917a7ab..1342f47d952 100644 --- a/lib/spack/llnl/util/filesystem.py +++ b/lib/spack/llnl/util/filesystem.py @@ -344,15 +344,17 @@ def groupid_to_group(x): regex = re.escape(regex) regex_compiled = re.compile(regex) for path in path_to_os_path(*filenames): - fd, temp_path = tempfile.mkstemp(prefix=os.path.basename(path), dir=os.path.dirname(path)) - os.close(fd) - if ignore_absent and not os.path.exists(path): tty.debug(f'FILTER FILE: file "{path}" not found. Skipping to next file.') continue else: tty.debug(f'FILTER FILE: {path} [replacing "{regex}"]') + fd, temp_path = tempfile.mkstemp( + prefix=f"{os.path.basename(path)}.", dir=os.path.dirname(path) + ) + os.close(fd) + shutil.copy(path, temp_path) errored = False