mirror of
https://github.com/saltstack/salt.git
synced 2025-04-17 10:10:20 +00:00
Fixed issue with file.line on Windows running Python 2.
The target file was being read as binary, but written as text, causing file.line to append an extra linesep on every line. Added integration test to ensure file.line produces the expected content.
This commit is contained in:
parent
8f89c99fa5
commit
ef7b6bbb81
2 changed files with 10 additions and 1 deletions
|
@ -1861,7 +1861,9 @@ def line(path, content, match=None, mode=None, location=None,
|
|||
if __opts__['test'] is False:
|
||||
fh_ = None
|
||||
try:
|
||||
fh_ = salt.utils.atomicfile.atomic_open(path, 'w')
|
||||
# Make sure we match the file mode from salt.utils.fopen
|
||||
mode = 'wb' if six.PY2 and salt.utils.is_windows() else 'w'
|
||||
fh_ = salt.utils.atomicfile.atomic_open(path, mode)
|
||||
fh_.write(body)
|
||||
finally:
|
||||
if fh_:
|
||||
|
|
|
@ -323,6 +323,13 @@ class FileModuleTest(integration.ModuleCase):
|
|||
mode='insert', after='Hello')
|
||||
self.assertIn('Hello' + os.linesep + '+Goodbye', ret)
|
||||
|
||||
def test_file_line_content(self):
|
||||
self.minion_run('file.line', self.myfile, 'Goodbye',
|
||||
mode='insert', after='Hello')
|
||||
with salt.utils.fopen(self.myfile, 'r') as fp:
|
||||
content = fp.read()
|
||||
self.assertEqual(content, 'Hello' + os.linesep + 'Goodbye' + os.linesep)
|
||||
|
||||
if __name__ == '__main__':
|
||||
from integration import run_tests
|
||||
run_tests(FileModuleTest)
|
||||
|
|
Loading…
Add table
Reference in a new issue