commit:     711c55e34680ec5bc3bfc7c8e919b111b5c437fc
Author:     Zac Medico <zmedico <AT> gentoo <DOT> org>
AuthorDate: Thu Nov 13 04:11:08 2025 +0000
Commit:     Zac Medico <zmedico <AT> gentoo <DOT> org>
CommitDate: Thu Nov 13 05:33:57 2025 +0000
URL:        https://gitweb.gentoo.org/proj/portage.git/commit/?id=711c55e3

movefile: use tempfile module for pid namespace safety

Bug: https://bugs.gentoo.org/851015
Signed-off-by: Zac Medico <zmedico <AT> gentoo.org>

 lib/portage/util/movefile.py | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/lib/portage/util/movefile.py b/lib/portage/util/movefile.py
index 4fae97a199..d7401e2275 100644
--- a/lib/portage/util/movefile.py
+++ b/lib/portage/util/movefile.py
@@ -8,6 +8,7 @@ import fnmatch
 import os as _os
 import stat
 import textwrap
+import tempfile
 
 import portage
 from portage import (
@@ -282,7 +283,10 @@ def movefile(
     # and them use os.rename() to replace the destination.
     if hardlink_candidates:
         head, tail = os.path.split(dest)
-        hardlink_tmp = os.path.join(head, 
f".{tail}._portage_merge_.{portage.getpid()}")
+        with tempfile.NamedTemporaryFile(
+            dir=head, prefix=f".{tail}._portage_merge_.{portage.getpid()}"
+        ) as hardlink_tmp_file:
+            hardlink_tmp = hardlink_tmp_file.name
         try:
             os.unlink(hardlink_tmp)
         except OSError as e:

Reply via email to