don't leak fds in upgrade

This commit is contained in:
Damien Elmes 2011-10-27 17:42:23 +09:00
parent caf46e948a
commit ad81a564d1
2 changed files with 4 additions and 2 deletions

View file

@ -113,7 +113,7 @@ analyze;""")
######################################################################
def _openDB(self, path):
(fd, self.tmppath) = tmpfile(suffix=".anki2")
self.tmppath = tmpfile(suffix=".anki2")
shutil.copy(path, self.tmppath)
self.db = DB(self.tmppath)

View file

@ -238,7 +238,9 @@ def tmpdir():
return _tmpdir
def tmpfile(prefix="", suffix=""):
return tempfile.mkstemp(dir=tmpdir(), prefix=prefix, suffix=suffix)
(fd, name) = tempfile.mkstemp(dir=tmpdir(), prefix=prefix, suffix=suffix)
os.close(fd)
return name
def namedtmp(name):
"Return tmpdir+name. Deletes any existing file."