mirror of
https://github.com/saltstack/salt.git
synced 2025-04-17 10:10:20 +00:00
Merge pull request #47572 from garethgreenaway/47546_archive_non_ascii_filenames
[2018.3] archive module, filenames with Unicode characters
This commit is contained in:
commit
69056e5b67
3 changed files with 40 additions and 7 deletions
|
@ -410,9 +410,9 @@ def list_(name,
|
|||
item.sort()
|
||||
|
||||
if verbose:
|
||||
ret = {'dirs': sorted(dirs),
|
||||
'files': sorted(files),
|
||||
'links': sorted(links)}
|
||||
ret = {'dirs': sorted(salt.utils.data.decode_list(dirs)),
|
||||
'files': sorted(salt.utils.data.decode_list(files)),
|
||||
'links': sorted(salt.utils.data.decode_list(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']
|
||||
|
|
|
@ -1090,7 +1090,7 @@ 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)
|
||||
full_path = salt.utils.path.join(name, path)
|
||||
try:
|
||||
path_mode = os.lstat(full_path.rstrip(os.sep)).st_mode
|
||||
if not func(path_mode):
|
||||
|
@ -1259,7 +1259,7 @@ def extracted(name,
|
|||
if options is None:
|
||||
try:
|
||||
with closing(tarfile.open(cached, 'r')) as tar:
|
||||
tar.extractall(name)
|
||||
tar.extractall(salt.utils.stringutils.to_str(name))
|
||||
files = tar.getnames()
|
||||
if trim_output:
|
||||
files = files[:trim_output]
|
||||
|
|
|
@ -47,7 +47,7 @@ class ArchiveTest(ModuleCase):
|
|||
self.arch = os.path.join(self.base_path, 'archive.{0}'.format(arch_fmt))
|
||||
self.dst = os.path.join(self.base_path, '{0}_dst_dir'.format(arch_fmt))
|
||||
|
||||
def _set_up(self, arch_fmt):
|
||||
def _set_up(self, arch_fmt, unicode_filename=False):
|
||||
'''
|
||||
Create source file tree and destination directory
|
||||
|
||||
|
@ -62,7 +62,11 @@ class ArchiveTest(ModuleCase):
|
|||
|
||||
# Create source
|
||||
os.makedirs(self.src)
|
||||
with salt.utils.files.fopen(os.path.join(self.src, 'file'), 'w') as theorem:
|
||||
if unicode_filename:
|
||||
filename = 'file®'
|
||||
else:
|
||||
filename = 'file'
|
||||
with salt.utils.files.fopen(os.path.join(self.src, filename), 'w') as theorem:
|
||||
theorem.write(textwrap.dedent(salt.utils.stringutils.to_str(r'''\
|
||||
Compression theorem of computational complexity theory:
|
||||
|
||||
|
@ -150,6 +154,35 @@ class ArchiveTest(ModuleCase):
|
|||
|
||||
self._tear_down()
|
||||
|
||||
@skipIf(not salt.utils.path.which('tar'), 'Cannot find tar executable')
|
||||
def test_tar_pack_unicode(self):
|
||||
'''
|
||||
Validate using the tar function to create archives
|
||||
'''
|
||||
self._set_up(arch_fmt='tar', unicode_filename=True)
|
||||
|
||||
# Test create archive
|
||||
ret = self.run_function('archive.tar', ['-cvf', self.arch], sources=self.src)
|
||||
self.assertTrue(isinstance(ret, list), six.text_type(ret))
|
||||
self._assert_artifacts_in_ret(ret)
|
||||
|
||||
self._tear_down()
|
||||
|
||||
@skipIf(not salt.utils.path.which('tar'), 'Cannot find tar executable')
|
||||
def test_tar_unpack_unicode(self):
|
||||
'''
|
||||
Validate using the tar function to extract archives
|
||||
'''
|
||||
self._set_up(arch_fmt='tar', unicode_filename=True)
|
||||
self.run_function('archive.tar', ['-cvf', self.arch], sources=self.src)
|
||||
|
||||
# Test extract archive
|
||||
ret = self.run_function('archive.tar', ['-xvf', self.arch], dest=self.dst)
|
||||
self.assertTrue(isinstance(ret, list), six.text_type(ret))
|
||||
self._assert_artifacts_in_ret(ret)
|
||||
|
||||
self._tear_down()
|
||||
|
||||
@skipIf(not salt.utils.path.which('gzip'), 'Cannot find gzip executable')
|
||||
def test_gzip(self):
|
||||
'''
|
||||
|
|
Loading…
Add table
Reference in a new issue