Mercurial > public > mercurial-scm > hg-stable
diff mercurial/posix.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 | f1fa8f481c7c |
children | 5b0a3f6cbead |
line wrap: on
line diff
--- a/mercurial/posix.py Fri Feb 11 22:24:10 2011 +0800 +++ b/mercurial/posix.py Fri Dec 24 15:23:01 2010 +0100 @@ -77,20 +77,26 @@ if l: if not stat.S_ISLNK(s): # switch file to link - data = open(f).read() + fp = open(f) + data = fp.read() + fp.close() os.unlink(f) try: os.symlink(data, f) except: # failed to make a link, rewrite file - open(f, "w").write(data) + fp = open(f, "w") + fp.write(data) + fp.close() # no chmod needed at this point return if stat.S_ISLNK(s): # switch link to file data = os.readlink(f) os.unlink(f) - open(f, "w").write(data) + fp = open(f, "w") + fp.write(data) + fp.close() s = 0666 & ~umask # avoid restatting for chmod sx = s & 0100