]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
cephfs-shell: fix mkdir command
authorMilind Changire <mchangir@redhat.com>
Fri, 12 Apr 2019 16:06:30 +0000 (21:36 +0530)
committerMilind Changire <mchangir@redhat.com>
Sat, 13 Apr 2019 06:36:21 +0000 (12:06 +0530)
Signed-off-by: Milind Changire <mchangir@redhat.com>
src/tools/cephfs/cephfs-shell

index 95d96a18b14a1920cc46515f4276782964bd089b..519d33d9f5a09622727637416bd6912abcc1743b 100755 (executable)
@@ -391,6 +391,29 @@ class CephFSShell(Cmd):
         """
         return self.complete_filenames(text, line, begidx, endidx)
 
+    class ModeAction(argparse.Action):
+        def __init__(self, option_strings, dest, nargs=None, **kwargs):
+            if nargs is not None and nargs is not '?':
+                raise ValueError("more than one modes not allowed")
+            super().__init__(option_strings, dest, **kwargs)
+
+        def __call__(self, parser, namespace, values, option_string=None):
+            o_mode = 0
+            try:
+                o_mode = int(values, base=8)
+            except ValueError as e:
+                parser.error("invalid mode: %s\n"
+                             "mode must be a numeric octal literal." % values)
+
+            if o_mode < 0:
+                parser.error("invalid mode: %s\n"
+                             "mode cannot be negative." % values)
+            if o_mode > 0o777:
+                parser.error("invalid mode: %s\n"
+                             "mode cannot be greater than octal 0777" % values)
+            setattr(namespace, self.dest, values)
+
+
     mkdir_parser = argparse.ArgumentParser(
         description='Create the directory(ies), if they do not already exist.')
     mkdir_parser.add_argument('dirs', type=str,
@@ -398,7 +421,7 @@ class CephFSShell(Cmd):
                               help='Name of new_directory.',
                               nargs='+')
     mkdir_parser.add_argument('-m', '--mode', type=str,
-                              action='store',
+                              action=ModeAction,
                               help='Sets the access mode for the new directory.')
     mkdir_parser.add_argument('-p', '--parent', action='store_true',
                               help='Create parent directories as necessary. \
@@ -419,7 +442,13 @@ exists.')
             if args.parent:
                 cephfs.mkdirs(path, permission)
             else:
-                cephfs.mkdir(path, permission)
+                try:
+                    cephfs.mkdir(path, permission)
+                except:
+                    self.poutput("directory missing in the path; "
+                                 "you may want to pass the -p argument")
+                    return
+
 
     def complete_put(self, text, line, begidx, endidx):
         """