From 1a0c29a00effffb0f4f65d08bcc4fc8bc7cb4bcb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rodolfo=20Garc=C3=ADa=20Pe=C3=B1as=20=28kix=29?= Date: Sun, 25 Jul 2021 15:46:31 +0200 Subject: [PATCH] OS rename raises an exception on Windows This patch checks the exception raises by os.rename() on Windows and provide the same behavior than Linux. This patch is related to issue #37, issue 5. This patch sets closes the issue 37. closes #37 --- offlineimap/folder/Base.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/offlineimap/folder/Base.py b/offlineimap/folder/Base.py index 58f4fcd..f871d6f 100644 --- a/offlineimap/folder/Base.py +++ b/offlineimap/folder/Base.py @@ -302,7 +302,15 @@ class BaseFolder: with open(uidfilename + ".tmp", "wt") as uidfile: uidfile.write("%d\n" % newval) - os.rename(uidfilename + ".tmp", uidfilename) + + # This is weird, os.rename on Windows raises an exception, + # But not in Linux. In linux the file is overwritten. + try: + os.rename(uidfilename + ".tmp", uidfilename) + except WindowsError: + os.remove(uidfilename) + os.rename(uidfilename + ".tmp", uidfilename) + self._base_saved_uidvalidity = newval def get_uidvalidity(self):