From: Maciej Tronowski Date: Wed, 2 Sep 2015 15:24:55 +0000 (+0200) Subject: fixes in handling file name with special characters X-Git-Tag: v1.1~24 X-Git-Url: http://mmka.chem.univ.gda.pl/gitweb/?a=commitdiff_plain;h=5ec84e98f89d5fe0cc67d6779861d2a0d9520cd7;p=qcg-portal.git fixes in handling file name with special characters --- diff --git a/filex/ftp.py b/filex/ftp.py index 3ccd8c6..85161a4 100644 --- a/filex/ftp.py +++ b/filex/ftp.py @@ -6,7 +6,7 @@ import re from threading import Event from urlparse import urlparse, urlunparse -from django.utils.http import urlunquote +from django.utils.http import urlquote from django.utils.timezone import localtime, UTC @@ -190,15 +190,22 @@ class FTPOperation: self._check_disk_stack_args(*([path, archive] + files)) if self.match_ext(archive, '.tar.gz', '.tgz'): - cmd, args = 'tar', ['cvzf', archive, '-C', path] + files + cmd, args = 'tar', ['czf', archive, '-C', path] + files elif self.match_ext(archive, '.tar.bz2', '.tbz'): - cmd, args = 'tar', ['cvjf', archive, '-C', path] + files + cmd, args = 'tar', ['cjf', archive, '-C', path] + files elif self.match_ext(archive, '.zip'): - cmd, args = 'jar', (['cvMf', archive] + list(chain.from_iterable(('-C', path, f) for f in files))) + # zip doesn't support unicode file names + for arg in files: + try: + arg.encode('ascii') + except UnicodeEncodeError as e: + raise ValueError(u'Unsupported character `{}` in `{}`!'.format(arg[e.start:e.start + 1], arg)) + + cmd, args = 'jar', (['cMf', archive] + list(chain.from_iterable(('-C', path, f) for f in files))) else: raise ValueError('Unknown archive type: {}'.format(archive)) - self.op_attr.set_disk_stack('#'.join(["popen:argv=", cmd] + args)) + self.op_attr.set_disk_stack('#'.join(["popen:argv=", cmd] + map(urlquote, args))) return self.get(server) @@ -206,21 +213,21 @@ class FTPOperation: self._check_disk_stack_args(*[archive, dst]) if self.match_ext(archive, '.tar.gz', '.tgz'): - cmd, args = 'tar', ('xvzf', archive, '-C', dst) + cmd, args = 'tar', ('xzf', archive, '-C', dst) elif self.match_ext(archive, '.tar.bz2', '.tbz'): - cmd, args = 'tar', ('xvjf', archive, '-C', dst) + cmd, args = 'tar', ('xjf', archive, '-C', dst) elif self.match_ext(archive, '.zip'): - cmd, args = 'unzip', (archive, '-d', dst) + cmd, args = 'unzip', ('-qo', archive, '-d', dst) else: raise ValueError('Unknown archive type: {}'.format(archive)) - self.op_attr.set_disk_stack('#'.join(("popen:argv=", cmd) + args)) + self.op_attr.set_disk_stack('#'.join(["popen:argv=", cmd] + map(urlquote, args))) return self.get(server) @staticmethod def _check_disk_stack_args(*args): - for char in ['#', ',', ';', '%23', '%3B']: + for char in ['#', ';']: for arg in args: if char in arg: - raise ValueError('Unsupported character `{}` in `{}`!'.format(urlunquote(char), urlunquote(arg))) + raise ValueError(u'Unsupported character `{}` in `{}`!'.format(char, arg))