From: Varsha Rao Date: Mon, 10 Jun 2019 13:33:53 +0000 (+0530) Subject: cephfs-shell: Fix 'lls' command errors X-Git-Tag: v15.1.0~2476^2 X-Git-Url: http://git.apps.os.sepia.ceph.com/?a=commitdiff_plain;h=d1ddd4c50f56331c7036964f78d4e399e10431b8;p=ceph-ci.git cephfs-shell: Fix 'lls' command errors 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 --- diff --git a/src/tools/cephfs/cephfs-shell b/src/tools/cephfs/cephfs-shell index 67f2d9c1616..4974c169ba3 100755 --- a/src/tools/cephfs/cephfs-shell +++ b/src/tools/cephfs/cephfs-shell @@ -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