[config] load_configuration should not crash because of fs errors. Closes #2286215

authorSylvain Thénault <sylvain.thenault@logilab.fr>
changeset4c1efb5bde0a
branchstable
phasepublic
hiddenno
parent revision#0044a29ea118 [workflow ui] fix state/transition edition form on existing entity. Closes #2423531
child revision#8de41063d629 [web login] fix after login redirection: redirect expect an url not a relative path. Breaks on cases like '?vid=aview'. Closes #2423575
files modified by this revision
cwconfig.py
# HG changeset patch
# User Sylvain Thénault <sylvain.thenault@logilab.fr>
# Date 1342774668 -7200
# Fri Jul 20 10:57:48 2012 +0200
# Branch stable
# Node ID 4c1efb5bde0a31d4e1698bcd2cb89966b6f92377
# Parent 0044a29ea1184908bee3e8c961bb3efa67ed592c
[config] load_configuration should not crash because of fs errors. Closes #2286215

diff --git a/cwconfig.py b/cwconfig.py
@@ -169,10 +169,11 @@
1  __docformat__ = "restructuredtext en"
2  _ = unicode
3 
4  import sys
5  import os
6 +import stat
7  import logging
8  import logging.config
9  from smtplib import SMTP
10  from threading import Lock
11  from os.path import (exists, join, expanduser, abspath, normpath,
@@ -1074,11 +1075,16 @@
12          server process and is writeable.
13 
14          If not, try to fix this, letting exception propagate when not possible.
15          """
16          if not exists(path):
17 -            os.makedirs(path)
18 +            self.info('creating %s directory', path)
19 +            try:
20 +                os.makedirs(path)
21 +            except OSError, ex:
22 +                self.warning('error while creating %s directory: %s', path, ex)
23 +                return
24          if self['uid']:
25              try:
26                  uid = int(self['uid'])
27              except ValueError:
28                  from pwd import getpwnam
@@ -1088,14 +1094,24 @@
29                  uid = os.getuid()
30              except AttributeError: # we are on windows
31                  return
32          fstat = os.stat(path)
33          if fstat.st_uid != uid:
34 -            os.chown(path, uid, os.getgid())
35 -        import stat
36 +            self.info('giving ownership of %s directory to %s', path, self['uid'])
37 +            try:
38 +                os.chown(path, uid, os.getgid())
39 +            except OSError, ex:
40 +                self.warning('error while giving ownership of %s directory to %s: %s',
41 +                             path, self['uid'], ex)
42          if not (fstat.st_mode & stat.S_IWUSR):
43 -            os.chmod(path, fstat.st_mode | stat.S_IWUSR)
44 +            self.info('forcing write permission on directory %s', path)
45 +            try:
46 +                os.chmod(path, fstat.st_mode | stat.S_IWUSR)
47 +            except OSError, ex:
48 +                self.warning('error while forcing write permission on directory %s: %s',
49 +                             path, ex)
50 +                return
51 
52      @cached
53      def instance_md5_version(self):
54          from hashlib import md5 # pylint: disable=E0611
55          infos = []