Transform pathnames to bytes before passing on to os.path functions

pull/15204/head
Toshio Kuratomi 9 years ago committed by James Cammarata
parent 068e322610
commit 3ffb7027ad

@ -36,7 +36,7 @@ from ansible.parsing.yaml.loader import AnsibleLoader
from ansible.parsing.yaml.objects import AnsibleBaseYAMLObject, AnsibleUnicode from ansible.parsing.yaml.objects import AnsibleBaseYAMLObject, AnsibleUnicode
from ansible.module_utils.basic import is_executable from ansible.module_utils.basic import is_executable
from ansible.utils.path import unfrackpath from ansible.utils.path import unfrackpath
from ansible.utils.unicode import to_unicode from ansible.utils.unicode import to_unicode, to_bytes
class DataLoader(): class DataLoader():
@ -121,15 +121,15 @@ class DataLoader():
def path_exists(self, path): def path_exists(self, path):
path = self.path_dwim(path) path = self.path_dwim(path)
return os.path.exists(path) return os.path.exists(to_bytes(path))
def is_file(self, path): def is_file(self, path):
path = self.path_dwim(path) path = self.path_dwim(path)
return os.path.isfile(path) or path == os.devnull return os.path.isfile(to_bytes(path, errors='strict')) or path == os.devnull
def is_directory(self, path): def is_directory(self, path):
path = self.path_dwim(path) path = self.path_dwim(path)
return os.path.isdir(path) return os.path.isdir(to_bytes(path, errors='strict'))
def list_directory(self, path): def list_directory(self, path):
path = self.path_dwim(path) path = self.path_dwim(path)
@ -238,8 +238,8 @@ class DataLoader():
basedir = unfrackpath(path) basedir = unfrackpath(path)
# is it a role and if so make sure you get correct base path # is it a role and if so make sure you get correct base path
if path.endswith('tasks') and os.path.exists(os.path.join(path,'main.yml')) \ if path.endswith('tasks') and os.path.exists(to_bytes(os.path.join(path,'main.yml'), errors='strict')) \
or os.path.exists(os.path.join(path,'tasks/main.yml')): or os.path.exists(to_bytes(os.path.join(path,'tasks/main.yml'), errors='strict')):
isrole = True isrole = True
if path.endswith('tasks'): if path.endswith('tasks'):
basedir = unfrackpath(os.path.dirname(path)) basedir = unfrackpath(os.path.dirname(path))
@ -262,7 +262,7 @@ class DataLoader():
search.append(self.path_dwim(source)) search.append(self.path_dwim(source))
for candidate in search: for candidate in search:
if os.path.exists(candidate): if os.path.exists(to_bytes(candidate, errors='strict')):
break break
return candidate return candidate
@ -273,8 +273,8 @@ class DataLoader():
retrieve password from STDOUT retrieve password from STDOUT
""" """
this_path = os.path.realpath(os.path.expanduser(vault_password_file)) this_path = os.path.realpath(to_bytes(os.path.expanduser(vault_password_file), errors='strict'))
if not os.path.exists(this_path): if not os.path.exists(to_bytes(this_path, errors='strict')):
raise AnsibleFileNotFound("The vault password file %s was not found" % this_path) raise AnsibleFileNotFound("The vault password file %s was not found" % this_path)
if self.is_executable(this_path): if self.is_executable(this_path):

Loading…
Cancel
Save