mirror of
https://github.com/valitydev/salt.git
synced 2024-11-07 08:58:59 +00:00
Fix file.line line endings
This commit is contained in:
parent
4590494b50
commit
baf291b4c8
@ -158,7 +158,12 @@ def atomic_open(filename, mode='w'):
|
|||||||
'''
|
'''
|
||||||
if mode in ('r', 'rb', 'r+', 'rb+', 'a', 'ab'):
|
if mode in ('r', 'rb', 'r+', 'rb+', 'a', 'ab'):
|
||||||
raise TypeError('Read or append modes don\'t work with atomic_open')
|
raise TypeError('Read or append modes don\'t work with atomic_open')
|
||||||
ntf = tempfile.NamedTemporaryFile(mode, prefix='.___atomic_write',
|
kwargs = {
|
||||||
dir=os.path.dirname(filename),
|
'prefix': '.___atomic_write',
|
||||||
delete=False)
|
'dir': os.path.dirname(filename),
|
||||||
|
'delete': False,
|
||||||
|
}
|
||||||
|
if six.PY3:
|
||||||
|
kwargs['newline'] = ''
|
||||||
|
ntf = tempfile.NamedTemporaryFile(mode, **kwargs)
|
||||||
return _AtomicWFile(ntf, ntf.name, filename)
|
return _AtomicWFile(ntf, ntf.name, filename)
|
||||||
|
@ -2404,6 +2404,32 @@ class FileTest(ModuleCase, SaltReturnAssertsMixin):
|
|||||||
self.assertEqual(pwd.getpwuid(temp_file_stats.st_uid).pw_name, user)
|
self.assertEqual(pwd.getpwuid(temp_file_stats.st_uid).pw_name, user)
|
||||||
self.assertEqual(grp.getgrgid(temp_file_stats.st_gid).gr_name, group)
|
self.assertEqual(grp.getgrgid(temp_file_stats.st_gid).gr_name, group)
|
||||||
|
|
||||||
|
@with_tempdir()
|
||||||
|
def test_issue_48557(self, tempdir):
|
||||||
|
tempfile = os.path.join(tempdir, 'temp_file_issue_48557')
|
||||||
|
with open(tempfile, 'wb') as fp:
|
||||||
|
fp.write(os.linesep.join([
|
||||||
|
'test1',
|
||||||
|
'test2',
|
||||||
|
'test3',
|
||||||
|
'',
|
||||||
|
]).encode('utf-8'))
|
||||||
|
ret = self.run_state('file.line',
|
||||||
|
name=tempfile,
|
||||||
|
after='test2',
|
||||||
|
mode='insert',
|
||||||
|
content='test4')
|
||||||
|
self.assertSaltTrueReturn(ret)
|
||||||
|
with open(tempfile, 'rb') as fp:
|
||||||
|
content = fp.read()
|
||||||
|
self.assertEqual(content, os.linesep.join([
|
||||||
|
'test1',
|
||||||
|
'test2',
|
||||||
|
'test4',
|
||||||
|
'test3',
|
||||||
|
'',
|
||||||
|
]).encode('utf-8'))
|
||||||
|
|
||||||
|
|
||||||
class BlockreplaceTest(ModuleCase, SaltReturnAssertsMixin):
|
class BlockreplaceTest(ModuleCase, SaltReturnAssertsMixin):
|
||||||
marker_start = '# start'
|
marker_start = '# start'
|
||||||
|
Loading…
Reference in New Issue
Block a user