diff options
author | Pranith Kumar K <pranithk@gluster.com> | 2010-09-21 10:49:49 +0000 |
---|---|---|
committer | Vijay Bellur <vijay@dev.gluster.com> | 2010-09-21 10:41:13 -0700 |
commit | eb8561e302bd83305fb093eb8cca42b4f9f62b22 (patch) | |
tree | 1432eb8e9add9b6b029aaedbc0939d8960a70b80 /cli | |
parent | bd1fa94c8e26cb34566ad460092c2089597e2b17 (diff) |
cli: remove trailing slashes from brick paths
Signed-off-by: Pranith Kumar K <pranithk@gluster.com>
Signed-off-by: Vijay Bellur <vijay@dev.gluster.com>
BUG: 1659 ()
URL: http://bugs.gluster.com/cgi-bin/bugzilla3/show_bug.cgi?id=1659
Diffstat (limited to 'cli')
-rw-r--r-- | cli/src/cli-cmd-parser.c | 61 | ||||
-rw-r--r-- | cli/src/cli.c | 20 | ||||
-rw-r--r-- | cli/src/cli.h | 2 |
3 files changed, 73 insertions, 10 deletions
diff --git a/cli/src/cli-cmd-parser.c b/cli/src/cli-cmd-parser.c index 479df9386..2b7cdd9f6 100644 --- a/cli/src/cli-cmd-parser.c +++ b/cli/src/cli-cmd-parser.c @@ -189,6 +189,8 @@ cli_cmd_volume_create_parse (const char **words, int wordcount, dict_t **options "<export-dir-abs-path>", words[brick_index]); ret = -1; goto out; + } else { + cli_path_strip_trailing_slashes (delimiter + 1); } if ((brick_list_size + strlen (words[brick_index]) + 1) > 120000) { gf_log ("cli", GF_LOG_ERROR, @@ -451,7 +453,10 @@ cli_cmd_volume_add_brick_parse (const char **words, int wordcount, "<export-dir-abs-path>", words[brick_index]); ret = -1; goto out; + } else { + cli_path_strip_trailing_slashes (delimiter + 1); } + if ((brick_list_size + strlen (words[brick_index]) + 1) > 120000) { gf_log ("cli", GF_LOG_ERROR, "total brick list is larger than a request " @@ -635,7 +640,10 @@ cli_cmd_volume_remove_brick_parse (const char **words, int wordcount, "<export-dir-abs-path>", words[brick_index]); ret = -1; goto out; + } else { + cli_path_strip_trailing_slashes (delimiter + 1); } + j = tmp_index; strcpy(tmp_brick, words[brick_index]); while ( j < brick_index) { @@ -723,6 +731,7 @@ cli_cmd_volume_replace_brick_parse (const char **words, int wordcount, delimiter = strchr ((char *)words[3], ':'); if (delimiter && delimiter != words[3] && *(delimiter+1) == '/') { + cli_path_strip_trailing_slashes (delimiter + 1); ret = dict_set_str (dict, "src-brick", (char *)words[3]); if (ret) @@ -740,8 +749,11 @@ cli_cmd_volume_replace_brick_parse (const char **words, int wordcount, "<HOSTNAME>:<export-dir-abs-path>", words[4]); ret = -1; goto out; + } else { + cli_path_strip_trailing_slashes (delimiter + 1); } + ret = dict_set_str (dict, "dst-brick", (char *)words[4]); if (ret) @@ -800,6 +812,7 @@ cli_cmd_log_filename_parse (const char **words, int wordcount, dict_t **options) char *volname = NULL; char *str = NULL; int ret = -1; + char *delimiter = NULL; GF_ASSERT (words); GF_ASSERT (options); @@ -821,6 +834,16 @@ cli_cmd_log_filename_parse (const char **words, int wordcount, dict_t **options) str = (char *)words[4]; if (strchr (str, ':')) { + delimiter = strchr (words[4], ':'); + if (!delimiter || delimiter == words[4] + || *(delimiter+1) != '/') { + cli_out ("wrong brick type: %s, use <HOSTNAME>:" + "<export-dir-abs-path>", words[4]); + ret = -1; + goto out; + } else { + cli_path_strip_trailing_slashes (delimiter + 1); + } ret = dict_set_str (dict, "brick", str); if (ret) goto out; @@ -851,6 +874,7 @@ cli_cmd_log_locate_parse (const char **words, int wordcount, dict_t **options) char *volname = NULL; char *str = NULL; int ret = -1; + char *delimiter = NULL; GF_ASSERT (words); GF_ASSERT (options); @@ -870,12 +894,20 @@ cli_cmd_log_locate_parse (const char **words, int wordcount, dict_t **options) if (ret) goto out; - str = (char *)words[4]; - if (str && strchr (str, ':')) { - ret = dict_set_str (dict, "brick", str); - if (ret) - goto out; + delimiter = strchr (words[4], ':'); + if (!delimiter || delimiter == words[4] + || *(delimiter+1) != '/') { + cli_out ("wrong brick type: %s, use <HOSTNAME>:" + "<export-dir-abs-path>", words[4]); + ret = -1; + goto out; + } else { + cli_path_strip_trailing_slashes (delimiter + 1); } + str = (char *)words[4]; + ret = dict_set_str (dict, "brick", str); + if (ret) + goto out; *options = dict; @@ -893,6 +925,7 @@ cli_cmd_log_rotate_parse (const char **words, int wordcount, dict_t **options) char *volname = NULL; char *str = NULL; int ret = -1; + char *delimiter = NULL; GF_ASSERT (words); GF_ASSERT (options); @@ -912,12 +945,20 @@ cli_cmd_log_rotate_parse (const char **words, int wordcount, dict_t **options) if (ret) goto out; - str = (char *)words[4]; - if (str && strchr (str, ':')) { - ret = dict_set_str (dict, "brick", str); - if (ret) - goto out; + delimiter = strchr (words[4], ':'); + if (!delimiter || delimiter == words[4] + || *(delimiter+1) != '/') { + cli_out ("wrong brick type: %s, use <HOSTNAME>:" + "<export-dir-abs-path>", words[4]); + ret = -1; + goto out; + } else { + cli_path_strip_trailing_slashes (delimiter + 1); } + str = (char *)words[4]; + ret = dict_set_str (dict, "brick", str); + if (ret) + goto out; *options = dict; diff --git a/cli/src/cli.c b/cli/src/cli.c index 8730211bf..a08d2d214 100644 --- a/cli/src/cli.c +++ b/cli/src/cli.c @@ -495,6 +495,26 @@ cli_local_wipe (cli_local_t *local) return; } +void +cli_path_strip_trailing_slashes (char *path) +{ + int i = 0; + int len = 0; + + if (!path) + return; + + len = strlen (path); + for (i = len - 1; i > 0 ; i--) { + if (path[i] != '/') + break; + + } + + if (i < (len - 1)) + path[i + 1] = '\0'; +} + struct cli_state *global_state; int diff --git a/cli/src/cli.h b/cli/src/cli.h index 44f653685..b8aa985b8 100644 --- a/cli/src/cli.h +++ b/cli/src/cli.h @@ -207,4 +207,6 @@ cli_cmd_broadcast_connected (); int cli_rpc_notify (struct rpc_clnt *rpc, void *mydata, rpc_clnt_event_t event, void *data); +void +cli_path_strip_trailing_slashes (char *path); #endif /* __CLI_H__ */ |