Fix copying the dest attributes when using a tmp file

pull/83986/head
s-hertel 1 year ago
parent bf8da52aac
commit 024fe1c67d

@ -1663,6 +1663,8 @@ class AnsibleModule(object):
if keep_dest_attrs: if keep_dest_attrs:
if dest_stat and (tmp_stat.st_uid != dest_stat.st_uid or tmp_stat.st_gid != dest_stat.st_gid): if dest_stat and (tmp_stat.st_uid != dest_stat.st_uid or tmp_stat.st_gid != dest_stat.st_gid):
os.chown(b_tmp_dest_name, dest_stat.st_uid, dest_stat.st_gid) os.chown(b_tmp_dest_name, dest_stat.st_uid, dest_stat.st_gid)
if dest_stat:
shutil.copystat(b_dest, b_tmp_dest_name)
os.utime(b_tmp_dest_name, times=(time.time(), time.time())) os.utime(b_tmp_dest_name, times=(time.time(), time.time()))
except OSError as e: except OSError as e:
if e.errno != errno.EPERM: if e.errno != errno.EPERM:

@ -29,6 +29,21 @@
- "'group::r--' in acls.stdout_lines" - "'group::r--' in acls.stdout_lines"
- "'other::r--' in acls.stdout_lines" - "'other::r--' in acls.stdout_lines"
- name: Update the mode
command: chmod 664 /home/{{ remote_unprivileged_user }}/test.txt
become: yes
- name: Test updating the content preserves the mode
copy:
content: "UPDATE"
dest: "~/test.txt"
register: copy_update
become: yes
become_user: "{{ remote_unprivileged_user }}"
- assert:
that: copy_update.mode == "0664"
always: always:
- name: Clean up - name: Clean up
file: file:

Loading…
Cancel
Save