summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJordan Borean <jborean93@gmail.com>2020-09-28 15:28:01 +1000
committerGitHub <noreply@github.com>2020-09-28 00:28:01 -0500
commit68278f36fd616293e11440dde9f5c9519cb09b4c (patch)
tree84acc2e5e2d21fb097b1c978a93b869b1405d28d
parentab100f8ee58f02c47f229e780873bb500452e5a7 (diff)
downloadansible-68278f36fd616293e11440dde9f5c9519cb09b4c.tar.gz
psrp - fix hang when copying an empty file (#71649) (#71651)
(cherry picked from commit b615789fcc8d2ddd831ef04c89163300c3bc1a0b)
-rw-r--r--changelogs/fragments/psrp-copy-empty-file.yml2
-rw-r--r--lib/ansible/plugins/connection/psrp.py3
-rw-r--r--test/integration/targets/connection_psrp/files/empty.txt0
-rw-r--r--test/integration/targets/connection_psrp/tests.yml48
4 files changed, 53 insertions, 0 deletions
diff --git a/changelogs/fragments/psrp-copy-empty-file.yml b/changelogs/fragments/psrp-copy-empty-file.yml
new file mode 100644
index 0000000000..282fbeeb66
--- /dev/null
+++ b/changelogs/fragments/psrp-copy-empty-file.yml
@@ -0,0 +1,2 @@
+bugfixes:
+- psrp - Fix hang when copying an empty file to the remote target
diff --git a/lib/ansible/plugins/connection/psrp.py b/lib/ansible/plugins/connection/psrp.py
index d53ca4068e..9fab96935f 100644
--- a/lib/ansible/plugins/connection/psrp.py
+++ b/lib/ansible/plugins/connection/psrp.py
@@ -663,6 +663,9 @@ end {
b64_data = base64.b64encode(b_data)
yield [to_text(b64_data)]
+ if offset == 0: # empty file
+ yield [""]
+
rc, stdout, stderr = self._exec_psrp_script(copy_script, read_gen(), arguments=[out_path], force_stop=True)
return rc, stdout, stderr, sha1_hash.hexdigest()
diff --git a/test/integration/targets/connection_psrp/files/empty.txt b/test/integration/targets/connection_psrp/files/empty.txt
new file mode 100644
index 0000000000..e69de29bb2
--- /dev/null
+++ b/test/integration/targets/connection_psrp/files/empty.txt
diff --git a/test/integration/targets/connection_psrp/tests.yml b/test/integration/targets/connection_psrp/tests.yml
index 1247ee1927..dabbf40729 100644
--- a/test/integration/targets/connection_psrp/tests.yml
+++ b/test/integration/targets/connection_psrp/tests.yml
@@ -83,3 +83,51 @@
- shell_unicode_output.rc == 0
- "shell_unicode_output.stdout == '\U0001F4A9\n'"
- shell_unicode_output.stderr == ''
+
+ - name: copy empty file
+ win_copy:
+ src: empty.txt
+ dest: C:\Windows\TEMP\empty.txt
+ register: copy_empty
+
+ - name: get result of copy empty file
+ win_stat:
+ path: C:\Windows\TEMP\empty.txt
+ get_checksum: yes
+ register: copy_empty_actual
+
+ - name: assert copy empty file
+ assert:
+ that:
+ - copy_empty.checksum == 'da39a3ee5e6b4b0d3255bfef95601890afd80709'
+ - copy_empty_actual.stat.checksum == 'da39a3ee5e6b4b0d3255bfef95601890afd80709'
+ - copy_empty_actual.stat.size == 0
+
+ - block:
+ - name: fetch empty file
+ fetch:
+ src: C:\Windows\TEMP\empty.txt
+ dest: /tmp/empty.txt
+ flat: yes
+ register: fetch_empty
+
+ - name: get result of fetch empty file
+ stat:
+ path: /tmp/empty.txt
+ get_checksum: yes
+ register: fetch_empty_actual
+ delegate_to: localhost
+
+ - name: assert fetch empty file
+ assert:
+ that:
+ - fetch_empty.checksum == 'da39a3ee5e6b4b0d3255bfef95601890afd80709'
+ - fetch_empty_actual.stat.checksum == 'da39a3ee5e6b4b0d3255bfef95601890afd80709'
+ - fetch_empty_actual.stat.size == 0
+
+ always:
+ - name: remove tmp file
+ file:
+ path: /tmp/empty.txt
+ state: absent
+ delegate_to: localhost