Skip to contentSkip to conversation

erofs-utils: mkfs: add --exclude-from option

PATCH Superseded Nithurshen 2 participants 5 messages Mar 8 – Mar 9

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Nithurshen

author
#0 lore raw

PATCH 1/1 erofs-utils: mkfs: add --exclude-from option

Currently, users who want to exclude multiple specific files or paths must pass them one-by-one using --exclude-path or --exclude-regex via the command line. This becomes cumbersome for complex build systems with dozens of exclusions.

This patch introduces an \--exclude-from=FILE\ flag to mkfs.erofs.

Similar to standard archiving tools, it allows users to supply a text file containing a list of paths or regexes to exclude, which are read line-by-line and applied to the EROFS build process.

---
 mkfs/main.c | 35 +++++++++++++++++++++++++++++++++++
 1 file changed, 35 insertions(+)
mkfs/main.c +35 -0
index 07ef086..a6cd251 100644
@@ -39,6 +39,7 @@ static struct option long_options[] = {
 	{"help", no_argument, 0, 'h'},
 	{"exclude-path", required_argument, NULL, 2},
 	{"exclude-regex", required_argument, NULL, 3},
+	{"exclude-from", required_argument, NULL, 540},
 #ifdef HAVE_LIBSELINUX
 	{"file-contexts", required_argument, NULL, 4},
 #endif
@@ -199,6 +200,7 @@ static void usage(int argc, char **argv)
 		" --dsunit=#             align all data block addresses to multiples of #\n"
 		" --exclude-path=X       avoid including file X (X = exact literal path)\n"
 		" --exclude-regex=X      avoid including files that match X (X = regular expression)\n"
+		" --exclude-from=X       avoid including files listed in file X\n"
 #ifdef HAVE_LIBSELINUX
 		" --file-contexts=X      specify a file contexts file to setup selinux labels\n"
 #endif
@@ -1246,6 +1248,39 @@ static int mkfs_parse_options_cfg(struct erofs_importer_params *params,
 		case 7:
 			params->fixed_uid = params->fixed_gid = 0;
 			break;
+		case 540: {
+			FILE *f = fopen(optarg, "r");
+			if (!f) {
+				erofs_err("failed to open exclude file: %s", optarg);
+				return -errno;
+			}
+
+			char *line = NULL;
+			size_t len = 0;
+			ssize_t read;
+
+			while ((read = getline(&line, &len, f)) != -1) {
+				if (read > 0 && line[read - 1] == '\n') {
+					line[read - 1] = '\0';
+					read--;
+				}
+
+				if (read == 0) continue;
+
+				opt = erofs_parse_exclude_path(line, false);
+				if (opt) {
+					erofs_err("failed to parse exclude path from file: %s",
+						  erofs_strerror(opt));
+					free(line);
+					fclose(f);
+					return opt;
+				}
+			}
+			free(line);
+			fclose(f);
+			break;
+			}
+
 #ifndef NDEBUG
 		case 8:
 			cfg.c_random_pclusterblks = true;
Signature · 1 line
2.51.0
#1 lore raw
Quoted 5 lines · Nithurshen

Currently, users who want to exclude multiple specific files or paths must pass them one-by-one using --exclude-path or --exclude-regex via the command line. This becomes cumbersome for complex build systems with dozens of exclusions.

This patch introduces an \--exclude-from=FILE\ flag to mkfs.erofs.

Similar to standard archiving tools, it allows users to supply a text file containing a list of paths or regexes to exclude, which are read line-by-line and applied to the EROFS build process.

Hi Nithurshen,

72-char limit again.

Your code seems could not handle regex, as you call erofs_parse_exclude_path(line, false).

Thanks,

Yifan

Quoted 65 lines
---
  mkfs/main.c | 35 +++++++++++++++++++++++++++++++++++
  1 file changed, 35 insertions(+)
mkfs/main.c +35 -0
index 07ef086..a6cd251 100644
@@ -39,6 +39,7 @@ static struct option long_options[] = {
  	{"help", no_argument, 0, 'h'},
  	{"exclude-path", required_argument, NULL, 2},
  	{"exclude-regex", required_argument, NULL, 3},
+	{"exclude-from", required_argument, NULL, 540},
  #ifdef HAVE_LIBSELINUX
  	{"file-contexts", required_argument, NULL, 4},
  #endif
@@ -199,6 +200,7 @@ static void usage(int argc, char **argv)
  		" --dsunit=#             align all data block addresses to multiples of #\n"
  		" --exclude-path=X       avoid including file X (X = exact literal path)\n"
  		" --exclude-regex=X      avoid including files that match X (X = regular expression)\n"
+		" --exclude-from=X       avoid including files listed in file X\n"
  #ifdef HAVE_LIBSELINUX
  		" --file-contexts=X      specify a file contexts file to setup selinux labels\n"
  #endif
@@ -1246,6 +1248,39 @@ static int mkfs_parse_options_cfg(struct erofs_importer_params *params,
  		case 7:
  			params->fixed_uid = params->fixed_gid = 0;
  			break;
+		case 540: {
+			FILE *f = fopen(optarg, "r");
+			if (!f) {
+				erofs_err("failed to open exclude file: %s", optarg);
+				return -errno;
+			}
+
+			char *line = NULL;
+			size_t len = 0;
+			ssize_t read;
+
+			while ((read = getline(&line, &len, f)) != -1) {
+				if (read > 0 && line[read - 1] == '\n') {
+					line[read - 1] = '\0';
+					read--;
+				}
+
+				if (read == 0) continue;
+
+				opt = erofs_parse_exclude_path(line, false);
+				if (opt) {
+					erofs_err("failed to parse exclude path from file: %s",
+						  erofs_strerror(opt));
+					free(line);
+					fclose(f);
+					return opt;
+				}
+			}
+			free(line);
+			fclose(f);
+			break;
+			}
+
  #ifndef NDEBUG
  		case 8:
  			cfg.c_random_pclusterblks = true;
#2 lore raw

Hi Yifan Zhao,

Quoted 3 lines

Hi Nithurshen,

72-char limit again.

Yes, I will double check the char limit from here on out.

Quoted 3 lines

Your code seems could not handle regex, as you call erofs_parse_exclude_path(line, false).

I have taken care of this in the v2 patch.

Thanks and regards
Nithurshen

author
#3 lore raw

PATCH v2 1/1 erofs-utils: mkfs: add --exclude-path-from and --exclude-regex-from

In reply to Nithurshen

Currently, users who want to exclude multiple specific files or paths must pass them one-by-one using --exclude-path or --exclude-regex via the command line. This becomes cumbersome for complex build systems with dozens of exclusions.

This patch introduces --exclude-path-from=FILE and --exclude-regex-from=FILE flags to mkfs.erofs. Similar to standard archiving tools, they allow users to supply a text file containing a list of literal paths or regular expressions to exclude, which are read line-by-line and applied to the EROFS build process.

---
 mkfs/main.c | 39 +++++++++++++++++++++++++++++++++++++++
 1 file changed, 39 insertions(+)
mkfs/main.c +39 -0
index 07ef086..1240771 100644
@@ -39,6 +39,8 @@ static struct option long_options[] = {
 	{"help", no_argument, 0, 'h'},
 	{"exclude-path", required_argument, NULL, 2},
 	{"exclude-regex", required_argument, NULL, 3},
+	{"exclude-path-from", required_argument, NULL, 540},
+	{"exclude-regex-from", required_argument, NULL, 541},
 #ifdef HAVE_LIBSELINUX
 	{"file-contexts", required_argument, NULL, 4},
 #endif
@@ -199,6 +201,8 @@ static void usage(int argc, char **argv)
 		" --dsunit=#             align all data block addresses to multiples of #\n"
 		" --exclude-path=X       avoid including file X (X = exact literal path)\n"
 		" --exclude-regex=X      avoid including files that match X (X = regular expression)\n"
+		" --exclude-path-from=X  avoid including files listed in file X\n"
+		" --exclude-regex-from=X avoid including regexes listed in file X\n"
 #ifdef HAVE_LIBSELINUX
 		" --file-contexts=X      specify a file contexts file to setup selinux labels\n"
 #endif
@@ -1246,6 +1250,41 @@ static int mkfs_parse_options_cfg(struct erofs_importer_params *params,
 		case 7:
 			params->fixed_uid = params->fixed_gid = 0;
 			break;
+			case 540:
+			case 541: {
+				FILE *f = fopen(optarg, "r");
+				if (!f) {
+					erofs_err("failed to open exclude file: %s", optarg);
+					return -errno;
+				}
+
+				char *line = NULL;
+				size_t len = 0;
+				ssize_t read;
+				bool is_regex = (opt == 541);
+
+				while ((read = getline(&line, &len, f)) != -1) {
+					if (read > 0 && line[read - 1] == '\n') {
+						line[read - 1] = '\0';
+						read--;
+					}
+
+					if (read == 0) continue;
+
+					err = erofs_parse_exclude_path(line, is_regex);
+					if (err) {
+						erofs_err("failed to parse exclude rule from file: %s",
+							  erofs_strerror(err));
+						free(line);
+						fclose(f);
+						return err;
+					}
+				}
+				free(line);
+				fclose(f);
+				break;
+			}
+
 #ifndef NDEBUG
 		case 8:
 			cfg.c_random_pclusterblks = true;
Signature · 1 line
2.51.0
author
#4 lore raw

PATCH v2 1/1 erofs-utils: mkfs: add --exclude-path-from and --exclude-regex-from

In reply to Nithurshen

Currently, users who want to exclude multiple specific files or paths must pass them one-by-one using --exclude-path or --exclude-regex via the command line. This becomes cumbersome for complex build systems with dozens of exclusions.

This patch introduces --exclude-path-from=FILE and --exclude-regex-from=FILE flags to mkfs.erofs. Similar to standard archiving tools, they allow users to supply a text file containing a list of literal paths or regular expressions to exclude, which are read line-by-line and applied to the EROFS build process.

---
 mkfs/main.c | 39 +++++++++++++++++++++++++++++++++++++++
 1 file changed, 39 insertions(+)
mkfs/main.c +39 -0
index 07ef086..1240771 100644
@@ -39,6 +39,8 @@ static struct option long_options[] = {
 	{"help", no_argument, 0, 'h'},
 	{"exclude-path", required_argument, NULL, 2},
 	{"exclude-regex", required_argument, NULL, 3},
+	{"exclude-path-from", required_argument, NULL, 540},
+	{"exclude-regex-from", required_argument, NULL, 541},
 #ifdef HAVE_LIBSELINUX
 	{"file-contexts", required_argument, NULL, 4},
 #endif
@@ -199,6 +201,8 @@ static void usage(int argc, char **argv)
 		" --dsunit=#             align all data block addresses to multiples of #\n"
 		" --exclude-path=X       avoid including file X (X = exact literal path)\n"
 		" --exclude-regex=X      avoid including files that match X (X = regular expression)\n"
+		" --exclude-path-from=X  avoid including files listed in file X\n"
+		" --exclude-regex-from=X avoid including regexes listed in file X\n"
 #ifdef HAVE_LIBSELINUX
 		" --file-contexts=X      specify a file contexts file to setup selinux labels\n"
 #endif
@@ -1246,6 +1250,41 @@ static int mkfs_parse_options_cfg(struct erofs_importer_params *params,
 		case 7:
 			params->fixed_uid = params->fixed_gid = 0;
 			break;
+			case 540:
+			case 541: {
+				FILE *f = fopen(optarg, "r");
+				if (!f) {
+					erofs_err("failed to open exclude file: %s", optarg);
+					return -errno;
+				}
+
+				char *line = NULL;
+				size_t len = 0;
+				ssize_t read;
+				bool is_regex = (opt == 541);
+
+				while ((read = getline(&line, &len, f)) != -1) {
+					if (read > 0 && line[read - 1] == '\n') {
+						line[read - 1] = '\0';
+						read--;
+					}
+
+					if (read == 0) continue;
+
+					err = erofs_parse_exclude_path(line, is_regex);
+					if (err) {
+						erofs_err("failed to parse exclude rule from file: %s",
+							  erofs_strerror(err));
+						free(line);
+						fclose(f);
+						return err;
+					}
+				}
+				free(line);
+				fclose(f);
+				break;
+			}
+
 #ifndef NDEBUG
 		case 8:
 			cfg.c_random_pclusterblks = true;
Signature · 1 line
2.51.0