mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-04-25 11:51:26 -07:00
fix Mac chown/chmod -R issue, add error checks
The changes to chown/chmod were broken on Mac (-R was being appended to the end of the command- OSX requires it before the file list). A number of base action remote setup commands were also blindly proceeding without checking for success. Added error raises for unrecoverable failure cases.
This commit is contained in:
parent
5fdac707fd
commit
05af5c88ea
2 changed files with 29 additions and 13 deletions
|
@ -54,23 +54,29 @@ class ShellBase(object):
|
|||
|
||||
def chmod(self, mode, path, recursive=True):
|
||||
path = pipes.quote(path)
|
||||
cmd = ['chmod', mode, path]
|
||||
cmd = ['chmod']
|
||||
|
||||
if recursive:
|
||||
cmd.append('-R')
|
||||
cmd.append('-R') # many chmods require -R before file list
|
||||
|
||||
cmd.extend([mode, path])
|
||||
|
||||
return ' '.join(cmd)
|
||||
|
||||
def chown(self, path, user, group=None, recursive=True):
|
||||
path = pipes.quote(path)
|
||||
user = pipes.quote(user)
|
||||
|
||||
if group is None:
|
||||
cmd = ['chown', user, path]
|
||||
else:
|
||||
group = pipes.quote(group)
|
||||
cmd = ['chown', '%s:%s' % (user, group), path]
|
||||
cmd = ['chown']
|
||||
|
||||
if recursive:
|
||||
cmd.append('-R')
|
||||
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])
|
||||
|
||||
return ' '.join(cmd)
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue