# HG changeset patch # User Arseniy Alekseyev # Date 1652211026 -3600 # Node ID 4ff4e23de7df86f05318ca6d89fd928675ade2bb # Parent 237855525f64d0584698551d22d80d59f237aaa4 clone: use better names for temp files Before this commit, the file names are /tmp/tmpn8smvlr8 After this commit, they are more like /tmp/hg-clone-n8smvlr8/00manifest.ndb3qj52v6, which makes it much clearer what these files correspond to. Differential Revision: https://phab.mercurial-scm.org/D12623 diff -r 237855525f64 -r 4ff4e23de7df mercurial/streamclone.py --- a/mercurial/streamclone.py Mon May 02 16:27:14 2022 +0400 +++ b/mercurial/streamclone.py Tue May 10 20:30:26 2022 +0100 @@ -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): diff -r 237855525f64 -r 4ff4e23de7df mercurial/util.py --- a/mercurial/util.py Mon May 02 16:27:14 2022 +0400 +++ b/mercurial/util.py Tue May 10 20:30:26 2022 +0100 @@ -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"""