Created
December 19, 2013 00:49
-
-
Save Orangenhain/8032471 to your computer and use it in GitHub Desktop.
patch to add `minimum file size` option to duff
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
From d94859fa294d9974563b48195b7430a36c15d651 Mon Sep 17 00:00:00 2001 | |
From: OrangeRaven <apfelsinenhain@gmx.de> | |
Date: Thu, 19 Dec 2013 01:45:16 +0100 | |
Subject: [PATCH] Add option option for minimum file size ( `-m _size_` ) ... | |
don't check files smaller than this. | |
--- | |
src/duff.c | 16 ++++++++++++++-- | |
src/duffdriver.c | 6 +++++- | |
2 files changed, 19 insertions(+), 3 deletions(-) | |
diff --git a/src/duff.c b/src/duff.c | |
index ac1a22d..8b28573 100644 | |
--- a/src/duff.c | |
+++ b/src/duff.c | |
@@ -139,6 +139,10 @@ int header_uses_digest = 0; | |
*/ | |
off_t sample_limit = 0; | |
+/* Specifies the minimal size of files to be compared with the sampling method. | |
+ */ | |
+off_t min_file_size = 0; | |
+ | |
/* These functions are documented below, where they are defined. | |
*/ | |
static void version(void); | |
@@ -161,7 +165,7 @@ static void version(void) | |
*/ | |
static void usage(void) | |
{ | |
- printf(_("Usage: %s [-0DHLPaepqrtuz] [-d function] [-f format] [-l size] [file ...]\n"), | |
+ printf(_("Usage: %s [-0DHLPaepqrtuz] [-d function] [-f format] [-l size] [-m size] [file ...]\n"), | |
PACKAGE_NAME); | |
printf(" %s -h\n", PACKAGE_NAME); | |
@@ -179,6 +183,7 @@ static void usage(void) | |
printf(_(" -f format for cluster headers\n")); | |
printf(_(" -h show this help\n")); | |
printf(_(" -l the minimum size that activates sampling\n")); | |
+ printf(_(" -m minimum size; files smaller than this will be ignored\n")); | |
printf(_(" -q quiet; suppress warnings and error messages\n")); | |
printf(_(" -p physical files; do not report multiple hard links as duplicates\n")); | |
printf(_(" -r search recursively through specified directories\n")); | |
@@ -208,7 +213,7 @@ int main(int argc, char** argv) | |
bindtextdomain(PACKAGE, LOCALEDIR); | |
textdomain(PACKAGE); | |
- while ((ch = getopt(argc, argv, "0DHLPad:ef:hl:pqrtuvz")) != -1) | |
+ while ((ch = getopt(argc, argv, "0DHLPad:ef:hl:m:pqrtuvz")) != -1) | |
{ | |
switch (ch) | |
{ | |
@@ -251,6 +256,13 @@ int main(int argc, char** argv) | |
else | |
sample_limit = limit; | |
break; | |
+ case 'm': | |
+ limit = (off_t) strtoull(optarg, &temp, 10); | |
+ if (temp == optarg || errno == ERANGE || errno == EINVAL) | |
+ warning(_("Ignoring invalid minimum file size %s"), optarg); | |
+ else | |
+ min_file_size = limit; | |
+ break; | |
case 'p': | |
physical_flag = 1; | |
break; | |
diff --git a/src/duffdriver.c b/src/duffdriver.c | |
index a300858..39cd9da 100644 | |
--- a/src/duffdriver.c | |
+++ b/src/duffdriver.c | |
@@ -105,6 +105,7 @@ extern int physical_flag; | |
extern int excess_flag; | |
extern const char* header_format; | |
extern int header_uses_digest; | |
+extern off_t min_file_size; | |
/* Represents a single physical directory. | |
*/ | |
@@ -333,7 +334,10 @@ static void process_file(const char* path, struct stat* sb) | |
if (ignore_empty_flag) | |
return; | |
} | |
- | |
+ | |
+ if (sb->st_size < min_file_size) | |
+ return; | |
+ | |
/* NOTE: Check for duplicate arguments? */ | |
if (physical_flag) | |
-- | |
1.7.11.1 | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment