Windows atomic rename correction
authorPlamen Dimitrov <plamen.dimitrov@intra2net.com>
Thu, 28 Jun 2012 15:42:39 +0000 (17:42 +0200)
committerPlamen Dimitrov <plamen.dimitrov@intra2net.com>
Thu, 28 Jun 2012 15:42:39 +0000 (17:42 +0200)
.gitignore
src/caching_data.py
src/fix_imap_internaldate.py

index fd368ef..b1f9917 100644 (file)
@@ -12,8 +12,8 @@ build/
 bin/
 
 src/.metadata/
-src/.project
-src/.pydevproject
+.project
+.pydevproject
 src/__pycache__/
 
 # kdevelop
index c578a3b..d9db749 100644 (file)
@@ -14,7 +14,7 @@ but WITHOUT ANY WARRANTY; without even the implied warranty of
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 GNU General Public License for more details.
 '''
-import os, tempfile
+import os, platform, tempfile
 import pickle
 import logging
 from mailbox_state import MailboxState
@@ -68,16 +68,22 @@ class CachingData:
                     del saved_data[user]
                     logging.debug("The user %s will not be saved.", user)
             self.data = saved_data
-    
             # avoid test mode or cases where nothing needs saving
             if(len(saved_data)==0):
+                cachefile.close()
                 os.unlink(tmpname)
                 return
             
             # serialize in file
             pickle.dump((self.version, self.data), cachefile)
             logging.debug("%s users stored.", len(self.data))
-            cachefile.close()
+
+            # handle windows non-atomic rename
+            if(platform.system()=='Windows'):
+                if(os.path.exists(CACHE_FILENAME)):
+                    cachefile.close()
+                    os.unlink(CACHE_FILENAME)
+
             os.rename(tmpname, CACHE_FILENAME)
         except:
             os.unlink(tmpname)           
index cc46e4d..04f3fd8 100644 (file)
@@ -138,7 +138,7 @@ def synchronize_csv(config, test_mode):
                                     internal_date.strftime("%d %b %Y %H:%M:%S"),
                                     received_date.strftime("%d %b %Y %H:%M:%S"),
                                     fetched_received_date.split("Received:")[1])
-                    if(test_mode==0):
+                    if(not test_mode):
                         try:
                             session.update_message(mid, box.name, received_date)
                         except UserWarning as ex: