From: Karel Zak Date: Wed, 17 Feb 2021 10:14:54 +0000 (+0100) Subject: hardlink: add --quiet option X-Git-Tag: v2.37-rc1~110 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=4c467ebc5cb53d58956112f9466b7507f639e585;p=thirdparty%2Futil-linux.git hardlink: add --quiet option Signed-off-by: Karel Zak --- diff --git a/misc-utils/hardlink.1 b/misc-utils/hardlink.1 index d47fda5c19..4665f60c2f 100644 --- a/misc-utils/hardlink.1 +++ b/misc-utils/hardlink.1 @@ -23,6 +23,9 @@ print quick usage details to the screen. More verbose output. If specified once, every hardlinked file is displayed, if specified twice, it also shows every comparison. .TP +.BR \-q ,\ \-\-quiet +Quiet mode, don't print anything. +.TP .B \-n ,\ \-\-dry\-run Do not act, just print what would happen .TP diff --git a/misc-utils/hardlink.c b/misc-utils/hardlink.c index 88e1c4f417..ef2852a197 100644 --- a/misc-utils/hardlink.c +++ b/misc-utils/hardlink.c @@ -42,6 +42,7 @@ #include "xalloc.h" #include "strutils.h" #include "monotonic.h" +#include "optutils.h" /* Use libpcre2posix if it's available */ #ifdef HAVE_PCRE2_POSIX @@ -56,6 +57,8 @@ # include /* listxattr, getxattr */ #endif +static int quiet; /* don't print anything */ + /** * struct file - Information about a file * @st: The stat buffer associated with the file @@ -184,7 +187,7 @@ static void jlog(enum log_level level, const char *format, ...) { va_list args; - if (level > (unsigned int) opts.verbosity) + if (quiet || level > (unsigned int) opts.verbosity) return; va_start(args, format); @@ -858,6 +861,7 @@ static void __attribute__((__noreturn__)) usage(void) fputs(USAGE_OPTIONS, out); fputs(_(" -v, --verbose verbose output (repeat for more verbosity)\n"), out); + fputs(_(" -q, --quiet quiet mode - don't print anything\n" fputs(_(" -n, --dry-run don't actually link anything\n"), out); fputs(_(" -f, --respect-name filenames have to be identical\n"), out); fputs(_(" -p, --ignore-mode ignore changes of file mode\n"), out); @@ -915,7 +919,7 @@ static void register_regex(struct regex_link **pregs, const char *regex) */ static int parse_options(int argc, char *argv[]) { - static const char optstr[] = "VhvnfpotXcmMOx:i:s:"; + static const char optstr[] = "VhvnfpotXcmMOx:i:s:q"; static const struct option long_options[] = { {"version", no_argument, NULL, 'V'}, {"help", no_argument, NULL, 'h'}, @@ -933,11 +937,20 @@ static int parse_options(int argc, char *argv[]) {"include", required_argument, NULL, 'i'}, {"minimum-size", required_argument, NULL, 's'}, {"content", no_argument, NULL, 'c'}, + {"quiet", no_argument, NULL, 'q'}, {NULL, 0, NULL, 0} }; + static const ul_excl_t excl[] = { + { 'q','v' }, + { 0 } + }; + int excl_st[ARRAY_SIZE(excl)] = UL_EXCL_STATUS_INIT; int c; while ((c = getopt_long(argc, argv, optstr, long_options, NULL)) != -1) { + + err_exclusive_options(c, long_options, excl, excl_st); + switch (c) { case 'p': opts.respect_mode = FALSE; @@ -966,6 +979,9 @@ static int parse_options(int argc, char *argv[]) case 'v': opts.verbosity++; break; + case 'q': + quiet = TRUE; + break; case 'c': opts.respect_mode = FALSE; opts.respect_name = FALSE;