From: Varsha Rao Date: Wed, 24 Feb 2021 11:29:21 +0000 (+0530) Subject: tools/cephfs-shell: fix listing of symbolic links X-Git-Tag: v16.2.0~15^2~2 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=704e3f7177ac39c7ac522f0f78a85a52084dcab4;p=ceph.git tools/cephfs-shell: fix listing of symbolic links Fixes: https://tracker.ceph.com/issues/48912 Signed-off-by: Varsha Rao (cherry picked from commit c005e08a5da34bac267487f40e3cf4bf634611ee) --- diff --git a/src/tools/cephfs/cephfs-shell b/src/tools/cephfs/cephfs-shell index b2dc535b3b6..e7a03e65b36 100755 --- a/src/tools/cephfs/cephfs-shell +++ b/src/tools/cephfs/cephfs-shell @@ -124,6 +124,8 @@ def mode_notation(mode): notation = '-' if mode[2] == '4': notation = 'd' + elif mode[2:4] == '12': + notation = 'l' for i in mode[-3:]: notation += permission_bits[i] return notation @@ -225,11 +227,16 @@ def humansize(nbytes): return '%s%s' % (f, suffixes[i]) -def print_long(path, is_dir, human_readable): - info = cephfs.stat(path) +def print_long(path, is_dir, is_symlink, human_readable): pretty = os.path.basename(path.decode('utf-8')) - if is_dir: - pretty = colorama.Style.BRIGHT + colorama.Fore.CYAN + pretty + '/' + info = cephfs.stat(path, follow_symlink=(not is_symlink)) + + if is_symlink: + target_file = cephfs.readlink(path, size=255).decode('utf-8') + pretty = colorama.Style.BRIGHT + colorama.Fore.CYAN + pretty + ' -> ' + target_file + pretty += colorama.Style.RESET_ALL + elif is_dir: + pretty = colorama.Style.BRIGHT + colorama.Fore.BLUE + pretty + '/' pretty += colorama.Style.RESET_ALL if human_readable: poutput('{}\t{:10s} {} {} {} {}'.format( @@ -821,24 +828,30 @@ class CephFSShell(Cmd): if args.S: items = sorted(items, key=lambda item: cephfs.stat( - path + b'/' + item.d_name).st_size) + 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, True) + is_dir, is_sym_lnk, True) elif args.long: print_long(os.path.join(cephfs.getcwd(), path, filepath), - is_dir, False) - elif is_dir: + is_dir, is_sym_lnk, False) + elif is_sym_lnk: values.append(colorama.Style.BRIGHT + colorama.Fore.CYAN + filepath.decode('utf-8') + + colorama.Style.RESET_ALL) + elif is_dir: + values.append(colorama.Style.BRIGHT + + colorama.Fore.BLUE + + filepath.decode('utf-8') + '/' + colorama.Style.RESET_ALL) else: