Mercurial > public > mercurial-scm > hg-stable
diff mercurial/archival.py @ 13400:14f3795a5ed7
explicitly close files
Add missing calls to close() to many places where files are
opened. Relying on reference counting to catch them soon-ish is not
portable and fails in environments with a proper GC, such as PyPy.
author | Dan Villiom Podlaski Christiansen <danchr@gmail.com> |
---|---|
date | Fri, 24 Dec 2010 15:23:01 +0100 |
parents | aae2d5cbde64 |
children | 9a41af6b9f29 |
line wrap: on
line diff
--- a/mercurial/archival.py Fri Feb 11 22:24:10 2011 +0800 +++ b/mercurial/archival.py Fri Dec 24 15:23:01 2010 +0100 @@ -84,6 +84,7 @@ def __init__(self, dest, mtime, kind=''): self.mtime = mtime + self.fileobj = None def taropen(name, mode, fileobj=None): if kind == 'gz': @@ -93,8 +94,10 @@ gzfileobj = self.GzipFileWithTime(name, mode + 'b', zlib.Z_BEST_COMPRESSION, fileobj, timestamp=mtime) + self.fileobj = gzfileobj return tarfile.TarFile.taropen(name, mode, gzfileobj) else: + self.fileobj = fileobj return tarfile.open(name, mode + kind, fileobj) if isinstance(dest, str): @@ -120,6 +123,8 @@ def done(self): self.z.close() + if self.fileobj: + self.fileobj.close() class tellable(object): '''provide tell method for zipfile.ZipFile when writing to http