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

This commit is contained in:
Michael DeHaan 2013-04-28 16:03:03 -04:00
parent 68f711d5ae
commit 4bea9a612f
2 changed files with 10 additions and 9 deletions

File diff suppressed because one or more lines are too long

View file

@ -829,20 +829,21 @@ class AnsibleModule(object):
dest_dir = os.path.dirname(dest)
dest_file = os.path.basename(dest)
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:
shutil.move(src, tmp_dest)
os.rename(tmp_dest, dest)
rc = True
except (shutil.Error, OSError, IOError), e:
cleanup()
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
def run_command(self, args, check_rc=False, close_fds=False, executable=None, data=None):