# HG changeset patch # User Sylvain Thénault # Date 1468936438 -7200 # Node ID f6ba947c11ee6b961c4959a10b72ae9cda3ab84d # Parent bc473cddba5e9699a3612ed8cbe7adf736bfe6c1 [web] Fix bug with usage of os.rename under windows environment In 7c386161ebd6 we removed cache handling from property sheet and introduced usage of a tempfile + os.rename to get atomic generation of files. The pb is that this is not portable, since under windows os.rename will raise an exception if the file already exists (because there is no way to write a file atomatically in such case). This kind of thing should be out of the CW scope anyway, so implements a quick & dirty fix in the mean time. Closes #14214794 diff -r bc473cddba5e -r f6ba947c11ee web/propertysheet.py --- a/web/propertysheet.py Wed Jul 20 09:40:04 2016 +0200 +++ b/web/propertysheet.py Tue Jul 19 15:53:58 2016 +0200 @@ -1,4 +1,4 @@ -# copyright 2010 LOGILAB S.A. (Paris, FRANCE), all rights reserved. +# copyright 2010-2016 LOGILAB S.A. (Paris, FRANCE), all rights reserved. # contact http://www.logilab.fr/ -- mailto:contact@logilab.fr # # This file is part of CubicWeb. @@ -29,10 +29,12 @@ ('STYLESHEETS_IE', list), ('STYLESHEETS_PRINT', list), ] + class lazystr(object): def __init__(self, string, context): self.string = string self.context = context + def __str__(self): return self.string % self.context @@ -105,7 +107,12 @@ tmpfd, tmpfile = tempfile.mkstemp(dir=rcachedir, prefix=osp.basename(cachefile)) with os.fdopen(tmpfd, 'w') as stream: stream.write(content) - os.rename(tmpfile, cachefile) + try: + os.rename(tmpfile, cachefile) + except IOError: + # Under windows, os.rename won't overwrite an existing file + os.unlink(cachefile) + os.rename(tmpfile, cachefile) adirectory = self._cache_directory return adirectory