mirror of
https://github.com/saltstack/salt.git
synced 2025-04-17 10:10:20 +00:00
Merge pull request #48985 from garethgreenaway/48123_file_directory_recurse_fails_broken_symlink
[2018.3] Fix to salt/modules/file.py
This commit is contained in:
commit
3325b7d4c0
2 changed files with 33 additions and 1 deletions
|
@ -4454,7 +4454,8 @@ def check_perms(name, ret, user, group, mode, attrs=None, follow_symlinks=False)
|
|||
perms['lmode'] = salt.utils.files.normalize_mode(cur['mode'])
|
||||
|
||||
is_dir = os.path.isdir(name)
|
||||
if not salt.utils.platform.is_windows() and not is_dir:
|
||||
is_link = os.path.islink(name)
|
||||
if not salt.utils.platform.is_windows() and not is_dir and not is_link:
|
||||
lattrs = lsattr(name)
|
||||
if lattrs is not None:
|
||||
# List attributes on file
|
||||
|
|
|
@ -1043,6 +1043,37 @@ class FileTest(ModuleCase, SaltReturnAssertsMixin):
|
|||
self.assertTrue(os.path.exists(good_file))
|
||||
self.assertFalse(os.path.exists(wrong_file))
|
||||
|
||||
def test_directory_broken_symlink(self):
|
||||
'''
|
||||
Ensure that file.directory works even if a directory
|
||||
contains broken symbolic link
|
||||
'''
|
||||
try:
|
||||
tmp_dir = os.path.join(TMP, 'foo')
|
||||
null_file = '{0}/null'.format(tmp_dir)
|
||||
broken_link = '{0}/broken'.format(tmp_dir)
|
||||
|
||||
if IS_WINDOWS:
|
||||
self.run_function('file.mkdir', [tmp_dir, 'Administrators'])
|
||||
else:
|
||||
os.mkdir(tmp_dir, 0o700)
|
||||
|
||||
self.run_function('file.symlink', [null_file, broken_link])
|
||||
|
||||
if IS_WINDOWS:
|
||||
ret = self.run_state(
|
||||
'file.directory', name=tmp_dir, recurse={'mode'},
|
||||
follow_symlinks=True, win_owner='Administrators')
|
||||
else:
|
||||
ret = self.run_state(
|
||||
'file.directory', name=tmp_dir, recurse={'mode'},
|
||||
file_mode=644, dir_mode=755)
|
||||
|
||||
self.assertSaltTrueReturn(ret)
|
||||
finally:
|
||||
if os.path.isdir(tmp_dir):
|
||||
self.run_function('file.remove', [tmp_dir])
|
||||
|
||||
@with_tempdir(create=False)
|
||||
def test_recurse(self, name):
|
||||
'''
|
||||
|
|
Loading…
Add table
Reference in a new issue