From: Xiao Yang Date: Thu, 30 Jul 2020 00:45:36 +0000 (-0400) Subject: xfs_io: Make -D and -R options incompatible explicitly X-Git-Tag: v5.8.0-rc0~50 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=5fd7257cda8189bf41a86f62eb48aa1da2187009;p=thirdparty%2Fxfsprogs-dev.git xfs_io: Make -D and -R options incompatible explicitly -D and -R options are mutually exclusive actually but many commands can accept them at the same time and process them differently(e.g. chattr alway chooses -D option or cowextsize accepts the last one specified), so make these commands have the consistent behavior that don't accept them concurrently. 1) Make them incompatible by setting argmax to 1 if commands can accept single option(i.e. lsattr, lsproj). 2) Make them incompatible by adding check if commands can accept multiple options(i.e. chattr, chproj, extsize, cowextsize). Signed-off-by: Xiao Yang Reviewed-by: Eric Sandeen Signed-off-by: Eric Sandeen --- diff --git a/io/attr.c b/io/attr.c index 80e285147..181ff0895 100644 --- a/io/attr.c +++ b/io/attr.c @@ -191,12 +191,10 @@ lsattr_f( while ((c = getopt(argc, argv, "DRav")) != EOF) { switch (c) { case 'D': - recurse_all = 0; recurse_dir = 1; break; case 'R': recurse_all = 1; - recurse_dir = 0; break; case 'a': aflag = 1; @@ -320,6 +318,13 @@ chattr_f( } } + if (recurse_all && recurse_dir) { + fprintf(stderr, _("%s: -R and -D options are mutually exclusive\n"), + progname); + exitcode = 1; + return 0; + } + if (recurse_all || recurse_dir) { nftw(name, chattr_callback, 100, FTW_PHYS | FTW_MOUNT | FTW_DEPTH); diff --git a/io/cowextsize.c b/io/cowextsize.c index 549634438..f6b134df3 100644 --- a/io/cowextsize.c +++ b/io/cowextsize.c @@ -141,12 +141,10 @@ cowextsize_f( while ((c = getopt(argc, argv, "DR")) != EOF) { switch (c) { case 'D': - recurse_all = 0; recurse_dir = 1; break; case 'R': recurse_all = 1; - recurse_dir = 0; break; default: return command_usage(&cowextsize_cmd); @@ -165,6 +163,13 @@ cowextsize_f( cowextsize = -1; } + if (recurse_all && recurse_dir) { + fprintf(stderr, _("%s: -R and -D options are mutually exclusive\n"), + progname); + exitcode = 1; + return 0; + } + if (recurse_all || recurse_dir) nftw(file->name, (cowextsize >= 0) ? set_cowextsize_callback : get_cowextsize_callback, diff --git a/io/open.c b/io/open.c index 9a8b5e5c5..d8072664c 100644 --- a/io/open.c +++ b/io/open.c @@ -426,12 +426,10 @@ lsproj_f( while ((c = getopt(argc, argv, "DR")) != EOF) { switch (c) { case 'D': - recurse_all = 0; recurse_dir = 1; break; case 'R': recurse_all = 1; - recurse_dir = 0; break; default: exitcode = 1; @@ -504,12 +502,10 @@ chproj_f( while ((c = getopt(argc, argv, "DR")) != EOF) { switch (c) { case 'D': - recurse_all = 0; recurse_dir = 1; break; case 'R': recurse_all = 1; - recurse_dir = 0; break; default: exitcode = 1; @@ -529,6 +525,13 @@ chproj_f( return 0; } + if (recurse_all && recurse_dir) { + fprintf(stderr, _("%s: -R and -D options are mutually exclusive\n"), + progname); + exitcode = 1; + return 0; + } + if (recurse_all || recurse_dir) nftw(file->name, chproj_callback, 100, FTW_PHYS | FTW_MOUNT | FTW_DEPTH); @@ -661,12 +664,10 @@ extsize_f( while ((c = getopt(argc, argv, "DR")) != EOF) { switch (c) { case 'D': - recurse_all = 0; recurse_dir = 1; break; case 'R': recurse_all = 1; - recurse_dir = 0; break; default: exitcode = 1; @@ -686,6 +687,13 @@ extsize_f( extsize = -1; } + if (recurse_all && recurse_dir) { + fprintf(stderr, _("%s: -R and -D options are mutually exclusive\n"), + progname); + exitcode = 1; + return 0; + } + if (recurse_all || recurse_dir) { nftw(file->name, (extsize >= 0) ? set_extsize_callback : get_extsize_callback, @@ -960,7 +968,7 @@ open_init(void) lsproj_cmd.cfunc = lsproj_f; lsproj_cmd.args = _("[-D | -R]"); lsproj_cmd.argmin = 0; - lsproj_cmd.argmax = -1; + lsproj_cmd.argmax = 1; lsproj_cmd.flags = CMD_NOMAP_OK | CMD_FOREIGN_OK; lsproj_cmd.oneline = _("list project identifier set on the currently open file");