Use file list, not recursion, in _fixup_perms. (#16924)

Run setfacl/chown/chmod on each temp dir and file.

This fixes temp file permissions handling on platforms such as FreeBSD
which always return success when using find -exec. This is done by
eliminating the use of find when setting up temp files and directories.

Additionally, tests that now pass on FreeBSD have been enabled for CI.
This commit is contained in:
Matt Clay 2016-08-05 18:40:28 -07:00 committed by GitHub
commit 72cca01cd4
11 changed files with 55 additions and 76 deletions

View file

@ -57,45 +57,25 @@ class ShellBase(object):
def path_has_trailing_slash(self, path):
return path.endswith('/')
def chmod(self, mode, path, recursive=True):
path = pipes.quote(path)
cmd = ['chmod']
if recursive:
cmd.append('-R') # many chmods require -R before file list
cmd.extend([mode, path])
def chmod(self, paths, mode):
cmd = ['chmod', mode]
cmd.extend(paths)
cmd = [pipes.quote(c) for c in cmd]
return ' '.join(cmd)
def chown(self, path, user, group=None, recursive=True):
path = pipes.quote(path)
user = pipes.quote(user)
cmd = ['chown']
if recursive:
cmd.append('-R') # many chowns require -R before file list
if group is None:
cmd.extend([user, path])
else:
group = pipes.quote(group)
cmd.extend(['%s:%s' % (user, group), path])
def chown(self, paths, user):
cmd = ['chown', user]
cmd.extend(paths)
cmd = [pipes.quote(c) for c in cmd]
return ' '.join(cmd)
def set_user_facl(self, path, user, mode, recursive=True):
def set_user_facl(self, paths, user, mode):
"""Only sets acls for users as that's really all we need"""
path = pipes.quote(path)
mode = pipes.quote(mode)
user = pipes.quote(user)
cmd = ['setfacl', '-m', 'u:%s:%s' % (user, mode)]
if recursive:
cmd = ['find', path, '-exec'] + cmd + ["'{}'", "'+'"]
else:
cmd.append(path)
cmd.extend(paths)
cmd = [pipes.quote(c) for c in cmd]
return ' '.join(cmd)

View file

@ -68,13 +68,13 @@ class ShellModule(object):
path = self._unquote(path)
return path.endswith('/') or path.endswith('\\')
def chmod(self, mode, path, recursive=True):
def chmod(self, paths, mode):
raise NotImplementedError('chmod is not implemented for Powershell')
def chown(self, path, user, group=None, recursive=True):
def chown(self, paths, user):
raise NotImplementedError('chown is not implemented for Powershell')
def set_user_facl(self, path, user, mode, recursive=True):
def set_user_facl(self, paths, user, mode):
raise NotImplementedError('set_user_facl is not implemented for Powershell')
def remove(self, path, recurse=False):