mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-04-28 13:21:25 -07:00
simplified unsafe writes
This commit is contained in:
parent
727ca6f436
commit
8c5d321a23
1 changed files with 15 additions and 19 deletions
|
@ -2091,8 +2091,8 @@ class AnsibleModule(object):
|
||||||
os.rename(b_tmp_dest_name, b_dest)
|
os.rename(b_tmp_dest_name, b_dest)
|
||||||
except (shutil.Error, OSError, IOError):
|
except (shutil.Error, OSError, IOError):
|
||||||
e = get_exception()
|
e = get_exception()
|
||||||
if unsafe_writes:
|
if unsafe_writes and e.errno == errno.EBUSY:
|
||||||
self._unsafe_writes(b_tmp_dest_name, b_dest, e)
|
self._unsafe_writes(b_tmp_dest_name, b_dest)
|
||||||
else:
|
else:
|
||||||
self.fail_json(msg='Unable to rename file: %s to %s: %s' % (src, dest, e))
|
self.fail_json(msg='Unable to rename file: %s to %s: %s' % (src, dest, e))
|
||||||
except (shutil.Error, OSError, IOError):
|
except (shutil.Error, OSError, IOError):
|
||||||
|
@ -2114,11 +2114,9 @@ class AnsibleModule(object):
|
||||||
# rename might not preserve context
|
# rename might not preserve context
|
||||||
self.set_context_if_different(dest, context, False)
|
self.set_context_if_different(dest, context, False)
|
||||||
|
|
||||||
def _unsafe_writes(self, src, dest, exception):
|
def _unsafe_writes(self, src, dest):
|
||||||
# sadly there are some situations where we cannot ensure atomicity, but only if
|
# sadly there are some situations where we cannot ensure atomicity, but only if
|
||||||
# the user insists and we get the appropriate error we update the file unsafely
|
# the user insists and we get the appropriate error we update the file unsafely
|
||||||
if exception.errno == errno.EBUSY:
|
|
||||||
#TODO: issue warning that this is an unsafe operation, but doing it cause user insists
|
|
||||||
try:
|
try:
|
||||||
try:
|
try:
|
||||||
out_dest = open(dest, 'wb')
|
out_dest = open(dest, 'wb')
|
||||||
|
@ -2133,8 +2131,6 @@ class AnsibleModule(object):
|
||||||
e = get_exception()
|
e = get_exception()
|
||||||
self.fail_json(msg='Could not write data to file (%s) from (%s): %s' % (dest, src, e))
|
self.fail_json(msg='Could not write data to file (%s) from (%s): %s' % (dest, src, e))
|
||||||
|
|
||||||
else:
|
|
||||||
self.fail_json(msg='Could not replace file: %s to %s: %s' % (src, dest, exception))
|
|
||||||
|
|
||||||
def _read_from_pipes(self, rpipes, rfds, file_descriptor):
|
def _read_from_pipes(self, rpipes, rfds, file_descriptor):
|
||||||
data = b('')
|
data = b('')
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue