From: dparmar18 Date: Thu, 5 May 2022 09:37:51 +0000 (+0530) Subject: cephfs-shell: fix `rmdir`'s description and error msg output X-Git-Tag: v18.0.0~825^2 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=9d06d861487afbf7981a6db1d9997e70742024d2;p=ceph.git cephfs-shell: fix `rmdir`'s description and error msg output Descrption: rmdir cmd's description bettered(used man page's rmdir description), along with aligning the error message with that of bash's rmdir. Fixes: https://tracker.ceph.com/issues/40860 Signed-off-by: Dhairya Parmar --- diff --git a/src/tools/cephfs/cephfs-shell b/src/tools/cephfs/cephfs-shell index ce12ffeab718..b2e099936f6c 100755 --- a/src/tools/cephfs/cephfs-shell +++ b/src/tools/cephfs/cephfs-shell @@ -865,14 +865,14 @@ class CephFSShell(Cmd): """ return self.complete_filenames(text, line, begidx, endidx) - rmdir_parser = argparse.ArgumentParser(description='Remove Directory.') - rmdir_parser.add_argument('paths', help='Directory Path.', nargs='+', + rmdir_parser = argparse.ArgumentParser( + description='Remove the directory(ies), if they are empty.') + rmdir_parser.add_argument('paths', help='Directory Path(s)', nargs='+', action=path_to_bytes) rmdir_parser.add_argument('-p', '--parent', action='store_true', - help='Remove parent directories as necessary. ' - 'When this option is specified, no error ' - 'is reported if a directory has any ' - 'sub-directories, files') + help="remove directory and its ancestors; " + "e.g., 'rmdir -p a/b/c' is similar to " + "'rmdir a/b/c a/b a'") @with_argparser(rmdir_parser) def do_rmdir(self, args): @@ -922,7 +922,23 @@ class CephFSShell(Cmd): try: cephfs.rmdir(path) except libcephfs.Error as e: - set_exit_code_msg(msg=e) + if e.get_error_code() == 2: + set_exit_code_msg(e.get_error_code(), + "rmdir: failed to remove " + f"{path.decode('utf-8')}: " + "No such file or directory") + elif e.get_error_code() == 20: + set_exit_code_msg(e.get_error_code(), + "rmdir: failed to remove " + f"{path.decode('utf-8')}: " + "Not a directory") + elif e.get_error_code() == 39: + set_exit_code_msg(e.get_error_code(), + "rmdir: failed to remove " + f"{path.decode('utf-8')}: " + "Directory not empty") + else: + set_exit_code_msg(msg=e) def complete_rm(self, text, line, begidx, endidx): """