Support transfering empty files to target host. Fixes #36725 (#45751)

This commit is contained in:
Matt Martz 2018-09-18 09:05:20 -05:00 committed by GitHub
parent f8c98600a9
commit b6fcbfe813
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 39 additions and 8 deletions

View file

@ -148,8 +148,12 @@ class Connection(ConnectionBase):
out_path = shlex_quote(self._prefix_login_path(out_path))
try:
with open(to_bytes(in_path, errors='surrogate_or_strict'), 'rb') as in_file:
if not os.fstat(in_file.fileno()).st_size:
count = ' count=0'
else:
count = ''
try:
p = self._buffered_exec_command('dd of=%s bs=%s' % (out_path, BUFSIZE), stdin=in_file)
p = self._buffered_exec_command('dd of=%s bs=%s%s' % (out_path, BUFSIZE, count), stdin=in_file)
except OSError:
raise AnsibleError("chroot connection requires dd command in the chroot")
try: