[web] fix os.rename usage on windows when destination exists
authorPhilippe Pepiot <philippe.pepiot@logilab.fr>
Tue, 21 Feb 2017 10:12:47 +0100
changeset 11965 fb03a4113979
parent 11964 01eeea97e549
child 11966 fe995d56c949
[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	Wed Jan 25 14:28:20 2017 +0100
+++ b/cubicweb/web/propertysheet.py	Tue Feb 21 10:12:47 2017 +0100
@@ -19,6 +19,7 @@
 
 
 
+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)