mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-05-31 13:29:08 -07:00
Refuse to convert a non-empty directory into a link with the file module
Also adds an integration test for the above. Fixes #7254
This commit is contained in:
parent
deb532c367
commit
b753625dbf
2 changed files with 51 additions and 3 deletions
|
@ -192,8 +192,13 @@ def main():
|
|||
if state == 'hard':
|
||||
if not os.path.isabs(src):
|
||||
module.fail_json(msg="absolute paths are required")
|
||||
|
||||
elif prev_state in ['file', 'hard', 'directory'] and not force:
|
||||
elif prev_state == 'directory':
|
||||
if not force:
|
||||
module.fail_json(path=path, msg='refusing to convert between %s and %s for %s' % (prev_state, state, src))
|
||||
elif len(os.listdir(path)) > 0:
|
||||
# refuse to replace a directory that has files in it
|
||||
module.fail_json(path=path, msg='the directory %s is not empty, refusing to convert it' % path)
|
||||
elif prev_state in ['file', 'hard'] and not force:
|
||||
module.fail_json(path=path, msg='refusing to convert between %s and %s for %s' % (prev_state, state, src))
|
||||
|
||||
if prev_state == 'absent':
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue