]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
cephfs-shell: fix `rmdir`'s description and error msg output 46160/head
authordparmar18 <dparmar@redhat.com>
Thu, 5 May 2022 09:37:51 +0000 (15:07 +0530)
committerdparmar18 <dparmar@redhat.com>
Mon, 9 May 2022 15:08:52 +0000 (20:38 +0530)
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 <dparmar@redhat.com>
src/tools/cephfs/cephfs-shell

index ce12ffeab71810cfd0c2a795603840317282c8aa..b2e099936f6cf1fdc9e20d34ea3298a4e107faa0 100755 (executable)
@@ -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):
         """