copy, fix permissions and atime on diff partitions (#83824)

we just set time also, when on diff partitions
pull/83865/head
Brian Coca 3 months ago committed by GitHub
parent faf446a895
commit 2a676ff897
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -0,0 +1,2 @@
bugfixes:
- module_utils atomic_move (used by most file based modules), now correctly handles permission copy and setting mtime correctly across all paths

@ -1557,7 +1557,7 @@ class AnsibleModule(object):
# Similar to shutil.copy(), but metadata is copied as well - in fact, # Similar to shutil.copy(), but metadata is copied as well - in fact,
# this is just shutil.copy() followed by copystat(). This is similar # this is just shutil.copy() followed by copystat(). This is similar
# to the Unix command cp -p. # to the Unix command cp -p.
#
# shutil.copystat(src, dst) # shutil.copystat(src, dst)
# Copy the permission bits, last access time, last modification time, # Copy the permission bits, last access time, last modification time,
# and flags from src to dst. The file contents, owner, and group are # and flags from src to dst. The file contents, owner, and group are
@ -1660,8 +1660,10 @@ class AnsibleModule(object):
b_tmp_dest_name, context, False) b_tmp_dest_name, context, False)
try: try:
tmp_stat = os.stat(b_tmp_dest_name) tmp_stat = os.stat(b_tmp_dest_name)
if keep_dest_attrs and dest_stat and (tmp_stat.st_uid != dest_stat.st_uid or tmp_stat.st_gid != dest_stat.st_gid): 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):
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)
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:
raise raise

@ -2490,3 +2490,45 @@
state: absent state: absent
loop: loop:
- '{{ remote_file }}' - '{{ remote_file }}'
- name: Verify atime and mtime update on content change (diff partition)
vars:
remote_file: "/var/tmp/foo.txt"
ansible_remote_tmp: "/tmp"
block:
- name: Create a dest file
shell: "echo Test content > {{ remote_file }}"
register: create_dest_result
- name: Check the stat results of the file before copying
stat:
path: "{{ remote_file }}"
register: stat_results_before_copy
- name: Overwrite the file using the content system
copy:
content: "modified"
dest: "{{ remote_file }}"
decrypt: no
register: copy_result
- name: Check the stat results of the file after copying
stat:
path: "{{ remote_file }}"
register: stat_results_after_copy
- name: Assert that the file has changed
assert:
that:
- "create_dest_result is changed"
- "copy_result is changed"
- "'content' not in copy_result"
- "stat_results_before_copy.stat.atime < stat_results_after_copy.stat.atime"
- "stat_results_before_copy.stat.mtime < stat_results_after_copy.stat.mtime"
always:
- name: clean up dest file
file:
path: '{{ item }}'
state: absent
loop:
- '{{ remote_file }}'

Loading…
Cancel
Save