[PATCH v2] xfs_io: Make -D and -R options incompatible explicitly

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



-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@xxxxxxxxxxxxxx>
---
 io/attr.c       |  9 +++++++--
 io/cowextsize.c |  9 +++++++--
 io/open.c       | 22 +++++++++++++++-------
 3 files changed, 29 insertions(+), 11 deletions(-)

diff --git a/io/attr.c b/io/attr.c
index 80e28514..181ff089 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 54963443..f6b134df 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 9a8b5e5c..d8072664 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");
-- 
2.21.0






[Index of Archives]     [XFS Filesystem Development (older mail)]     [Linux Filesystem Development]     [Linux Audio Users]     [Yosemite Trails]     [Linux Kernel]     [Linux RAID]     [Linux SCSI]


  Powered by Linux