]> git.ipfire.org Git - thirdparty/xfsprogs-dev.git/commitdiff
xfs_io: Make -D and -R options incompatible explicitly
authorXiao Yang <yangx.jy@cn.fujitsu.com>
Thu, 30 Jul 2020 00:45:36 +0000 (20:45 -0400)
committerEric Sandeen <sandeen@sandeen.net>
Thu, 30 Jul 2020 00:45:36 +0000 (20:45 -0400)
-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 <yangx.jy@cn.fujitsu.com>
Reviewed-by: Eric Sandeen <sandeen@redhat.com>
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
io/attr.c
io/cowextsize.c
io/open.c

index 80e285147acb2975bd21ec5d5cafc916b17a29d0..181ff089579d2976ea6b09a4f14416c24a4ab0f2 100644 (file)
--- 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);
index 549634438aa4c31281078b5166937d304201f831..f6b134df37729adbc2237e14c91897369a6021b0 100644 (file)
@@ -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,
index 9a8b5e5c59040ce18badf4da8ab19d1f36ed6ad4..d8072664c1657f1c9d4640864e98ff6b161acf27 100644 (file)
--- 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");