Skip to content

Commit

Permalink
Merge pull request saltstack#50978 from jalandis/avoid-checking-root-…
Browse files Browse the repository at this point in the history
…when-children_only-specified-in-file-directory

Ignoring checking meta data on root directory if children_only specified
  • Loading branch information
dwoz authored Feb 15, 2019
2 parents b1781a7 + 87c2309 commit 86adb6b
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 5 deletions.
14 changes: 9 additions & 5 deletions salt/states/file.py
Original file line number Diff line number Diff line change
Expand Up @@ -693,7 +693,8 @@ def _check_directory(name,
require=False,
exclude_pat=None,
max_depth=None,
follow_symlinks=False):
follow_symlinks=False,
children_only=False):
'''
Check what changes need to be made on a directory
'''
Expand Down Expand Up @@ -743,10 +744,13 @@ def _check_directory(name,
fchange = _check_dir_meta(path, user, group, mode, follow_symlinks)
if fchange:
changes[path] = fchange

# Recurse skips root (we always do dirs, not root), so always check root:
fchange = _check_dir_meta(name, user, group, mode, follow_symlinks)
if fchange:
changes[name] = fchange
if not children_only:
fchange = _check_dir_meta(name, user, group, mode, follow_symlinks)
if fchange:
changes[name] = fchange

if clean:
keep = _gen_keep_files(name, require, walk_d)

Expand Down Expand Up @@ -3410,7 +3414,7 @@ def directory(name,
else:
presult, pcomment, pchanges = _check_directory(
name, user, group, recurse or [], dir_mode, file_mode, clean,
require, exclude_pat, max_depth, follow_symlinks)
require, exclude_pat, max_depth, follow_symlinks, children_only)

if pchanges:
ret['changes'].update(pchanges)
Expand Down
11 changes: 11 additions & 0 deletions tests/unit/states/test_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -955,6 +955,17 @@ def test_directory(self):
(name, user=user, group=group),
ret)

recurse = ['mode']
ret.update({'comment': 'The directory {} is in the '
'correct state'.format(name),
'changes': {},
'result': True})
with patch.object(os.path, 'isdir', mock_t):
self.assertDictEqual(filestate.directory
(name, user=user, dir_mode=700,
recurse=recurse, group=group,
children_only=True), ret)

# 'recurse' function tests: 1

def test_recurse(self):
Expand Down

0 comments on commit 86adb6b

Please sign in to comment.