avoid removing of data when user removed a maildir

When a maildir is removed it must be considered new for the sync. However, the
local cache of the folder remains. This means the sync of the folder removes all
the missing emails.

Avoid loosing of data for users not aware of the local cache by removing any
pre-existing status cache of a folder when we actually want to create the
database.

Improve style.

Github-fix: https://github.com/OfflineIMAP/offlineimap/issues/333
Signed-off-by: Nicolas Sebrecht <nicolas.s-dev@laposte.net>
This commit is contained in:
Nicolas Sebrecht
2016-06-17 19:47:37 +02:00
parent 08e17de7e2
commit 1410a391bc
5 changed files with 63 additions and 42 deletions

View File

@ -1,5 +1,5 @@
# Local status cache virtual folder
# Copyright (C) 2002-2015 John Goerzen & contributors
# Copyright (C) 2002-2016 John Goerzen & contributors
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
@ -18,11 +18,10 @@
from sys import exc_info
import os
import threading
import six
from .Base import BaseFolder
import six
class LocalStatusFolder(BaseFolder):
"""LocalStatus backend implemented as a plain text file."""
@ -73,8 +72,8 @@ class LocalStatusFolder(BaseFolder):
uid = int(uid)
flags = set(flags)
except ValueError as e:
errstr = "Corrupt line '%s' in cache file '%s'" % \
(line, self.filename)
errstr = ("Corrupt line '%s' in cache file '%s'"%
(line, self.filename))
self.ui.warn(errstr)
six.reraise(ValueError(errstr), None, exc_info()[2])
self.messagelist[uid] = self.msglist_item_initializer(uid)
@ -162,6 +161,15 @@ class LocalStatusFolder(BaseFolder):
def closefiles(self):
pass # Closing files is done on a per-transaction basis.
def purge(self):
"""Remove any pre-existing database."""
try:
os.unlink(self.filename)
except OSError as e:
self.ui.debug('', "could not remove file %s: %s"%
(self.filename, e))
def save(self):
"""Save changed data to disk. For this backend it is the same as saveall."""

View File

@ -88,6 +88,14 @@ class LocalStatusSQLiteFolder(BaseFolder):
if version < LocalStatusSQLiteFolder.cur_version:
self.__upgrade_db(version)
def purge(self):
"""Remove any pre-existing database."""
try:
os.unlink(self.filename)
except OSError as e:
self.ui.debug('', "could not remove file %s: %s"%
(self.filename, e))
def storesmessages(self):
return False