From 5bb6893d41fab87cefad9a19091cb6b45ae5879d Mon Sep 17 00:00:00 2001 From: Stanislau Hlebik Date: Wed, 17 May 2017 06:42:04 -0700 Subject: [PATCH] infinitepush: cleanup temp files Summary: Infinitepush didn't clean up temp files during pulls. Test Plan: Choose any hg server that's not in vip (for example, hg014.lla2). Run `hg pull ssh://hg014.lla2.facebook.com//data/scm/fbsource -r INFINITEPUSH_COMMIT_HASH` Check that new /tmp/tmp* file has appeared. Install fixed infinitepush extension on the server. Run the same command again, make sure it works fine. Note: no new unittests, because temp filenames are random and that's difficult to test. Reviewers: #mercurial, dschatzberg, tja Reviewed By: tja Subscribers: mjpieters Differential Revision: https://phabricator.intern.facebook.com/D5077767 Tasks: 17599765 Signature: t1:5077767:1495025042:d209d1e5342442ac8b05a4c80748780bbf36846c --- infinitepush/__init__.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/infinitepush/__init__.py b/infinitepush/__init__.py index 3959828508..386ed12dc6 100644 --- a/infinitepush/__init__.py +++ b/infinitepush/__init__.py @@ -473,7 +473,7 @@ def getbundlechunks(orig, repo, source, heads=None, bundlecaps=None, **kwargs): newheads = [] scratchheads = [] nodestobundle = {} - allbundlerepos = [] + allbundlestocleanup = [] try: for head in heads: if head not in repo.changelog.nodemap: @@ -482,7 +482,7 @@ def getbundlechunks(orig, repo, source, heads=None, bundlecaps=None, **kwargs): bundlepath = "bundle:%s+%s" % (repo.root, newbundlefile) bundlerepo = repository(repo.ui, bundlepath) - allbundlerepos.append(bundlerepo) + allbundlestocleanup.append((bundlerepo, newbundlefile)) bundlerevs = set(_readbundlerevs(bundlerepo)) bundlecaps = _includefilelogstobundle( bundlecaps, bundlerepo, bundlerevs, repo.ui) @@ -499,8 +499,14 @@ def getbundlechunks(orig, repo, source, heads=None, bundlecaps=None, **kwargs): newheads.extend(bundleroots) scratchheads.append(head) finally: - for bundlerepo in allbundlerepos: + for bundlerepo, bundlefile in allbundlestocleanup: bundlerepo.close() + try: + os.unlink(bundlefile) + except (IOError, OSError): + # if we can't cleanup the file then just ignore the error, + # no need to fail + pass pullfrombundlestore = bool(scratchbundles) wrappedchangegrouppart = False