Don't use "finally" here as it's not 2.4 compliant.

pull/2803/head
Michael DeHaan 12 years ago
parent 68f711d5ae
commit 4bea9a612f

File diff suppressed because one or more lines are too long

@ -829,20 +829,21 @@ class AnsibleModule(object):
dest_dir = os.path.dirname(dest) dest_dir = os.path.dirname(dest)
dest_file = os.path.basename(dest) dest_file = os.path.basename(dest)
tmp_dest = "%s/.%s.%s.%s" % (dest_dir,dest_file,os.getpid(),time.time()) tmp_dest = "%s/.%s.%s.%s" % (dest_dir,dest_file,os.getpid(),time.time())
def cleanup():
if os.path.exists(tmp_dest):
try:
os.unlink(tmp_dest)
except OSError, e:
sys.stderr.write("could not cleanup %s: %s" % (tmp_dest, e))
try: try:
shutil.move(src, tmp_dest) shutil.move(src, tmp_dest)
os.rename(tmp_dest, dest) os.rename(tmp_dest, dest)
rc = True rc = True
except (shutil.Error, OSError, IOError), e: except (shutil.Error, OSError, IOError), e:
cleanup()
self.fail_json(msg='Could not replace file: %s to %s: %s' % (src, dest, e)) self.fail_json(msg='Could not replace file: %s to %s: %s' % (src, dest, e))
finally:
# Clean up in case of failure (don't leave nasty temps around)
if os.path.exists(tmp_dest):
try:
#TODO: would be nice to respect 'keep_remote_files'
os.unlink(tmp_dest)
except OSError, e:
sys.stderr.write("could not cleanup %s: %s" % (tmp_dest, e))
return rc return rc
def run_command(self, args, check_rc=False, close_fds=False, executable=None, data=None): def run_command(self, args, check_rc=False, close_fds=False, executable=None, data=None):

Loading…
Cancel
Save