module_utils: ensure find_mount_point consistently returns text (#73625) (#73710)

(cherry picked from commit dabfee4d5c)
This commit is contained in:
Brian Coca 2021-03-08 05:52:54 -05:00 committed by GitHub
parent 65037d4781
commit a1a57c699e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 8 additions and 6 deletions

View file

@ -0,0 +1,2 @@
bugfixes:
- ensure find_mount_point consistently returns text.

View file

@ -955,17 +955,17 @@ class AnsibleModule(object):
return (uid, gid)
def find_mount_point(self, path):
path_is_bytes = False
if isinstance(path, binary_type):
path_is_bytes = True
'''
Takes a path and returns it's mount point
:param path: a string type with a filesystem path
:returns: the path to the mount point as a text type
'''
b_path = os.path.realpath(to_bytes(os.path.expanduser(os.path.expandvars(path)), errors='surrogate_or_strict'))
while not os.path.ismount(b_path):
b_path = os.path.dirname(b_path)
if path_is_bytes:
return b_path
return to_text(b_path, errors='surrogate_or_strict')
def is_special_selinux_path(self, path):