[web] fix os.rename usage on windows when destination exists 3.23
authorPhilippe Pepiot <philippe.pepiot@logilab.fr>
Tue, 21 Feb 2017 10:12:47 +0100
branch3.23
changeset 11961 a25e52cd8be4
parent 11845 eed83dee2c79
child 12004 1822d36e2c24
[web] fix os.rename usage on windows when destination exists os.rename on windows will raise OSError (or WindowsError subclass) when if destination file already exists. Also check that exception is EEXIST. There is an attempt to fix in f6ba947c but using IOError instead of OSError. Closes #14214794
cubicweb/web/propertysheet.py
--- a/cubicweb/web/propertysheet.py	Thu Nov 17 17:26:49 2016 +0100
+++ b/cubicweb/web/propertysheet.py	Tue Feb 21 10:12:47 2017 +0100
@@ -19,6 +19,7 @@
 
 __docformat__ = "restructuredtext en"
 
+import errno
 import re
 import os
 import os.path as osp
@@ -109,7 +110,9 @@
                 stream.write(content)
             try:
                 os.rename(tmpfile, cachefile)
-            except IOError:
+            except OSError as err:
+                if err.errno != errno.EEXIST:
+                    raise
                 # Under windows, os.rename won't overwrite an existing file
                 os.unlink(cachefile)
                 os.rename(tmpfile, cachefile)