From e157355fd6d26f7e66e32f417c8108ce7a7794b6 Mon Sep 17 00:00:00 2001 From: Steve Smith Date: Thu, 20 Mar 2014 13:14:24 +0100 Subject: [PATCH] Only unlink the symlink tempfile on error if it was created in the previous operation. --- library/files/file | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/library/files/file b/library/files/file index b1c57ff4d9..710a9224c1 100644 --- a/library/files/file +++ b/library/files/file @@ -305,7 +305,8 @@ def main(): os.symlink(src, tmppath) os.rename(tmppath, path) except OSError, e: - os.unlink(tmppath) + if os.path.exists(tmppath): + os.unlink(tmppath) module.fail_json(path=path, msg='Error while replacing: %s' % str(e)) try: if state == 'hard':