mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
Fix changed=True/False detection when specifying mode=
This commit is contained in:
parent
63818000b4
commit
6874d853c9
1 changed files with 10 additions and 4 deletions
12
library/file
12
library/file
|
@ -157,15 +157,21 @@ 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):
|
||||
|
||||
st = os.stat(path)
|
||||
new_mode = stat.S_IMODE(st[stat.ST_MODE])
|
||||
|
||||
if new_mode != prev_mode:
|
||||
return True
|
||||
return changed
|
||||
|
||||
|
|
Loading…
Reference in a new issue