[PATCH 1/3] repository: Simplify restore_atime code

Sebastian Spaeth Sebastian at SSpaeth.de
Thu Sep 15 14:06:30 BST 2011


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 at SSpaeth.de>
---
 offlineimap/repository/Base.py    |   14 +++++---------
 offlineimap/repository/Maildir.py |   10 +++++++---
 2 files changed, 12 insertions(+), 12 deletions(-)

diff --git a/offlineimap/repository/Base.py b/offlineimap/repository/Base.py
index 184bc9a..72a5f88 100644
--- a/offlineimap/repository/Base.py
+++ b/offlineimap/repository/Base.py
@@ -39,17 +39,13 @@ class BaseRepository(object, CustomConfig.ConfigHelperMixin):
         if not os.path.exists(self.uiddir):
             os.mkdir(self.uiddir, 0700)
 
-    # The 'restoreatime' config parameter only applies to local Maildir
-    # mailboxes.
     def restore_atime(self):
-        if self.config.get('Repository ' + self.name, 'type').strip() != \
-                'Maildir':
-            return
+        """Sets folders' atime back to their values after a sync
 
-        if not self.config.has_option('Repository ' + self.name, 'restoreatime') or not self.config.getboolean('Repository ' + self.name, 'restoreatime'):
-            return
-
-        return self.restore_folder_atimes()
+        Controlled by the 'restoreatime' config parameter (default
+        False), applies only to local Maildir mailboxes and does nothing
+        on all other repository types."""
+        pass
 
     def connect(self):
         """Establish a connection to the remote, if necessary.  This exists
diff --git a/offlineimap/repository/Maildir.py b/offlineimap/repository/Maildir.py
index ef3a723..75e0fe6 100644
--- a/offlineimap/repository/Maildir.py
+++ b/offlineimap/repository/Maildir.py
@@ -39,15 +39,19 @@ class MaildirRepository(BaseRepository):
             os.mkdir(self.root, 0700)
 
     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)
         new = os.path.join(p, 'new')
         cur = os.path.join(p, 'cur')
         f = p, os.stat(new)[ST_ATIME], os.stat(cur)[ST_ATIME]
         self.folder_atimes.append(f)
 
-    def restore_folder_atimes(self):
-        if not self.folder_atimes:
-            return
+    def restore_atime(self):
+        """Sets folders' atime back to their values after a sync
+
+        Controlled by the 'restoreatime' config parameter."""
+        if not self.getconfboolean('restoreatime', False):
+            return # not configured
 
         for f in self.folder_atimes:
             t = f[1], os.stat(os.path.join(f[0], 'new'))[ST_MTIME]
-- 
1.7.4.1





More information about the OfflineIMAP-project mailing list