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
This commit is contained in:
Stanislau Hlebik 2017-05-17 06:42:04 -07:00
parent 24d8640017
commit 5bb6893d41

View File

@ -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