From 082333bfaba433dae5ef064c66ab24179a66c32c Mon Sep 17 00:00:00 2001 From: Milind Changire Date: Fri, 12 Apr 2019 21:36:30 +0530 Subject: [PATCH] cephfs-shell: fix mkdir command Signed-off-by: Milind Changire --- src/tools/cephfs/cephfs-shell | 33 +++++++++++++++++++++++++++++++-- 1 file changed, 31 insertions(+), 2 deletions(-) diff --git a/src/tools/cephfs/cephfs-shell b/src/tools/cephfs/cephfs-shell index 95d96a18b14..519d33d9f5a 100755 --- a/src/tools/cephfs/cephfs-shell +++ b/src/tools/cephfs/cephfs-shell @@ -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): """ -- 2.39.5