mirror of
https://github.com/valitydev/salt.git
synced 2024-11-08 17:33:54 +00:00
Create directories from makedirs=True with the right ownership
Fixes #1264
This commit is contained in:
parent
69e2d12a67
commit
1620f05b82
@ -117,12 +117,19 @@ def __clean_tmp(sfn):
|
||||
os.remove(sfn)
|
||||
|
||||
|
||||
def _makedirs(path):
|
||||
def _makedirs(path, user=None, group=None, mode=None):
|
||||
'''
|
||||
Ensure that the directory containing this path is available.
|
||||
'''
|
||||
if not os.path.isdir(os.path.dirname(path)):
|
||||
os.makedirs(os.path.dirname(path))
|
||||
directory = os.path.dirname(path)
|
||||
|
||||
if not os.path.isdir(directory):
|
||||
os.makedirs(directory)
|
||||
# If a caller such as managed() is invoked with
|
||||
# makedirs=True, make sure that any created dirs
|
||||
# are created with the same user and group to
|
||||
# follow the principal of least surprise method.
|
||||
_check_perms(directory, None, user, group, mode)
|
||||
|
||||
|
||||
def _is_bin(path):
|
||||
@ -962,14 +969,14 @@ def managed(name,
|
||||
|
||||
if not os.path.isdir(os.path.dirname(name)):
|
||||
if makedirs:
|
||||
_makedirs(name)
|
||||
_makedirs(name, user=user, group=group, mode=mode)
|
||||
else:
|
||||
__clean_tmp(sfn)
|
||||
return _error(ret, 'Parent directory not present')
|
||||
else:
|
||||
if not os.path.isdir(os.path.dirname(name)):
|
||||
if makedirs:
|
||||
_makedirs(name)
|
||||
_makedirs(name, user=user, group=group, mode=mode)
|
||||
else:
|
||||
__clean_tmp(sfn)
|
||||
return _error(ret, 'Parent directory not present')
|
||||
@ -1078,12 +1085,12 @@ def directory(name,
|
||||
# The dir does not exist, make it
|
||||
if not os.path.isdir(os.path.dirname(name)):
|
||||
if makedirs:
|
||||
_makedirs(name)
|
||||
_makedirs(name, user=user, group=group, mode=mode)
|
||||
else:
|
||||
return _error(
|
||||
ret, 'No directory to create {0} in'.format(name))
|
||||
if not os.path.isdir(name):
|
||||
_makedirs(name)
|
||||
_makedirs(name, user=user, group=group, mode=mode)
|
||||
os.makedirs(name)
|
||||
if not os.path.isdir(name):
|
||||
return _error(ret, 'Failed to create directory {0}'.format(name))
|
||||
@ -1280,7 +1287,7 @@ def recurse(name,
|
||||
)
|
||||
dirname = os.path.dirname(dest)
|
||||
if not os.path.isdir(dirname):
|
||||
_makedirs(dest)
|
||||
_makedirs(dest, user=user, group=group)
|
||||
if not dirname in vdir:
|
||||
# verify the directory perms if they are set
|
||||
# _check_perms(name, ret, user, group, mode)
|
||||
|
Loading…
Reference in New Issue
Block a user