Skip to content

Commit

Permalink
Merge pull request #49172 from Ch3LL/bp-49118
Browse files Browse the repository at this point in the history
[2018.3.3] cherry pick #49118
  • Loading branch information
dwoz committed Aug 17, 2018
2 parents 85ffc8d + ce5e17b commit b3a247b
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 7 deletions.
8 changes: 6 additions & 2 deletions salt/modules/file.py
Expand Up @@ -4079,8 +4079,12 @@ def _get_local_file_source_sum(path):
parsed_path = os.path.join(
urlparsed_source.netloc, urlparsed_source.path).rstrip(os.sep)
unix_local_source = parsed_scheme in ('file', '')

if unix_local_source:
if parsed_scheme == '':
parsed_path = sfn = source
if not os.path.exists(sfn):
msg = 'Local file source {0} does not exist'.format(sfn)
return '', {}, msg
elif parsed_scheme == 'file':
sfn = parsed_path
if not os.path.exists(sfn):
msg = 'Local file source {0} does not exist'.format(sfn)
Expand Down
4 changes: 3 additions & 1 deletion salt/states/file.py
Expand Up @@ -2429,7 +2429,9 @@ def managed(name,
'contents_grains is not a string or list of strings, and '
'is not binary data. SLS is likely malformed.'
)
contents = os.linesep.join(validated_contents)
contents = os.linesep.join(
[line.rstrip('\n').rstrip('\r') for line in validated_contents]
)
if contents_newline and not contents.endswith(os.linesep):
contents += os.linesep
if template:
Expand Down
8 changes: 4 additions & 4 deletions tests/integration/states/test_file.py
Expand Up @@ -861,14 +861,10 @@ def test_directory_clean(self, base_dir):
self.assertFalse(os.path.exists(straydir))
self.assertTrue(os.path.isdir(name))

@skipIf(salt.utils.platform.is_windows(), 'Skip on windows')
@with_tempdir()
def test_directory_clean_exclude(self, base_dir):
'''
file.directory with clean=True and exclude_pat set
Skipped on windows because clean and exclude_pat not supported by
salt.sates.file._check_directory_win
'''
name = os.path.join(base_dir, 'directory_clean_dir')
if not os.path.isdir(name):
Expand Down Expand Up @@ -904,10 +900,14 @@ def test_directory_clean_exclude(self, base_dir):
self.assertFalse(os.path.exists(strayfile2))
self.assertTrue(os.path.exists(keepfile))

@skipIf(salt.utils.platform.is_windows(), 'Skip on windows')
@with_tempdir()
def test_test_directory_clean_exclude(self, base_dir):
'''
file.directory with test=True, clean=True and exclude_pat set
Skipped on windows because clean and exclude_pat not supported by
salt.sates.file._check_directory_win
'''
name = os.path.join(base_dir, 'directory_clean_dir')
os.mkdir(name)
Expand Down

0 comments on commit b3a247b

Please sign in to comment.