commit: 667a6170ad2536aa3800bf35b3ea38f227d739b7
Author: Fabian Groffen <grobian <AT> gentoo <DOT> org>
AuthorDate: Sat Jun 29 11:44:55 2019 +0000
Commit: Fabian Groffen <grobian <AT> gentoo <DOT> org>
CommitDate: Sat Jun 29 11:44:55 2019 +0000
URL: https://gitweb.gentoo.org/proj/portage-utils.git/commit/?id=667a6170
qcheck: add -F argument
Signed-off-by: Fabian Groffen <grobian <AT> gentoo.org>
q.c | 2 +-
qcheck.c | 38 ++++++++++++++++++++++----------------
tests/qcheck/dotest | 2 +-
tests/qcheck/list01.good | 2 +-
tests/qcheck/list02.good | 2 +-
tests/qcheck/list04.good | 4 ++--
tests/qcheck/list05.good | 4 ++--
tests/qcheck/list06.good | 4 ++--
tests/qcheck/list07.good | 4 ++--
tests/qcheck/list09.good | 4 ++--
10 files changed, 36 insertions(+), 30 deletions(-)
diff --git a/q.c b/q.c
index 31427f3..3dd49f7 100644
--- a/q.c
+++ b/q.c
@@ -129,7 +129,7 @@ int q_main(int argc, char **argv)
rret = readlink("/proc/self/exe", buf, sizeof(buf) - 1);
#endif
if (rret == -1) {
- warnfp("haha no symlink love for you");
+ warnfp("haha no symlink love for you ... :(");
return 1;
}
buf[rret] = '\0';
diff --git a/qcheck.c b/qcheck.c
index 97070f2..f77a501 100644
--- a/qcheck.c
+++ b/qcheck.c
@@ -24,8 +24,12 @@
#include "xasprintf.h"
#include "xregex.h"
-#define QCHECK_FLAGS "s:uABHTPp" COMMON_FLAGS
+#define QCHECK_FORMAT "%[CATEGORY]%[PN]"
+#define QCHECK_FORMAT_VERBOSE "%[CATEGORY]%[PF]"
+
+#define QCHECK_FLAGS "F:s:uABHTPp" COMMON_FLAGS
static struct option const qcheck_long_opts[] = {
+ {"format", a_argument, NULL, 'F'},
{"skip", a_argument, NULL, 's'},
{"update", no_argument, NULL, 'u'},
{"noafk", no_argument, NULL, 'A'},
@@ -37,6 +41,7 @@ static struct option const qcheck_long_opts[] = {
COMMON_LONG_OPTS
};
static const char * const qcheck_opts_help[] = {
+ "Custom output format (default: " QCHECK_FORMAT ")",
"Ignore files matching the regular expression <arg>",
"Update missing files, chksum and mtimes for packages",
"Ignore missing files",
@@ -61,6 +66,7 @@ struct qcheck_opt_state {
bool chk_mtime;
bool chk_config_protect;
bool undo_prelink;
+ const char *fmt;
};
static int
@@ -97,7 +103,7 @@ qcheck_process_contents(tree_pkg_ctx *pkg_ctx, struct
qcheck_opt_state *state)
num_files = num_files_ok = num_files_unknown = num_files_ignored = 0;
qcprintf("%sing %s ...\n",
(state->qc_update ? "Updat" : "Check"),
- atom_format("%[CATEGORY]%[PF]", atom));
+ atom_format(state->fmt, atom));
if (state->qc_update) {
fp_contents_update = tree_pkg_vdb_fopenat_rw(pkg_ctx,
"CONTENTS~");
if (fp_contents_update == NULL) {
@@ -328,13 +334,8 @@ qcheck_process_contents(tree_pkg_ctx *pkg_ctx, struct
qcheck_opt_state *state)
if (!verbose)
return EXIT_SUCCESS;
}
- if (state->bad_only && num_files_ok != num_files) {
- if (verbose)
- printf("%s\n", atom_format("%[CATEGORY]%[PF]", atom));
- else {
- printf("%s\n", atom_format("%[CATEGORY]%[PN]", atom));
- }
- }
+ if (state->bad_only && num_files_ok != num_files)
+ printf("%s\n", atom_format(state->fmt, atom));
qcprintf(" %2$s*%1$s %3$s%4$zu%1$s out of %3$s%5$zu%1$s file%6$s are
good",
NORM, BOLD, BLUE, num_files_ok, num_files,
(num_files > 1 ? "s" : ""));
@@ -398,6 +399,7 @@ int qcheck_main(int argc, char **argv)
.chk_mtime = true,
.chk_config_protect = true,
.undo_prelink = false,
+ .fmt = NULL,
};
while ((ret = GETOPT_LONG(QCHECK, qcheck, "")) != -1) {
@@ -409,16 +411,20 @@ int qcheck_main(int argc, char **argv)
xarraypush(regex_arr, &preg, sizeof(preg));
break;
}
- case 'u': state.qc_update = true; break;
- case 'A': state.chk_afk = false; break;
- case 'B': state.bad_only = true; break;
- case 'H': state.chk_hash = false; break;
- case 'T': state.chk_mtime = false; break;
- case 'P': state.chk_config_protect = false; break;
- case 'p': state.undo_prelink = prelink_available(); break;
+ case 'u': state.qc_update = true; break;
+ case 'A': state.chk_afk = false; break;
+ case 'B': state.bad_only = true; break;
+ case 'H': state.chk_hash = false; break;
+ case 'T': state.chk_mtime = false; break;
+ case 'P': state.chk_config_protect = false; break;
+ case 'p': state.undo_prelink = prelink_available(); break;
+ case 'F': state.fmt = optarg; break;
}
}
+ if (state.fmt == NULL)
+ state.fmt = verbose ? QCHECK_FORMAT_VERBOSE : QCHECK_FORMAT;
+
argc -= optind;
argv += optind;
for (i = 0; i < (size_t)argc; ++i) {
diff --git a/tests/qcheck/dotest b/tests/qcheck/dotest
index fa1feed..c6e6e46 100755
--- a/tests/qcheck/dotest
+++ b/tests/qcheck/dotest
@@ -19,7 +19,7 @@ test() {
local num=$1 exp=$2 ret=0
shift 2
eval "$@" > list || ret=$?
- if ! diff -u list ${as}/list${num}.good ; then
+ if ! diff -u ${as}/list${num}.good list ; then
tfail "output does not match"
fi
if [[ ${exp} -ne ${ret} ]] ; then
diff --git a/tests/qcheck/list01.good b/tests/qcheck/list01.good
index 71e9db3..a6bde03 100644
--- a/tests/qcheck/list01.good
+++ b/tests/qcheck/list01.good
@@ -1,4 +1,4 @@
-Checking a-b/pkg-1.0 ...
+Checking a-b/pkg ...
MD5-DIGEST: /bin/bad-md5
MTIME: /bin/bad-mtime-obj
SHA1-DIGEST: /bin/bad-sha1
diff --git a/tests/qcheck/list02.good b/tests/qcheck/list02.good
index 8689d41..74e7b02 100644
--- a/tests/qcheck/list02.good
+++ b/tests/qcheck/list02.good
@@ -1,4 +1,4 @@
-Checking a-b/pkg-1.0 ...
+Checking a-b/pkg ...
MD5-DIGEST: /bin/bad-md5
MTIME: /bin/bad-mtime-obj
SHA1-DIGEST: /bin/bad-sha1
diff --git a/tests/qcheck/list04.good b/tests/qcheck/list04.good
index b90a759..604d20c 100644
--- a/tests/qcheck/list04.good
+++ b/tests/qcheck/list04.good
@@ -1,4 +1,4 @@
-Checking a-b/pkg-1.0 ...
+Checking a-b/pkg ...
MTIME: /bin/bad-mtime-obj
MTIME: /bin/bad-mtime-sym
AFK: /bin/broken-sym
@@ -7,5 +7,5 @@ Checking a-b/pkg-1.0 ...
AFK: /missing-dir/missing-file
AFK: /missing-dir/missing-sym
* 4 out of 11 files are good (2 files were ignored)
-Checking virtual/pkg-1 ...
+Checking virtual/pkg ...
* 0 out of 0 file are good
diff --git a/tests/qcheck/list05.good b/tests/qcheck/list05.good
index 6a6d206..35a0ff5 100644
--- a/tests/qcheck/list05.good
+++ b/tests/qcheck/list05.good
@@ -1,4 +1,4 @@
-Checking a-b/pkg-1.0 ...
+Checking a-b/pkg ...
MD5-DIGEST: /bin/bad-md5
SHA1-DIGEST: /bin/bad-sha1
AFK: /bin/broken-sym
@@ -7,5 +7,5 @@ Checking a-b/pkg-1.0 ...
AFK: /missing-dir/missing-file
AFK: /missing-dir/missing-sym
* 4 out of 11 files are good (2 files were ignored)
-Checking virtual/pkg-1 ...
+Checking virtual/pkg ...
* 0 out of 0 file are good
diff --git a/tests/qcheck/list06.good b/tests/qcheck/list06.good
index a924758..fb241db 100644
--- a/tests/qcheck/list06.good
+++ b/tests/qcheck/list06.good
@@ -1,8 +1,8 @@
-Checking a-b/pkg-1.0 ...
+Checking a-b/pkg ...
MD5-DIGEST: /bin/bad-md5
MTIME: /bin/bad-mtime-obj
SHA1-DIGEST: /bin/bad-sha1
MTIME: /bin/bad-mtime-sym
* 4 out of 8 files are good (5 files were ignored)
-Checking virtual/pkg-1 ...
+Checking virtual/pkg ...
* 0 out of 0 file are good
diff --git a/tests/qcheck/list07.good b/tests/qcheck/list07.good
index f354269..ae80975 100644
--- a/tests/qcheck/list07.good
+++ b/tests/qcheck/list07.good
@@ -1,4 +1,4 @@
-Checking a-b/pkg-1.0 ...
+Checking a-b/pkg ...
* 4 out of 4 files are good (9 files were ignored)
-Checking virtual/pkg-1 ...
+Checking virtual/pkg ...
* 0 out of 0 file are good
diff --git a/tests/qcheck/list09.good b/tests/qcheck/list09.good
index cd6195e..a12d957 100644
--- a/tests/qcheck/list09.good
+++ b/tests/qcheck/list09.good
@@ -1,4 +1,4 @@
-Updating a-b/pkg-1.0 ...
+Updating a-b/pkg ...
MD5-DIGEST: /bin/bad-md5
MTIME: /bin/bad-mtime-obj
SHA1-DIGEST: /bin/bad-sha1
@@ -8,5 +8,5 @@ Updating a-b/pkg-1.0 ...
AFK: /missing-dir
AFK: /missing-dir/missing-file
AFK: /missing-dir/missing-sym
-Checking a-b/pkg-1.0 ...
+Checking a-b/pkg ...
* 8 out of 8 files are good