[PATCH] Make sure bundlerepo doesn't leak temp files (issue2491)
Adrian Buehlmann
adrian at cadifra.com
Sat Feb 12 04:47:06 CST 2011
# HG changeset patch
# User Adrian Buehlmann <adrian at cadifra.com>
# Date 1297504691 -3600
# Node ID e898aca66ad00102f35774e96526136e964e84a5
# Parent d4ab9486e514dd24e21a2ca3b6c439ea13d85cab
Make sure bundlerepo doesn't leak temp files (issue2491)
Add empty repository.close() and call it in dispatch.
Remove bundlerepository.__del__(), merging it into bundlerepository.close(),
which overrides repository.close().
http://docs.python.org/reference/datamodel.html says:
"It is not guaranteed that __del__() methods are called for objects that
still exist when the interpreter exits."
diff --git a/mercurial/bundlerepo.py b/mercurial/bundlerepo.py
--- a/mercurial/bundlerepo.py
+++ b/mercurial/bundlerepo.py
@@ -251,11 +251,6 @@ class bundlerepository(localrepo.localre
self.bundle.close()
if self.tempfile is not None:
os.unlink(self.tempfile)
-
- def __del__(self):
- del self.bundle
- if self.tempfile is not None:
- os.unlink(self.tempfile)
if self._tempparent:
shutil.rmtree(self._tempparent, True)
diff --git a/mercurial/dispatch.py b/mercurial/dispatch.py
--- a/mercurial/dispatch.py
+++ b/mercurial/dispatch.py
@@ -589,8 +589,12 @@ def _dispatch(ui, args):
msg = ' '.join(' ' in a and repr(a) or a for a in fullargs)
ui.log("command", msg + "\n")
d = lambda: util.checksignature(func)(ui, *args, **cmdoptions)
- return runcommand(lui, repo, cmd, fullargs, ui, options, d,
- cmdpats, cmdoptions)
+ try:
+ return runcommand(lui, repo, cmd, fullargs, ui, options, d,
+ cmdpats, cmdoptions)
+ finally:
+ if repo:
+ repo.close()
def _runcommand(ui, options, cmd, cmdfunc):
def checkargs():
diff --git a/mercurial/repo.py b/mercurial/repo.py
--- a/mercurial/repo.py
+++ b/mercurial/repo.py
@@ -35,3 +35,6 @@ class repository(object):
def cancopy(self):
return self.local()
+
+ def close(self):
+ pass
diff --git a/tests/test-bundle.t b/tests/test-bundle.t
--- a/tests/test-bundle.t
+++ b/tests/test-bundle.t
@@ -188,6 +188,13 @@ Log -R full.hg in fresh empty
date: Thu Jan 01 00:00:00 1970 +0000
summary: 0.0
+Make sure bundlerepo doesn't leak tempfiles (issue2491)
+
+ $ ls .hg
+ 00changelog.i
+ cache
+ requires
+ store
Pull ../full.hg into empty (with hook)
More information about the Mercurial-devel
mailing list