try:
return func(self, *args, **kwargs)
except IOError as ioe:
- msg = 'Failed to access a file',
+ msg = 'Failed to access a local file',
raiseCLIError(ioe, msg, importance=2, details=[
'Check if the file exists. Also check if the remote',
'directories exist. All directories in a remote path',
parsed_name, self.container)])
else:
# Remote object is just a file
- if path.exists(local_path) and not self['resume']:
- raise CLIError(
- 'Cannot overwrite local file %s' % (local_path),
- details=['To overwrite/resume, use %s' % (
- self.arguments['resume'].lvalue)])
+ if path.exists(local_path):
+ if not self['resume']:
+ raise CLIError(
+ 'Cannot overwrite local file %s' % (local_path),
+ details=['To overwrite/resume, use %s' % (
+ self.arguments['resume'].lvalue)])
+ elif '/' in local_path[1:-1]:
+ dirs = [p for p in local_path.split('/') if p]
+ pref = '/' if local_path.startswith('/') else ''
+ for d in dirs[:-1]:
+ pref += d
+ if not path.exists(pref):
+ ret.append((None, d, None))
+ elif not path.isdir(pref):
+ raise CLIError(
+ 'Failed to use %s as a destination' % local_path,
+ importance=3,
+ details=[
+ 'Local file %s is not a directory' % pref,
+ 'Destination prefix must consist of '
+ 'directories or non-existing names',
+ 'Either remove the file, or choose another '
+ 'destination'])
ret.append((rpath, local_path, self['resume']))
for r, l, resume in ret:
if r: