Skip to content

Commit

Permalink
Add --cached option to speed up matching against files previously sca…
Browse files Browse the repository at this point in the history
…nned.
  • Loading branch information
adrianlopezroche committed Nov 5, 2022
1 parent 84765e0 commit ab5ef95
Show file tree
Hide file tree
Showing 19 changed files with 1,912 additions and 70 deletions.
12 changes: 12 additions & 0 deletions Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,19 @@ fdupes_SOURCES += filegroup.h\
positive_wcwidth.c\
positive_wcwidth.h
dist_man7_MANS = fdupes-help.7
endif

if WITH_SQLITE
fdupes_SOURCES += getrealpath.c\
getrealpath.h\
sdirname.c\
sdirname.h\
sbasename.c\
sbasename.h\
xdgbase.c\
xdgbase.h\
hashdb.c\
hashdb.h
endif

EXTRA_DIST = testdir CHANGES CONTRIBUTORS
Expand Down
20 changes: 20 additions & 0 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
[AC_DEFINE([_XOPEN_SOURCE], [700], [enable certain X/Open and POSIX features])]
)

#
# NCURSES library
#
AC_ARG_WITH([ncurses], AS_HELP_STRING([--without-ncurses], [Do not use ncurses interface]))

AC_CHECK_HEADERS([getopt.h ncursesw/curses.h])
Expand All @@ -42,6 +45,19 @@ AS_IF([test x"$with_ncurses" != x"no"],

AM_CONDITIONAL([WITH_NCURSES], [test x"$with_ncurses" != x"no"])

#
# SQLITE library
#
AC_ARG_WITH([sqlite], AS_HELP_STRING([--without-sqlite], [Do not use sqlite database]))

AS_IF([test x"$with_sqlite" != x"no"],
[AC_SEARCH_LIBS([sqlite3_prepare_v2], [sqlite3], [], [AC_ERROR([sqlite3 library not found])])],

[AC_DEFINE([NO_SQLITE], [], [Do not compile against sqlite])]
)

AM_CONDITIONAL([WITH_SQLITE], [test x"$with_sqlite" != x"no"])

unescaped_program_transform_name=`echo "${program_transform_name}"|sed -e "s&\\\\$\\\\$&\\\\$&g"`
transformed_program_name=`echo "${PACKAGE_NAME}"|sed -e "${unescaped_program_transform_name}"|sed -e "s&\\\\\\\\&\\\\\\\\\\\\\\\\&g"`
transformed_manpage_name=`echo "${PACKAGE_NAME}-help"|sed -e "${unescaped_program_transform_name}"`
Expand All @@ -54,6 +70,10 @@ AC_DEFINE([CHUNK_SIZE], [8192], [number of bytes to read per read call])
AC_DEFINE([PARTIAL_MD5_SIZE], [4096], [maximum number of bytes to use when calculating partial hashes])
AC_DEFINE([INPUT_SIZE], [256], [size of command buffer (plain interactive mode only)])

AC_DEFINE([FDUPES_CACHE_DIRECTORY], ["fdupes"], [default subdirectory for fdupes config files])
AC_DEFINE([FDUPES_CACHE_DIRECTORY_PERMISSIONS], [0700], [directory permissions for fdupes config directory])
AC_DEFINE([FDUPES_HASH_DATABASE_NAME], ["hash.db"], [filename for fdupes hash database])

AC_CONFIG_FILES([Makefile])
AC_PROG_CC
AC_OUTPUT
8 changes: 8 additions & 0 deletions confirmmatch.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */

#include "config.h"
#include "sigint.h"
#include "confirmmatch.h"
#include <stdlib.h>
#include <memory.h>

/* Do a bit-for-bit comparison in case two different files produce the
Expand All @@ -37,6 +39,12 @@ int confirmmatch(FILE *file1, FILE *file2)
fseek(file2, 0, SEEK_SET);

do {
if (got_sigint) {
fclose(file1);
fclose(file2);
exit(0);
}

r1 = fread(c1, sizeof(unsigned char), sizeof(c1), file1);
r2 = fread(c2, sizeof(unsigned char), sizeof(c2), file2);

Expand Down
33 changes: 31 additions & 2 deletions fdupes.1
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,33 @@ Consider only files greater than or equal to SIZE in bytes.
.B -L --maxsize\fR=\fISIZE\fR
Consider only files less than or equal to SIZE in bytes.
.TP
.B -c --cache
Speed up file comparisons by keeping track of their signatures in a
database; additional parameters may be provided using one or more
cache parameters (as indicated below). Please note that this option
may not be available on some systems.
.TP
.B -x cache.\fIOPTION\fR
Supply an optional cache parameter, where OPTION is one of the keywords
below and multiple options may be supplied via successive -x arguments:

\fIreadonly\fR
read but do not update file signatures

\fIprune\fR
look through entire cache and delete orphaned entries

\fIclear\fR
clear all entries from cache

\fIvacuum\fR
reduce size of DB file, if possible

The options prune, clear, and vacuum may be employed without
supplying a DIRECTORY argument, and will take effect even if readonly
is also specified. The order of operations is always clear, prune,
update signatures (unless readonly), and vacuum.
.TP
.B -n --noempty
Exclude zero-length files from consideration.
.TP
Expand Down Expand Up @@ -73,8 +100,10 @@ In interactive mode, defer byte-for-byte confirmation of
duplicates until just before file deletion.
.TP
.B -P --plain
With --delete, use line-based prompt (as with older versions of
fdupes) instead of screen-mode interface.
With --delete, use a line-based prompt (as with older versions of
fdupes) instead of the new screen-mode interface. On installations
where the screen-mode interface is not supported, fdupes will
default to a line-based prompt.
.TP
.B -N --noprompt
When used together with \-\-delete, preserve the first file in each
Expand Down
Loading

0 comments on commit ab5ef95

Please sign in to comment.