mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
Enforce state='file'
in copy
module
This was causing wrong behaviour when `prev_state` was `hard`-link, since the `file` module tried to apply the same `state` on the new file, causing unexpected errors. Particularly, both `overlay` and `devicemapper` storage drivers in docker use hardlinks to share files between layers. This causes most ansible playbooks to fail when working with files from layers below.
This commit is contained in:
parent
78dfbed2a5
commit
ecfa7f696d
3 changed files with 43 additions and 1 deletions
|
@ -250,6 +250,7 @@ def main():
|
|||
if basename:
|
||||
params['path'] = path = os.path.join(path, basename)
|
||||
b_path = to_bytes(path, errors='surrogate_or_strict')
|
||||
prev_state = get_state(b_path)
|
||||
|
||||
# make sure the target path is a directory when we're doing a recursive operation
|
||||
if recurse and state != 'directory':
|
||||
|
|
|
@ -331,7 +331,8 @@ class ActionModule(ActionBase):
|
|||
dict(
|
||||
src=source_rel,
|
||||
dest=dest,
|
||||
original_basename=source_rel
|
||||
original_basename=source_rel,
|
||||
state='file',
|
||||
)
|
||||
)
|
||||
if lmode:
|
||||
|
|
|
@ -156,6 +156,18 @@
|
|||
- "stat_results.stat.checksum == ('modified'|hash('sha1'))"
|
||||
- "stat_results.stat.mode == '0700'"
|
||||
|
||||
- name: Create a hardlink to the file
|
||||
file:
|
||||
src: '{{ remote_file }}'
|
||||
dest: '{{ output_dir }}/hard.lnk'
|
||||
state: hard
|
||||
|
||||
- name: copy the same contents into place
|
||||
copy:
|
||||
content: 'modified'
|
||||
dest: '{{ remote_file }}'
|
||||
mode: 0404
|
||||
|
||||
- name: Try invalid copy input location fails
|
||||
copy:
|
||||
src: invalid_file_location_does_not_exist
|
||||
|
@ -1072,6 +1084,34 @@
|
|||
- "stat_results.stat.checksum == ('modified'|hash('sha1'))"
|
||||
- "not stat_results.stat.islnk"
|
||||
|
||||
- name: setup directory for test
|
||||
file: state=directory dest={{remote_dir }}/directory mode=0755
|
||||
|
||||
- name: set file mode when the destination is a directory
|
||||
copy: src=foo.txt dest={{remote_dir}}/directory/ mode=0705
|
||||
|
||||
- name: set file mode when the destination is a directory
|
||||
copy: src=foo.txt dest={{remote_dir}}/directory/ mode=0604
|
||||
register: file_result
|
||||
|
||||
- name: check that the file has the correct attributes
|
||||
stat: path={{ remote_dir }}/directory/foo.txt
|
||||
register: file_attrs
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- "file_attrs.stat.uid == 0"
|
||||
- "file_attrs.stat.pw_name == 'root'"
|
||||
- "file_attrs.stat.mode == '0604'"
|
||||
|
||||
- name: check that the containing directory did not change attributes
|
||||
stat: path={{ remote_dir }}/directory/
|
||||
register: dir_attrs
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- "dir_attrs.stat.mode == '0755'"
|
||||
|
||||
#
|
||||
# I believe the below section is now covered in the recursive copying section.
|
||||
# Hold on for now as an original test case but delete once confirmed that
|
||||
|
|
Loading…
Reference in a new issue