Make download overwrite more intuitive
authorStavros Sachtouris <saxtouri@admin.grnet.gr>
Tue, 17 Dec 2013 15:45:14 +0000 (17:45 +0200)
committerStavros Sachtouris <saxtouri@admin.grnet.gr>
Tue, 17 Dec 2013 15:45:48 +0000 (17:45 +0200)
kamaki/cli/commands/errors.py
kamaki/cli/commands/pithos.py

index 2ff6d82..911d4d2 100644 (file)
@@ -516,7 +516,7 @@ class pithos(object):
             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',
index 763decc..4da6c80 100644 (file)
@@ -1206,11 +1206,29 @@ class file_download(_pithos_container):
                             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: