Patchwork [BUG:1942] takes either 'y' or 'yes' and 'n' or 'no' for stop volume, delete volume and remove-brick

login
register
Submitter Mohammed Junaid Ahmed
Date 2010-10-14 09:44:47
Message ID <20101014094447.GA3630@junaid@gluster.com>
Download mbox | patch
Permalink /patch/5499/
State Accepted
Headers show

Comments

Mohammed Junaid Ahmed - 2010-10-14 09:44:47
Signed-off-by: Mohammed Junaid <junaid@gluster.com>
---
 cli/src/cli-cmd-volume.c |   40 ++++++++++++++++++++++++++++++----------
 1 files changed, 30 insertions(+), 10 deletions(-)

Patch

diff --git a/cli/src/cli-cmd-volume.c b/cli/src/cli-cmd-volume.c
index 7a15f5c..8fb32f5 100644
--- a/cli/src/cli-cmd-volume.c
+++ b/cli/src/cli-cmd-volume.c
@@ -317,20 +317,40 @@  out:
 gf_answer_t
 cli_cmd_get_confirmation (struct cli_state *state, const char *question)
 {
-        char                    answer = '\0';
+        char                    answer[5] = {'\0', };
         char                    flush = '\0';
+	int			len = 0;
 
         if (state->mode & GLUSTER_MODE_SCRIPT)
                 return GF_ANSWER_YES;
-        printf ("%s (y/n) ", question);
-        answer = getchar ();
-        flush = answer;
-        while ('\n' != flush)
-                flush = getchar ();
-        if ('y' != answer) {
-                return GF_ANSWER_NO;
-        }
-        return GF_ANSWER_YES;
+
+	printf ("%s (y/n) ", question);
+
+	fgets (answer, 4, stdin);
+
+	len = strlen (answer);
+
+	if (answer [len - 1] == '\n'){
+		answer [--len] = '\0';
+	} else {
+		do{
+			flush = getchar ();
+		}while (flush != '\n');
+	}
+
+	if (len > 3)
+		goto out;
+
+	if (!strcasecmp (answer, "y") || !strcasecmp (answer, "yes"))
+		return GF_ANSWER_YES;
+
+	else if (!strcasecmp (answer, "n") || !strcasecmp (answer, "no"))
+		return GF_ANSWER_NO;
+
+out:
+	cli_out ("Invalid input, please enter y/n");
+
+	return GF_ANSWER_NO;
 }
 
 int