Accounting for when files in an archive contain non-ascii characters

This commit is contained in:
Gareth J. Greenaway 2018-05-09 09:33:58 -07:00
parent cb04d9c37e
commit 5a9cadd125
No known key found for this signature in database
GPG key ID: 10B62F8A7CAD7A41
2 changed files with 19 additions and 8 deletions

View file

@ -413,12 +413,20 @@ def list_(name,
ret = {'dirs': sorted(dirs),
'files': sorted(files),
'links': sorted(links)}
ret['top_level_dirs'] = [x for x in ret['dirs']
if x.count('/') == 1]
ret['top_level_files'] = [x for x in ret['files']
if x.count('/') == 0]
ret['top_level_links'] = [x for x in ret['links']
if x.count('/') == 0]
if six.PY2:
ret['top_level_dirs'] = [x for x in ret['dirs']
if x.decode('utf-8').count('/') == 1]
ret['top_level_files'] = [x for x in ret['files']
if x.decode('utf-8').count('/') == 0]
ret['top_level_links'] = [x for x in ret['links']
if x.decode('utf-8').count('/') == 0]
else:
ret['top_level_dirs'] = [x for x in ret['dirs']
if x.count('/') == 1]
ret['top_level_files'] = [x for x in ret['files']
if x.count('/') == 0]
ret['top_level_links'] = [x for x in ret['links']
if x.count('/') == 0]
else:
ret = sorted(dirs + files + links)
return ret

View file

@ -1090,7 +1090,10 @@ def extracted(name,
and not stat.S_ISDIR(x)),
(contents['links'], stat.S_ISLNK)):
for path in path_list:
full_path = os.path.join(name, path)
if six.PY2:
full_path = os.path.join(name, path.decode('utf-8'))
else:
full_path = os.path.join(name, path)
try:
path_mode = os.lstat(full_path.rstrip(os.sep)).st_mode
if not func(path_mode):
@ -1259,7 +1262,7 @@ def extracted(name,
if options is None:
try:
with closing(tarfile.open(cached, 'r')) as tar:
tar.extractall(name)
tar.extractall(salt.utils.to_bytes(name))
files = tar.getnames()
if trim_output:
files = files[:trim_output]