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
This commit is contained in:
Rodolfo García Peñas (kix) 2021-07-25 15:46:31 +02:00
parent c305f47e84
commit 1a0c29a00e

View File

@ -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):