From 3404fb45940392fc15f48f65675228ccbff2a29e Mon Sep 17 00:00:00 2001 From: Matthew Williams Date: Sun, 1 Apr 2012 16:44:08 -0700 Subject: [PATCH] protecting against replacing file or directory with link --- file | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/file b/file index f5b7e6f071d..6e44ebe2044 100755 --- a/file +++ b/file @@ -243,7 +243,7 @@ elif state == 'directory': # set modes owners and context as needed changed = set_context_if_different(path, secontext, changed) changed = set_owner_if_different(path, owner, changed) - changed = set_group_if_different(path, owner, changed) + changed = set_group_if_different(path, group, changed) changed = set_mode_if_different(path, mode, changed) exit_json(path=path, changed=changed) @@ -260,18 +260,20 @@ elif state == 'link': if prev_state == 'absent': os.symlink(src, dest) changed = True - else: + elif prev_state == 'link': old_src = os.readlink(dest) if not os.path.isabs(old_src): old_src = os.path.join(os.path.dirname(dest), old_src) if old_src != src: os.unlink(dest) os.symlink(src, dest) + else: + fail_json(dest=dest, src=src, msg='unexpected position reached') # set modes owners and context as needed changed = set_context_if_different(dest, secontext, changed) changed = set_owner_if_different(dest, owner, changed) - changed = set_group_if_different(dest, owner, changed) + changed = set_group_if_different(dest, group, changed) changed = set_mode_if_different(dest, mode, changed) exit_json(dest=dest, src=src, changed=changed)