Fix python3 and nonascii handling in inventory plugins

Fixes #30663
This commit is contained in:
Toshio Kuratomi 2017-09-20 17:01:07 -07:00
parent f12c6e0946
commit 72bdf7aa7e
6 changed files with 41 additions and 41 deletions

View file

@ -60,18 +60,18 @@ class BaseInventoryPlugin(object):
def verify_file(self, path):
''' Verify if file is usable by this plugin, base does minimal accessability check '''
b_path = to_bytes(path)
b_path = to_bytes(path, errors='surrogate_or_strict')
return (os.path.exists(b_path) and os.access(b_path, os.R_OK))
def get_cache_prefix(self, path):
''' create predictable unique prefix for plugin/inventory '''
m = hashlib.sha1()
m.update(to_bytes(self.NAME))
m.update(to_bytes(self.NAME, errors='surrogate_or_strict'))
d1 = m.hexdigest()
n = hashlib.sha1()
n.update(to_bytes(path))
n.update(to_bytes(path, errors='surrogate_or_strict'))
d2 = n.hexdigest()
return 's_'.join([d1[:5], d2[:5]])