mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-04-24 11:21:25 -07:00
resolve inventory path on init
This allows meta refresh_inventory to work with relative paths Added option to unfrackpath to not resolv symlinks fixes #16857
This commit is contained in:
parent
28dc527b2c
commit
8217c1c39c
2 changed files with 10 additions and 6 deletions
|
@ -26,10 +26,9 @@ from ansible.module_utils._text import to_bytes, to_native, to_text
|
|||
__all__ = ['unfrackpath', 'makedirs_safe']
|
||||
|
||||
|
||||
def unfrackpath(path):
|
||||
def unfrackpath(path, follow=True):
|
||||
'''
|
||||
Returns a path that is free of symlinks, environment
|
||||
variables, relative path traversals and symbols (~)
|
||||
Returns a path that is free of symlinks (if follow=True), environment variables, relative path traversals and symbols (~)
|
||||
|
||||
:arg path: A byte or text string representing a path to be canonicalized
|
||||
:raises UnicodeDecodeError: If the canonicalized version of the path
|
||||
|
@ -41,9 +40,13 @@ def unfrackpath(path):
|
|||
example::
|
||||
'$HOME/../../var/mail' becomes '/var/spool/mail'
|
||||
'''
|
||||
canonical_path = os.path.normpath(os.path.realpath(os.path.expanduser(os.path.expandvars(to_bytes(path, errors='surrogate_or_strict')))))
|
||||
return to_text(canonical_path, errors='surrogate_or_strict')
|
||||
|
||||
if follow:
|
||||
final_path = os.path.normpath(os.path.realpath(os.path.expanduser(os.path.expandvars(to_bytes(path, errors='surrogate_or_strict')))))
|
||||
else:
|
||||
final_path = os.path.normpath(os.path.abspath(os.path.expanduser(os.path.expandvars(to_bytes(path, errors='surrogate_or_strict')))))
|
||||
|
||||
return to_text(final_path, errors='surrogate_or_strict')
|
||||
|
||||
def makedirs_safe(path, mode=None):
|
||||
'''Safe way to create dirs in muliprocess/thread environments.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue