SQLite: close db when done
Backported from 6fb5700f94
.
Signed-off-by: Nicolas Sebrecht <nicolas.s-dev@laposte.net>
This commit is contained in:
parent
cb8678a5b5
commit
b840e66d59
@ -595,3 +595,4 @@ def syncfolder(account, remotefolder, quick):
|
|||||||
for folder in ["statusfolder", "localfolder", "remotefolder"]:
|
for folder in ["statusfolder", "localfolder", "remotefolder"]:
|
||||||
if folder in locals():
|
if folder in locals():
|
||||||
locals()[folder].dropmessagelistcache()
|
locals()[folder].dropmessagelistcache()
|
||||||
|
statusfolder.closefiles()
|
||||||
|
@ -155,6 +155,9 @@ class LocalStatusFolder(BaseFolder):
|
|||||||
self.readstatus(cachefd)
|
self.readstatus(cachefd)
|
||||||
cachefd.close()
|
cachefd.close()
|
||||||
|
|
||||||
|
def closefiles(self):
|
||||||
|
pass # Closing files is done on a per-transaction basis.
|
||||||
|
|
||||||
def save(self):
|
def save(self):
|
||||||
"""Save changed data to disk. For this backend it is the same as saveall."""
|
"""Save changed data to disk. For this backend it is the same as saveall."""
|
||||||
|
|
||||||
|
@ -222,6 +222,12 @@ class LocalStatusSQLiteFolder(BaseFolder):
|
|||||||
self.messagelist[uid]['labels'] = labels
|
self.messagelist[uid]['labels'] = labels
|
||||||
self.messagelist[uid]['mtime'] = row[2]
|
self.messagelist[uid]['mtime'] = row[2]
|
||||||
|
|
||||||
|
def closefiles(self):
|
||||||
|
try:
|
||||||
|
self.connection.close()
|
||||||
|
except:
|
||||||
|
pass
|
||||||
|
|
||||||
def dropmessagelistcache(self):
|
def dropmessagelistcache(self):
|
||||||
self.messagelist = {}
|
self.messagelist = {}
|
||||||
|
|
||||||
@ -338,7 +344,7 @@ class LocalStatusSQLiteFolder(BaseFolder):
|
|||||||
def savemessageslabelsbulk(self, labels):
|
def savemessageslabelsbulk(self, labels):
|
||||||
"""
|
"""
|
||||||
Saves labels from a dictionary in a single database operation.
|
Saves labels from a dictionary in a single database operation.
|
||||||
|
|
||||||
"""
|
"""
|
||||||
data = [(', '.join(sorted(l)), uid) for uid, l in labels.items()]
|
data = [(', '.join(sorted(l)), uid) for uid, l in labels.items()]
|
||||||
self.__sql_write('UPDATE status SET labels=? WHERE id=?', data, executemany=True)
|
self.__sql_write('UPDATE status SET labels=? WHERE id=?', data, executemany=True)
|
||||||
|
@ -170,7 +170,7 @@ class BaseRepository(CustomConfig.ConfigHelperMixin, object):
|
|||||||
to infinite folder creation cycles."""
|
to infinite folder creation cycles."""
|
||||||
|
|
||||||
if not self.get_create_folders() and not dst_repo.get_create_folders():
|
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
|
return
|
||||||
|
|
||||||
src_repo = self
|
src_repo = self
|
||||||
@ -178,7 +178,7 @@ class BaseRepository(CustomConfig.ConfigHelperMixin, object):
|
|||||||
dst_folders = dst_repo.getfolders()
|
dst_folders = dst_repo.getfolders()
|
||||||
# Do we need to refresh the folder list afterwards?
|
# Do we need to refresh the folder list afterwards?
|
||||||
src_haschanged, dst_haschanged = False, False
|
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.
|
# to the dest folder's sep.
|
||||||
src_hash = {}
|
src_hash = {}
|
||||||
for folder in src_folders:
|
for folder in src_folders:
|
||||||
@ -191,13 +191,13 @@ class BaseRepository(CustomConfig.ConfigHelperMixin, object):
|
|||||||
|
|
||||||
# Find new folders on src_repo.
|
# Find new folders on src_repo.
|
||||||
for src_name_t, src_folder in src_hash.iteritems():
|
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():
|
if not dst_repo.get_create_folders():
|
||||||
break
|
break
|
||||||
if src_folder.sync_this and not src_name_t in dst_folders:
|
if src_folder.sync_this and not src_name_t in dst_folders:
|
||||||
try:
|
try:
|
||||||
dst_repo.makefolder(src_name_t)
|
dst_repo.makefolder(src_name_t)
|
||||||
dst_haschanged = True # Need to refresh list
|
dst_haschanged = True # Need to refresh list.
|
||||||
except OfflineImapError as e:
|
except OfflineImapError as e:
|
||||||
self.ui.error(e, exc_info()[2],
|
self.ui.error(e, exc_info()[2],
|
||||||
"Creating folder %s on repository %s"%
|
"Creating folder %s on repository %s"%
|
||||||
|
@ -46,6 +46,9 @@ class LocalStatusRepository(BaseRepository):
|
|||||||
# self._folders is a dict of name:LocalStatusFolders()
|
# self._folders is a dict of name:LocalStatusFolders()
|
||||||
self._folders = {}
|
self._folders = {}
|
||||||
|
|
||||||
|
def _instanciatefolder(self, foldername):
|
||||||
|
return self.LocalStatusFolderClass(foldername, self) # Instanciate.
|
||||||
|
|
||||||
def setup_backend(self, backend):
|
def setup_backend(self, backend):
|
||||||
if backend in self.backends.keys():
|
if backend in self.backends.keys():
|
||||||
self._backend = backend
|
self._backend = backend
|
||||||
@ -87,19 +90,22 @@ class LocalStatusRepository(BaseRepository):
|
|||||||
return # bail out in dry-run mode
|
return # bail out in dry-run mode
|
||||||
|
|
||||||
# Create an empty StatusFolder
|
# Create an empty StatusFolder
|
||||||
folder = self.LocalStatusFolderClass(foldername, self)
|
folder = self._instanciatefolder(foldername)
|
||||||
folder.save()
|
folder.save()
|
||||||
|
folder.closefiles()
|
||||||
|
|
||||||
# Invalidate the cache.
|
# Invalidate the cache.
|
||||||
self.forgetfolders()
|
self.forgetfolders()
|
||||||
|
|
||||||
def getfolder(self, foldername):
|
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:
|
if foldername in self._folders:
|
||||||
return self._folders[foldername]
|
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 is empty, try to import data from an other backend.
|
||||||
if folder.isnewfolder():
|
if folder.isnewfolder():
|
||||||
|
Loading…
Reference in New Issue
Block a user