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
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)
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))