file module doesn't create hard link to given target directory
This commit is contained in:
parent
eaaf46a50d
commit
3b5dd4e0a0
1 changed files with 12 additions and 2 deletions
|
@ -401,10 +401,17 @@ def main():
|
||||||
changed = True
|
changed = True
|
||||||
if not force:
|
if not force:
|
||||||
module.fail_json(dest=path, src=src, msg='Cannot link, different hard link exists at destination')
|
module.fail_json(dest=path, src=src, msg='Cannot link, different hard link exists at destination')
|
||||||
elif prev_state in ('file', 'directory'):
|
elif prev_state == 'file':
|
||||||
changed = True
|
changed = True
|
||||||
if not force:
|
if not force:
|
||||||
module.fail_json(dest=path, src=src, msg='Cannot link, %s exists at destination' % prev_state)
|
module.fail_json(dest=path, src=src, msg='Cannot link, %s exists at destination' % prev_state)
|
||||||
|
elif prev_state == 'directory':
|
||||||
|
changed = True
|
||||||
|
if os.path.exists(b_path):
|
||||||
|
if state == 'hard' and os.stat(b_path).st_ino == os.stat(b_src).st_ino:
|
||||||
|
module.exit_json(path=path, changed=False)
|
||||||
|
elif not force:
|
||||||
|
module.fail_json(dest=path, src=src, msg='Cannot link, different hard link exists at destination')
|
||||||
else:
|
else:
|
||||||
module.fail_json(dest=path, src=src, msg='unexpected position reached')
|
module.fail_json(dest=path, src=src, msg='unexpected position reached')
|
||||||
|
|
||||||
|
@ -415,8 +422,11 @@ def main():
|
||||||
[os.path.dirname(b_path), to_bytes(".%s.%s.tmp" % (os.getpid(), time.time()))]
|
[os.path.dirname(b_path), to_bytes(".%s.%s.tmp" % (os.getpid(), time.time()))]
|
||||||
)
|
)
|
||||||
try:
|
try:
|
||||||
if prev_state == 'directory' and (state == 'hard' or state == 'link'):
|
if prev_state == 'directory' and state == 'link':
|
||||||
os.rmdir(b_path)
|
os.rmdir(b_path)
|
||||||
|
elif prev_state == 'directory' and state == 'hard':
|
||||||
|
if os.path.exists(b_path):
|
||||||
|
os.remove(b_path)
|
||||||
if state == 'hard':
|
if state == 'hard':
|
||||||
os.link(b_src, b_tmppath)
|
os.link(b_src, b_tmppath)
|
||||||
else:
|
else:
|
||||||
|
|
Loading…
Reference in a new issue