]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
tools/cephfs-shell: continue file listing even on error 40308/head
authorVarsha Rao <varao@redhat.com>
Thu, 25 Feb 2021 11:18:00 +0000 (16:48 +0530)
committerVarsha Rao <varao@redhat.com>
Mon, 22 Mar 2021 12:40:55 +0000 (18:10 +0530)
Fixes: https://tracker.ceph.com/issues/48912
Signed-off-by: Varsha Rao <varao@redhat.com>
(cherry picked from commit 64c066410a808e80a9562aa353bcf4596f78bf37)

src/tools/cephfs/cephfs-shell

index 8f21dcd241e355ef65ed27fca9fb6645cb0b1470..4c88cb8cd71ba8cf3dfece92d6a167eeff8721a0 100755 (executable)
@@ -801,60 +801,64 @@ class CephFSShell(Cmd):
         for path in paths:
             values = []
             items = []
-            if path.count(b'*') > 0:
-                all_items = get_all_possible_paths(path)
-                if len(all_items) == 0:
-                    continue
-                path = all_items[0].rsplit(b'/', 1)[0]
-                if path == b'':
-                    path = b'/'
-                dirs = []
-                for i in all_items:
-                    for item in ls(path):
-                        d_name = item.d_name
-                        if os.path.basename(i) == d_name:
-                            if item.is_dir():
-                                dirs.append(os.path.join(path, d_name))
-                            else:
-                                items.append(item)
-                if dirs:
-                    paths.extend(dirs)
-                else:
-                    poutput(path.decode('utf-8'), end=':\n')
-                items = sorted(items, key=lambda item: item.d_name)
-            else:
-                if path != b'' and path != cephfs.getcwd() and len(paths) > 1:
-                    poutput(path.decode('utf-8'), end=':\n')
-                items = sorted(ls(path),
-                               key=lambda item: item.d_name)
-            if not args.all:
-                items = [i for i in items if not i.d_name.startswith(b'.')]
-
-            if args.S:
-                items = sorted(items, key=lambda item: cephfs.stat(
-                    path + b'/' + item.d_name, follow_symlink=(not item.is_symbol_file())).st_size)
-
-            if args.reverse:
-                items = reversed(items)
-            for item in items:
-                filepath = item.d_name
-                is_dir = item.is_dir()
-                is_sym_lnk = item.is_symbol_file()
-
-                if args.long and args.H:
-                    print_long(os.path.join(cephfs.getcwd(), path, filepath),
-                               is_dir, is_sym_lnk, True)
-                elif args.long:
-                    print_long(os.path.join(cephfs.getcwd(), path, filepath),
-                               is_dir, is_sym_lnk, False)
-                elif is_sym_lnk or is_dir:
-                    values.append(style_listing(filepath.decode('utf-8'), is_dir, is_sym_lnk))
+            try:
+                if path.count(b'*') > 0:
+                    all_items = get_all_possible_paths(path)
+                    if len(all_items) == 0:
+                        continue
+                    path = all_items[0].rsplit(b'/', 1)[0]
+                    if path == b'':
+                        path = b'/'
+                    dirs = []
+                    for i in all_items:
+                        for item in ls(path):
+                            d_name = item.d_name
+                            if os.path.basename(i) == d_name:
+                                if item.is_dir():
+                                    dirs.append(os.path.join(path, d_name))
+                                else:
+                                    items.append(item)
+                    if dirs:
+                        paths.extend(dirs)
+                    else:
+                        poutput(path.decode('utf-8'), end=':\n')
+                    items = sorted(items, key=lambda item: item.d_name)
                 else:
-                    values.append(filepath)
-            if not args.long:
-                print_list(values, shutil.get_terminal_size().columns)
-                if path != paths[-1]:
-                    poutput('')
+                    if path != b'' and path != cephfs.getcwd() and len(paths) > 1:
+                        poutput(path.decode('utf-8'), end=':\n')
+                    items = sorted(ls(path), key=lambda item: item.d_name)
+                if not args.all:
+                    items = [i for i in items if not i.d_name.startswith(b'.')]
+                if args.S:
+                    items = sorted(items, key=lambda item: cephfs.stat(
+                        path + b'/' + item.d_name, follow_symlink=(
+                            not item.is_symbol_file())).st_size)
+                if args.reverse:
+                    items = reversed(items)
+                for item in items:
+                    filepath = item.d_name
+                    is_dir = item.is_dir()
+                    is_sym_lnk = item.is_symbol_file()
+                    try:
+                        if args.long and args.H:
+                            print_long(os.path.join(cephfs.getcwd(), path, filepath), is_dir,
+                                       is_sym_lnk, True)
+                        elif args.long:
+                            print_long(os.path.join(cephfs.getcwd(), path, filepath), is_dir,
+                                       is_sym_lnk, False)
+                        elif is_sym_lnk or is_dir:
+                            values.append(style_listing(filepath.decode('utf-8'), is_dir,
+                                          is_sym_lnk))
+                        else:
+                            values.append(filepath)
+                    except libcephfs.Error as e:
+                        set_exit_code_msg(msg=e)
+                if not args.long:
+                    print_list(values, shutil.get_terminal_size().columns)
+                    if path != paths[-1]:
+                        poutput('')
+            except libcephfs.Error as e:
+                set_exit_code_msg(msg=e)
 
     def complete_rmdir(self, text, line, begidx, endidx):
         """