mirror of
https://github.com/ansible-collections/community.general.git
synced 2026-05-06 21:32:49 +00:00
Fix for atomic_replace patch if file does not yet exist
This commit is contained in:
@@ -596,19 +596,19 @@ class AnsibleModule(object):
|
||||
|
||||
def atomic_replace(self, src, dest):
|
||||
'''atomically replace dest with src, copying attributes from dest'''
|
||||
st = os.stat(dest)
|
||||
os.chmod(src, st.st_mode & 07777)
|
||||
try:
|
||||
os.chown(src, st.st_uid, st.st_gid)
|
||||
except OSError, e:
|
||||
if e.errno != errno.EPERM:
|
||||
raise
|
||||
if self.selinux_enabled():
|
||||
context = self.selinux_context(dest)
|
||||
self.set_context_if_different(src, context, False)
|
||||
if os.path.exists(dest):
|
||||
st = os.stat(dest)
|
||||
os.chmod(src, st.st_mode & 07777)
|
||||
try:
|
||||
os.chown(src, st.st_uid, st.st_gid)
|
||||
except OSError, e:
|
||||
if e.errno != errno.EPERM:
|
||||
raise
|
||||
if self.selinux_enabled():
|
||||
context = self.selinux_context(dest)
|
||||
self.set_context_if_different(src, context, False)
|
||||
os.rename(src, dest)
|
||||
|
||||
|
||||
# == END DYNAMICALLY INSERTED CODE ===
|
||||
|
||||
"""
|
||||
|
||||
Reference in New Issue
Block a user