Merge pull request #51757 from twangboy/fix_case_2017.7

Make recurse and directory case sensitive (2017.7)
This commit is contained in:
Daniel Wozniak 2019-02-23 15:23:23 -07:00 committed by GitHub
commit b4153d3833
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 6 deletions

View file

@ -609,6 +609,7 @@ def _check_file(name):
def _find_keep_files(root, keep):
'''
Compile a list of valid keep files (and directories).
Used by _clean_dir()
'''
real_keep = set()
real_keep.add(root)
@ -632,6 +633,7 @@ def _clean_dir(root, keep, exclude_pat):
Clean out all of the files and directories in a directory (root) while
preserving the files in a list (keep) and part of exclude_pat
'''
root = os.path.normcase(root)
real_keep = _find_keep_files(root, keep)
removed = set()
@ -2933,7 +2935,7 @@ def directory(name,
perms: full_control
- win_inheritance: False
'''
name = os.path.normcase(os.path.expanduser(name))
name = os.path.expanduser(name)
ret = {'name': name,
'changes': {},
'pchanges': {},
@ -3419,7 +3421,7 @@ def recurse(name,
)
kwargs.pop('env')
name = os.path.normcase(os.path.expanduser(sdecode(name)))
name = os.path.expanduser(sdecode(name))
user = _test_owner(kwargs, user=user)
if salt.utils.is_windows():

View file

@ -1930,15 +1930,20 @@ class TestFindKeepFiles(TestCase):
@skipIf(not salt.utils.is_windows(), 'Only run on Windows')
def test__find_keep_files_win32(self):
'''
Test _find_keep_files. The `_find_keep_files` function is only called by
_clean_dir, so case doesn't matter. Should return all lower case.
'''
keep = filestate._find_keep_files(
'c:\\test\\parent_folder',
['C:\\test\\parent_folder\\meh-2.txt']
['C:\\test\\parent_folder\\meh-1.txt',
'C:\\Test\\Parent_folder\\Meh-2.txt']
)
expected = [
'c:\\',
'c:\\test',
'c:\\test\\parent_folder',
'c:\\test\\parent_folder\\meh-2.txt'
]
'c:\\test\\parent_folder\\meh-1.txt',
'c:\\test\\parent_folder\\meh-2.txt']
actual = sorted(list(keep))
assert actual == expected, actual
self.assertListEqual(actual, expected)