SQLite: close db when done
Signed-off-by: Nicolas Sebrecht <nicolas.s-dev@laposte.net>
This commit is contained in:
parent
1ba5e9160d
commit
6fb5700f94
@ -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()
|
||||||
|
@ -154,6 +154,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."""
|
||||||
|
|
||||||
|
@ -221,6 +221,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
|
||||||
|
|
||||||
# Interface from LocalStatusFolder
|
# Interface from LocalStatusFolder
|
||||||
def save(self):
|
def save(self):
|
||||||
pass
|
pass
|
||||||
|
@ -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,14 +191,14 @@ class BaseRepository(CustomConfig.ConfigHelperMixin, object):
|
|||||||
|
|
||||||
# Find and create new folders on src_repo.
|
# Find and create 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