[Updated] D12623: clone: use better names for temp files

baymax (Baymax, Your Personal Patch-care Companion) phabricator at mercurial-scm.org
Tue May 24 13:35:58 UTC 2022


baymax added a comment.
baymax updated this revision to Diff 33420.


  ✅ refresh by Heptapod after a successful CI run (🐙 💚)

REPOSITORY
  rHG Mercurial

CHANGES SINCE LAST UPDATE
  https://phab.mercurial-scm.org/D12623?vs=33404&id=33420

BRANCH
  default

CHANGES SINCE LAST ACTION
  https://phab.mercurial-scm.org/D12623/new/

REVISION DETAIL
  https://phab.mercurial-scm.org/D12623

AFFECTED FILES
  mercurial/streamclone.py
  mercurial/util.py

CHANGE DETAILS

diff --git a/mercurial/util.py b/mercurial/util.py
--- a/mercurial/util.py
+++ b/mercurial/util.py
@@ -2592,6 +2592,14 @@
             self.close()
 
 
+def tryrmdir(f):
+    try:
+        removedirs(f)
+    except OSError as e:
+        if e.errno != errno.ENOENT and e.errno != errno.ENOTEMPTY:
+            raise
+
+
 def unlinkpath(f, ignoremissing=False, rmdir=True):
     # type: (bytes, bool, bool) -> None
     """unlink and remove the directory if it is empty"""
diff --git a/mercurial/streamclone.py b/mercurial/streamclone.py
--- a/mercurial/streamclone.py
+++ b/mercurial/streamclone.py
@@ -558,11 +558,15 @@
 @contextlib.contextmanager
 def maketempcopies():
     """return a function to temporary copy file"""
+
     files = []
+    dst_dir = pycompat.mkdtemp(prefix=b'hg-clone-')
     try:
 
         def copy(src):
-            fd, dst = pycompat.mkstemp()
+            fd, dst = pycompat.mkstemp(
+                prefix=os.path.basename(src), dir=dst_dir
+            )
             os.close(fd)
             files.append(dst)
             util.copyfiles(src, dst, hardlink=True)
@@ -572,6 +576,7 @@
     finally:
         for tmp in files:
             util.tryunlink(tmp)
+        util.tryrmdir(dst_dir)
 
 
 def _makemap(repo):



To: aalekseyev, #hg-reviewers, marmoute, Alphare
Cc: marmoute, mercurial-patches
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mercurial-scm.org/pipermail/mercurial-patches/attachments/20220524/5f1fc049/attachment-0002.html>


More information about the Mercurial-patches mailing list