From 035d465d72a4eaee93a1c72846e37001fff7c41b Mon Sep 17 00:00:00 2001 From: Varsha Rao Date: Thu, 25 Feb 2021 16:48:00 +0530 Subject: [PATCH] tools/cephfs-shell: continue file listing even on error Fixes: https://tracker.ceph.com/issues/48912 Signed-off-by: Varsha Rao (cherry picked from commit 64c066410a808e80a9562aa353bcf4596f78bf37) --- src/tools/cephfs/cephfs-shell | 110 ++++++++++++++++++---------------- 1 file changed, 57 insertions(+), 53 deletions(-) diff --git a/src/tools/cephfs/cephfs-shell b/src/tools/cephfs/cephfs-shell index 8f21dcd241e35..4c88cb8cd71ba 100755 --- a/src/tools/cephfs/cephfs-shell +++ b/src/tools/cephfs/cephfs-shell @@ -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): """ -- 2.39.5