hardlink: cleanup --minimum-size stuff

* use uintmax_t
* use strtosize_or_err()
* add info about suffixes to man page

Signed-off-by: Karel Zak <kzak@redhat.com>
This commit is contained in:
Karel Zak 2021-02-04 13:06:56 +01:00
parent 9e7235e7e0
commit 631e6865e3
2 changed files with 11 additions and 34 deletions

View File

@ -59,11 +59,11 @@ A regular expression to include files. If the option \-\-exclude has been given,
this option re-includes files which would otherwise be excluded. If the option
is used without \-\-exclude, only files matched by the pattern are included.
.TP
.B \-s or \-\-minimum\-size
.B \-s or \-\-minimum\-size \fIsize\fP
The minimum size to consider. By default this is 1, so empty files will not
be linked. An optional suffix of K,M,G,T may be provided, indicating that the
file size is KiB,MiB,GiB,TiB.
be linked. The \fIsize\fR argument may be followed by the multiplicative
suffixes KiB (=1024), MiB (=1024*1024), and so on for GiB, TiB, PiB, EiB, ZiB
and YiB (the "iB" is optional, e.g., "K" has the same meaning as "KiB").
.SH ARGUMENTS
.B hardlink
takes one or more directories which will be searched for files to be linked.

View File

@ -40,6 +40,7 @@
#include "nls.h"
#include "c.h"
#include "xalloc.h"
#include "strutils.h"
/* Use libpcre2posix if it's available */
#ifdef HAVE_PCRE2_POSIX
@ -152,7 +153,7 @@ static struct options {
unsigned int minimise:1;
unsigned int keep_oldest:1;
unsigned int dry_run:1;
unsigned long long min_size;
uintmax_t min_size;
} opts = {
/* default setting */
.respect_mode = TRUE,
@ -770,7 +771,7 @@ static int inserter(const char *fpath, const struct stat *sb, int typeflag,
stats.files++;
if (sb->st_size < opts.min_size) {
if ((uintmax_t) sb->st_size < opts.min_size) {
jlog(JLOG_DEBUG1, "Skipped %s (smaller than configured size)", fpath);
return 0;
}
@ -972,13 +973,10 @@ static int parse_options(int argc, char *argv[])
{"content", no_argument, NULL, 'c'},
{NULL, 0, NULL, 0}
};
int c;
int opt;
char unit = '\0';
while ((opt = getopt_long(argc, argv, optstr, long_options, NULL)) != -1) {
switch (opt) {
while ((c = getopt_long(argc, argv, optstr, long_options, NULL)) != -1) {
switch (c) {
case 'p':
opts.respect_mode = FALSE;
break;
@ -1025,28 +1023,7 @@ static int parse_options(int argc, char *argv[])
return 1;
break;
case 's':
if (sscanf(optarg, "%llu%c", &opts.min_size, &unit) < 1) {
jlog(JLOG_ERROR, "Invalid option given to -s: %s", optarg);
return 1;
}
switch (tolower(unit)) {
case '\0':
break;
case 't':
opts.min_size *= 1024;
case 'g':
opts.min_size *= 1024;
case 'm':
opts.min_size *= 1024;
case 'k':
opts.min_size *= 1024;
break;
default:
jlog(JLOG_ERROR, "Unknown unit indicator %c.", unit);
return 1;
}
jlog(JLOG_DEBUG1, "Using minimum size of %lld bytes.",
opts.min_size);
opts.min_size = strtosize_or_err(optarg, _("failed to parse size"));
break;
case 'h':