diff --git a/salt/states/file.py b/salt/states/file.py index 74d5be1d7d49..2e8d9f0fceae 100644 --- a/salt/states/file.py +++ b/salt/states/file.py @@ -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 ''' @@ -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) @@ -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) diff --git a/tests/unit/states/test_file.py b/tests/unit/states/test_file.py index 23d37dccce59..9df712f4ad29 100644 --- a/tests/unit/states/test_file.py +++ b/tests/unit/states/test_file.py @@ -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):