(cherry picked from commit e68f895
)
Co-authored-by: Matt Martz <matt@sivel.net>
This commit is contained in:
parent
643726860b
commit
28632756d6
2 changed files with 11 additions and 6 deletions
2
changelogs/fragments/piped-transfer-empty-files.yaml
Normal file
2
changelogs/fragments/piped-transfer-empty-files.yaml
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
bugfixes:
|
||||||
|
- ssh connection - Support empty files with piped transfer_method (https://github.com/ansible/ansible/issues/45426)
|
|
@ -953,13 +953,16 @@ class Connection(ConnectionBase):
|
||||||
# we pass sudoable=False to disable pty allocation, which
|
# we pass sudoable=False to disable pty allocation, which
|
||||||
# would end up mixing stdout/stderr and screwing with newlines
|
# would end up mixing stdout/stderr and screwing with newlines
|
||||||
(returncode, stdout, stderr) = self.exec_command('dd if=%s bs=%s' % (in_path, BUFSIZE), sudoable=False)
|
(returncode, stdout, stderr) = self.exec_command('dd if=%s bs=%s' % (in_path, BUFSIZE), sudoable=False)
|
||||||
out_file = open(to_bytes(out_path, errors='surrogate_or_strict'), 'wb+')
|
with open(to_bytes(out_path, errors='surrogate_or_strict'), 'wb+') as out_file:
|
||||||
out_file.write(stdout)
|
out_file.write(stdout)
|
||||||
out_file.close()
|
|
||||||
else:
|
else:
|
||||||
in_data = open(to_bytes(in_path, errors='surrogate_or_strict'), 'rb').read()
|
with open(to_bytes(in_path, errors='surrogate_or_strict'), 'rb') as f:
|
||||||
in_data = to_bytes(in_data, nonstring='passthru')
|
in_data = to_bytes(f.read(), nonstring='passthru')
|
||||||
(returncode, stdout, stderr) = self.exec_command('dd of=%s bs=%s' % (out_path, BUFSIZE), in_data=in_data, sudoable=False)
|
if not in_data:
|
||||||
|
count = ' count=0'
|
||||||
|
else:
|
||||||
|
count = ''
|
||||||
|
(returncode, stdout, stderr) = self.exec_command('dd of=%s bs=%s%s' % (out_path, BUFSIZE, count), in_data=in_data, sudoable=False)
|
||||||
|
|
||||||
# Check the return code and rollover to next method if failed
|
# Check the return code and rollover to next method if failed
|
||||||
if returncode == 0:
|
if returncode == 0:
|
||||||
|
|
Loading…
Reference in a new issue