repository: Simplify restore_atime code
repository.BaseRepository().restore_atime() was testing in complex ways that it only operates on a Maildir and that the 'restoreatime' setting is set. This is unecessary, we can simply make the base implementation a NoOp, and move the implementation to MaildirRepository(). This will save a tad of work for everyone doing IMAP<->IMAP synchronization and simplify the code. Also document the functions. Signed-off-by: Sebastian Spaeth <Sebastian@SSpaeth.de> Signed-off-by: Nicolas Sebrecht <nicolas.s-dev@laposte.net>
This commit is contained in:
parent
d2af21d57d
commit
c1a2b1559d
@ -39,17 +39,13 @@ class BaseRepository(object, CustomConfig.ConfigHelperMixin):
|
|||||||
if not os.path.exists(self.uiddir):
|
if not os.path.exists(self.uiddir):
|
||||||
os.mkdir(self.uiddir, 0700)
|
os.mkdir(self.uiddir, 0700)
|
||||||
|
|
||||||
# The 'restoreatime' config parameter only applies to local Maildir
|
|
||||||
# mailboxes.
|
|
||||||
def restore_atime(self):
|
def restore_atime(self):
|
||||||
if self.config.get('Repository ' + self.name, 'type').strip() != \
|
"""Sets folders' atime back to their values after a sync
|
||||||
'Maildir':
|
|
||||||
return
|
|
||||||
|
|
||||||
if not self.config.has_option('Repository ' + self.name, 'restoreatime') or not self.config.getboolean('Repository ' + self.name, 'restoreatime'):
|
Controlled by the 'restoreatime' config parameter (default
|
||||||
return
|
False), applies only to local Maildir mailboxes and does nothing
|
||||||
|
on all other repository types."""
|
||||||
return self.restore_folder_atimes()
|
pass
|
||||||
|
|
||||||
def connect(self):
|
def connect(self):
|
||||||
"""Establish a connection to the remote, if necessary. This exists
|
"""Establish a connection to the remote, if necessary. This exists
|
||||||
|
@ -39,15 +39,19 @@ class MaildirRepository(BaseRepository):
|
|||||||
os.mkdir(self.root, 0700)
|
os.mkdir(self.root, 0700)
|
||||||
|
|
||||||
def _append_folder_atimes(self, foldername):
|
def _append_folder_atimes(self, foldername):
|
||||||
|
"""Store the atimes of a folder's new|cur in self.folder_atimes"""
|
||||||
p = os.path.join(self.root, foldername)
|
p = os.path.join(self.root, foldername)
|
||||||
new = os.path.join(p, 'new')
|
new = os.path.join(p, 'new')
|
||||||
cur = os.path.join(p, 'cur')
|
cur = os.path.join(p, 'cur')
|
||||||
f = p, os.stat(new)[ST_ATIME], os.stat(cur)[ST_ATIME]
|
f = p, os.stat(new)[ST_ATIME], os.stat(cur)[ST_ATIME]
|
||||||
self.folder_atimes.append(f)
|
self.folder_atimes.append(f)
|
||||||
|
|
||||||
def restore_folder_atimes(self):
|
def restore_atime(self):
|
||||||
if not self.folder_atimes:
|
"""Sets folders' atime back to their values after a sync
|
||||||
return
|
|
||||||
|
Controlled by the 'restoreatime' config parameter."""
|
||||||
|
if not self.getconfboolean('restoreatime', False):
|
||||||
|
return # not configured
|
||||||
|
|
||||||
for f in self.folder_atimes:
|
for f in self.folder_atimes:
|
||||||
t = f[1], os.stat(os.path.join(f[0], 'new'))[ST_MTIME]
|
t = f[1], os.stat(os.path.join(f[0], 'new'))[ST_MTIME]
|
||||||
|
Loading…
Reference in New Issue
Block a user