SQLite: close db when done

Signed-off-by: Nicolas Sebrecht <nicolas.s-dev@laposte.net>
This commit is contained in:
Nicolas Sebrecht 2016-04-09 19:52:33 +02:00
parent 1ba5e9160d
commit 6fb5700f94
5 changed files with 24 additions and 8 deletions

View File

@ -595,3 +595,4 @@ def syncfolder(account, remotefolder, quick):
for folder in ["statusfolder", "localfolder", "remotefolder"]:
if folder in locals():
locals()[folder].dropmessagelistcache()
statusfolder.closefiles()

View File

@ -154,6 +154,9 @@ class LocalStatusFolder(BaseFolder):
self.readstatus(cachefd)
cachefd.close()
def closefiles(self):
pass # Closing files is done on a per-transaction basis.
def save(self):
"""Save changed data to disk. For this backend it is the same as saveall."""

View File

@ -221,6 +221,12 @@ class LocalStatusSQLiteFolder(BaseFolder):
self.messagelist[uid]['labels'] = labels
self.messagelist[uid]['mtime'] = row[2]
def closefiles(self):
try:
self.connection.close()
except:
pass
# Interface from LocalStatusFolder
def save(self):
pass

View File

@ -170,7 +170,7 @@ class BaseRepository(CustomConfig.ConfigHelperMixin, object):
to infinite folder creation cycles."""
if not self.get_create_folders() and not dst_repo.get_create_folders():
# quick exit if no folder creation is enabled on either side.
# Quick exit if no folder creation is enabled on either side.
return
src_repo = self
@ -178,7 +178,7 @@ class BaseRepository(CustomConfig.ConfigHelperMixin, object):
dst_folders = dst_repo.getfolders()
# Do we need to refresh the folder list afterwards?
src_haschanged, dst_haschanged = False, False
# Create hashes with the names, but convert the source folders
# Create hashes with the names, but convert the source folders.
# to the dest folder's sep.
src_hash = {}
for folder in src_folders:
@ -191,14 +191,14 @@ class BaseRepository(CustomConfig.ConfigHelperMixin, object):
# Find and create new folders on src_repo.
for src_name_t, src_folder in src_hash.iteritems():
# Don't create on dst_repo, if it is readonly
# Don't create on dst_repo, if it is readonly.
if not dst_repo.get_create_folders():
break
if src_folder.sync_this and not src_name_t in dst_folders:
try:
dst_repo.makefolder(src_name_t)
dst_haschanged = True # Need to refresh list
dst_haschanged = True # Need to refresh list.
except OfflineImapError as e:
self.ui.error(e, exc_info()[2],
"Creating folder %s on repository %s"%

View File

@ -46,6 +46,9 @@ class LocalStatusRepository(BaseRepository):
# self._folders is a dict of name:LocalStatusFolders()
self._folders = {}
def _instanciatefolder(self, foldername):
return self.LocalStatusFolderClass(foldername, self) # Instanciate.
def setup_backend(self, backend):
if backend in self.backends.keys():
self._backend = backend
@ -87,19 +90,22 @@ class LocalStatusRepository(BaseRepository):
return # bail out in dry-run mode
# Create an empty StatusFolder
folder = self.LocalStatusFolderClass(foldername, self)
folder = self._instanciatefolder(foldername)
folder.save()
folder.closefiles()
# Invalidate the cache.
self.forgetfolders()
def getfolder(self, foldername):
"""Return the Folder() object for a foldername."""
"""Return the Folder() object for a foldername.
Caller must call closefiles() on the folder when done."""
if foldername in self._folders:
return self._folders[foldername]
folder = self.LocalStatusFolderClass(foldername, self)
folder = self._instanciatefolder(foldername)
# If folder is empty, try to import data from an other backend.
if folder.isnewfolder():