comparison mercurial/revlog.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 77351c88dd10
children b51bf961b3cb
comparison
equal deleted inserted replaced
13399:eff102facb15 13400:14f3795a5ed7
241 241
242 i = '' 242 i = ''
243 try: 243 try:
244 f = self.opener(self.indexfile) 244 f = self.opener(self.indexfile)
245 i = f.read() 245 i = f.read()
246 f.close()
246 if len(i) > 0: 247 if len(i) > 0:
247 v = struct.unpack(versionformat, i[:4])[0] 248 v = struct.unpack(versionformat, i[:4])[0]
248 except IOError, inst: 249 except IOError, inst:
249 if inst.errno != errno.ENOENT: 250 if inst.errno != errno.ENOENT:
250 raise 251 raise
1165 chain = self._addrevision(node, None, transaction, link, 1166 chain = self._addrevision(node, None, transaction, link,
1166 p1, p2, (chainrev, delta), ifh, dfh) 1167 p1, p2, (chainrev, delta), ifh, dfh)
1167 if not dfh and not self._inline: 1168 if not dfh and not self._inline:
1168 # addrevision switched from inline to conventional 1169 # addrevision switched from inline to conventional
1169 # reopen the index 1170 # reopen the index
1171 ifh.close()
1170 dfh = self.opener(self.datafile, "a") 1172 dfh = self.opener(self.datafile, "a")
1171 ifh = self.opener(self.indexfile, "a") 1173 ifh = self.opener(self.indexfile, "a")
1172 finally: 1174 finally:
1173 if dfh: 1175 if dfh:
1174 dfh.close() 1176 dfh.close()
1224 1226
1225 try: 1227 try:
1226 f = self.opener(self.datafile) 1228 f = self.opener(self.datafile)
1227 f.seek(0, 2) 1229 f.seek(0, 2)
1228 actual = f.tell() 1230 actual = f.tell()
1231 f.close()
1229 dd = actual - expected 1232 dd = actual - expected
1230 except IOError, inst: 1233 except IOError, inst:
1231 if inst.errno != errno.ENOENT: 1234 if inst.errno != errno.ENOENT:
1232 raise 1235 raise
1233 dd = 0 1236 dd = 0
1234 1237
1235 try: 1238 try:
1236 f = self.opener(self.indexfile) 1239 f = self.opener(self.indexfile)
1237 f.seek(0, 2) 1240 f.seek(0, 2)
1238 actual = f.tell() 1241 actual = f.tell()
1242 f.close()
1239 s = self._io.size 1243 s = self._io.size
1240 i = max(0, actual // s) 1244 i = max(0, actual // s)
1241 di = actual - (i * s) 1245 di = actual - (i * s)
1242 if self._inline: 1246 if self._inline:
1243 databytes = 0 1247 databytes = 0