mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-10-23 12:33:59 -07:00
Fix copy to only follow symlinks for files in the non-recursive case
Revert "**Temporary**"
This reverts commit 28b86b1148
.
We don't need this now that copy has been fixed
This commit is contained in:
parent
9e028ab704
commit
f332151f59
5 changed files with 66 additions and 18 deletions
|
@ -14,7 +14,7 @@
|
|||
name: ensure temp dir exists
|
||||
|
||||
# file cannot do this properly, use command instead
|
||||
- name: Create ciruclar symbolic link
|
||||
- name: Create circular symbolic link
|
||||
command: ln -s ../ circles
|
||||
args:
|
||||
chdir: '{{role_path}}/files/subdir/subdir1'
|
||||
|
@ -57,7 +57,7 @@
|
|||
|
||||
- name: Remove circular symbolic link
|
||||
file:
|
||||
path: subdir/subdir1/circles
|
||||
path: '{{ role_path }}/files/subdir/subdir1/circles'
|
||||
state: absent
|
||||
connection: local
|
||||
|
||||
|
|
|
@ -16,6 +16,10 @@
|
|||
mode: 0444
|
||||
register: copy_result
|
||||
|
||||
- name: Record the sha of the test file for later tests
|
||||
set_fact:
|
||||
remote_file_hash: "{{ copy_result['checksum'] }}"
|
||||
|
||||
- name: Check the mode of the output file
|
||||
file:
|
||||
name: "{{ remote_file }}"
|
||||
|
@ -173,7 +177,7 @@
|
|||
- name: Create a hardlink to the file
|
||||
file:
|
||||
src: '{{ remote_file }}'
|
||||
dest: '{{ output_dir }}/hard.lnk'
|
||||
dest: '{{ remote_dir }}/hard.lnk'
|
||||
state: hard
|
||||
|
||||
- name: copy the same contents into place
|
||||
|
@ -191,7 +195,7 @@
|
|||
|
||||
- name: Check the stat results of the hard link
|
||||
stat:
|
||||
path: "{{ output_dir }}/hard.lnk"
|
||||
path: "{{ remote_dir }}/hard.lnk"
|
||||
register: hlink_results
|
||||
|
||||
- name: Check that the file did not change
|
||||
|
@ -216,7 +220,7 @@
|
|||
|
||||
- name: Check the stat results of the hard link
|
||||
stat:
|
||||
path: "{{ output_dir }}/hard.lnk"
|
||||
path: "{{ remote_dir }}/hard.lnk"
|
||||
register: hlink_results
|
||||
|
||||
- name: Check that the file changed permissions but is still the same
|
||||
|
@ -242,7 +246,7 @@
|
|||
|
||||
- name: Check the stat results of the hard link
|
||||
stat:
|
||||
path: "{{ output_dir }}/hard.lnk"
|
||||
path: "{{ remote_dir }}/hard.lnk"
|
||||
register: hlink_results
|
||||
|
||||
- name: Check that the file changed and hardlink was broken
|
||||
|
@ -1105,6 +1109,10 @@
|
|||
|
||||
remote_user: root
|
||||
|
||||
#
|
||||
# Follow=True tests
|
||||
#
|
||||
|
||||
# test overwriting a link using "follow=yes" so that the link
|
||||
# is preserved and the link target is updated
|
||||
|
||||
|
@ -1122,7 +1130,7 @@
|
|||
- name: Update the test file using follow=True to preserve the link
|
||||
copy:
|
||||
dest: "{{ remote_dir }}/follow_link"
|
||||
content: "this is the new content\n"
|
||||
src: foo.txt
|
||||
follow: yes
|
||||
register: replace_follow_result
|
||||
|
||||
|
@ -1131,19 +1139,37 @@
|
|||
path: "{{ remote_dir }}/follow_link"
|
||||
register: stat_link_result
|
||||
|
||||
- name: Assert that the link is still a link
|
||||
- name: Assert that the link is still a link and contents were changed
|
||||
assert:
|
||||
that:
|
||||
- stat_link_result.stat.islnk
|
||||
- stat_link_result['stat']['islnk']
|
||||
- stat_link_result['stat']['lnk_target'] == './follow_test'
|
||||
- replace_follow_result['changed']
|
||||
- "replace_follow_result['checksum'] == remote_file_hash"
|
||||
|
||||
- name: Get the checksum of the link target
|
||||
shell: "{{ ansible_python_interpreter }} -c 'import hashlib; print(hashlib.sha1(open(\"{{remote_dir | expanduser}}/follow_test\", \"rb\").read()).hexdigest())'"
|
||||
register: target_file_result
|
||||
# Symlink handling when the dest is already there
|
||||
# https://github.com/ansible/ansible-modules-core/issues/1568
|
||||
|
||||
- name: Assert that the link target was updated
|
||||
- name: test idempotency by trying to copy to the symlink with the same contents
|
||||
copy:
|
||||
dest: "{{ remote_dir }}/follow_link"
|
||||
src: foo.txt
|
||||
follow: yes
|
||||
register: replace_follow_result
|
||||
|
||||
- name: Stat the link path
|
||||
stat:
|
||||
path: "{{ remote_dir }}/follow_link"
|
||||
register: stat_link_result
|
||||
|
||||
- name: Assert that the link is still a link and contents were changed
|
||||
assert:
|
||||
that:
|
||||
- replace_follow_result.checksum == target_file_result.stdout
|
||||
- stat_link_result['stat']['islnk']
|
||||
- stat_link_result['stat']['lnk_target'] == './follow_test'
|
||||
- not replace_follow_result['changed']
|
||||
- replace_follow_result['checksum'] == remote_file_hash
|
||||
|
||||
|
||||
- name: Update the test file using follow=False to overwrite the link
|
||||
copy:
|
||||
|
@ -1169,6 +1195,13 @@
|
|||
- "stat_results.stat.checksum == ('modified'|hash('sha1'))"
|
||||
- "not stat_results.stat.islnk"
|
||||
|
||||
# test overwriting a link using "follow=yes" so that the link
|
||||
# is preserved and the link target is updated when the thing being copied is a link
|
||||
|
||||
#
|
||||
# File mode tests
|
||||
#
|
||||
|
||||
- name: setup directory for test
|
||||
file: state=directory dest={{remote_dir }}/directory mode=0755
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue