1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2024-09-14 20:13:21 +02:00

Fix symlink handling (#26877)

* Fix symlink handling

On symlinks, make lnk_source return the absolute path of the target of the symlink.
Add a new return field lnk_target that returns the actual, unexpanded path to the target of the symlink.
This commit is contained in:
Toshio Kuratomi 2017-07-17 12:06:35 -07:00 committed by GitHub
parent 66f5a094bc
commit 84fb9f032d

View file

@ -292,10 +292,16 @@ stat:
type: boolean type: boolean
sample: False sample: False
lnk_source: lnk_source:
description: Original path description: Target of the symlink normalized for the remote filesystem
returned: success, path exists and user can read stats and the path is a symbolic link returned: success, path exists and user can read stats and the path is a symbolic link
type: string type: string
sample: /home/foobar/21102015-1445431274-908472971 sample: /home/foobar/21102015-1445431274-908472971
lnk_target:
description: Target of the symlink. Note that relative paths remain relative
returned: success, path exists and user can read stats and the path is a symbolic link
type: string
sample: ../foobar/21102015-1445431274-908472971
version_added: 2.4
md5: md5:
description: md5 hash of the path description: md5 hash of the path
returned: success, path exists and user can read stats and path returned: success, path exists and user can read stats and path
@ -481,6 +487,7 @@ def main():
# symlink info # symlink info
if output.get('islnk'): if output.get('islnk'):
output['lnk_source'] = os.path.realpath(b_path) output['lnk_source'] = os.path.realpath(b_path)
output['lnk_target'] = os.readlink(b_path)
try: # user data try: # user data
pw = pwd.getpwuid(st.st_uid) pw = pwd.getpwuid(st.st_uid)