]> git.apps.os.sepia.ceph.com Git - ceph-ci.git/commitdiff
cephfs-shell: Fix 'lls' command errors
authorVarsha Rao <varao@redhat.com>
Mon, 10 Jun 2019 13:33:53 +0000 (19:03 +0530)
committerVarsha Rao <varao@redhat.com>
Mon, 10 Jun 2019 14:58:48 +0000 (20:28 +0530)
This patch fixes following:
* Not printing complete path when '..' is passed as argument.
* Printing of path for current working directory.
* No need to set default value for add_argument. As it returns empty list with
  nargs='*'.
* No need to check for absolute path. os.listdir takes both relative and
  absolute path.
* Use try-catch instead of if-else statement to catch exceptions.

Fixes: http://tracker.ceph.com/issues/40244
Signed-off-by: Varsha Rao <varao@redhat.com>
src/tools/cephfs/cephfs-shell

index 67f2d9c1616e9e4aae87a280388b0b36a3d70179..4974c169ba370355c50d91f75b0e9f4da033e1e0 100755 (executable)
@@ -1024,28 +1024,23 @@ sub-directories, files')
 
     lls_parser = argparse.ArgumentParser(
         description='List files in local system.')
-    lls_parser.add_argument('paths', help='Paths', nargs='*', default=[''])
+    lls_parser.add_argument('paths', help='Paths', nargs='*')
 
     @with_argparser(lls_parser)
     def do_lls(self, args):
         """
         Lists all files and folders in the current local directory
         """
-
-        if len(args.paths) == 0 or (len(args.paths) == 1 and
-                                    args.paths[0] == ''):
-            if len(args.paths) > 0:
-                args.paths.pop(0)
-            args.paths.append(os.getcwd())
-        for path in args.paths:
-            if not os.path.isabs(path):
-                path = os.path.relpath(path)
-            if os.path.isdir(path):
-                self.poutput("%s:" % path)
-                items = os.listdir(path)
-                print_list(items)
-            else:
-                self.poutput("%s: no such directory" % path)
+        if not args.paths:
+            print_list(os.listdir(os.getcwd()))
+        else:
+            for path in args.paths:
+                try:
+                    items = os.listdir(path)
+                    self.poutput("{}:".format(path))
+                    print_list(items)
+                except OSError as e:
+                    self.perror("'{}': {}".format(e.filename, e.strerror), False)
         # Arguments to the with_argpaser decorator function are sticky.
         # The items in args.path do not get overwritten in subsequent calls.
         # The arguments remain in args.paths after the function exits and we