--- a/cubicweb/cwconfig.py Tue Aug 16 14:26:41 2016 +0200
+++ b/cubicweb/cwconfig.py Thu Sep 08 11:40:50 2016 +0200
@@ -1107,6 +1107,9 @@
except OSError as ex:
self.warning('error while creating %s directory: %s', path, ex)
return
+ self.ensure_uid(path)
+
+ def get_uid(self):
if self['uid']:
try:
uid = int(self['uid'])
@@ -1118,22 +1121,37 @@
uid = os.getuid()
except AttributeError: # we are on windows
return
+ return uid
+
+ def ensure_uid(self, path, enforce_write=False):
+ if not exists(path):
+ return
+ uid = self.get_uid()
+ if uid is None:
+ return
fstat = os.stat(path)
if fstat.st_uid != uid:
- self.info('giving ownership of %s directory to %s', path, self['uid'])
+ self.info('giving ownership of %s to %s', path, self['uid'])
try:
os.chown(path, uid, os.getgid())
except OSError as ex:
- self.warning('error while giving ownership of %s directory to %s: %s',
+ self.warning('error while giving ownership of %s to %s: %s',
path, self['uid'], ex)
- if not (fstat.st_mode & stat.S_IWUSR):
- self.info('forcing write permission on directory %s', path)
+
+ if enforce_write and not (fstat.st_mode & stat.S_IWUSR):
+ self.info('forcing write permission on %s', path)
try:
os.chmod(path, fstat.st_mode | stat.S_IWUSR)
except OSError as ex:
- self.warning('error while forcing write permission on directory %s: %s',
+ self.warning('error while forcing write permission on %s: %s',
path, ex)
- return
+
+ def ensure_uid_directory(self, path, enforce_write=False):
+ self.check_writeable_uid_directory(path)
+ for dirpath, dirnames, filenames in os.walk(path):
+ for name in filenames:
+ self.ensure_uid(join(dirpath, name), enforce_write)
+ return path
@cached
def instance_md5_version(self):