From 6874d853c9188eac85910a085d997cea0378e31d Mon Sep 17 00:00:00 2001 From: Michael DeHaan Date: Thu, 15 Mar 2012 22:35:59 -0400 Subject: [PATCH] Fix changed=True/False detection when specifying mode= --- library/file | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/library/file b/library/file index c9d0aaadc52..6d046a31ebd 100755 --- a/library/file +++ b/library/file @@ -157,16 +157,22 @@ def set_mode_if_different(path, mode, changed): fail_json(path=path, msg='mode needs to be something octalish', details=str(e)) st = os.stat(path) - actual_mode = stat.S_IMODE(st[stat.ST_MODE]) + prev_mode = stat.S_IMODE(st[stat.ST_MODE]) - if actual_mode != mode: + if prev_mode != mode: + # FIXME: comparison against string above will cause this to be executed + # every time try: debug('setting mode') os.chmod(path, mode) except Exception, e: fail_json(path=path, msg='chmod failed', details=str(e)) - if os.path.exists(path): - return True + + st = os.stat(path) + new_mode = stat.S_IMODE(st[stat.ST_MODE]) + + if new_mode != prev_mode: + return True return changed def rmtree_error(func, path, exc_info):