From a6d571bed52b7a6a66ea21ce8dbe38dbe382e8f5 Mon Sep 17 00:00:00 2001 From: Daniel Friesel Date: Sun, 19 Aug 2012 12:43:17 +0200 Subject: find-new / find-known: Support multiple database files --- bin/hashl | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/bin/hashl b/bin/hashl index d3187c5..2ec73b9 100755 --- a/bin/hashl +++ b/bin/hashl @@ -12,6 +12,7 @@ use File::Copy; use File::Find; use Getopt::Long; use IO::Handle; +use List::MoreUtils qw(any); use Time::Progress; my $add_unignore = 0; @@ -28,6 +29,7 @@ my $read_size; my ( $find_ref, $find_db_write ); my $hashl; +my @ehashl; our $VERSION = '1.00'; @@ -65,6 +67,16 @@ if ( -r $db_file ) { else { $hashl = App::Hashl->new( read_size => $read_size ); } +@ehashl = ($hashl); + +for my $file (@edb_files) { + if (-r $file) { + push(@ehashl, App::Hashl->new_from_file($file)); + } + else { + die("-e ${file}: database does not exist\n"); + } +} local $SIG{INT} = \&quit_save_db; local $SIG{TERM} = \&quit_save_db; @@ -111,7 +123,7 @@ sub copy_file { sub db_find_new { my ( $file, $path ) = @_; - if ( not $hashl->file_in_db($path) ) { + if ( not any { $_->file_in_db($path) } @ehashl ) { say "\r\e[2K${file}"; } @@ -121,7 +133,7 @@ sub db_find_new { sub db_find_known { my ( $file, $path ) = @_; - if ( $hashl->file_in_db($path) ) { + if ( any { $_->file_in_db($path) } @ehashl ) { say "\r\e[2K${file}"; } @@ -425,12 +437,12 @@ I. =item B [I] -List all files which are already in the database. Scans either the current +List all files which are already in any database. Scans either the current directory or I. =item B [I] -List all files which are not in the database. Scans either the current +List all files which are not in any database. Scans either the current directory or I. =item B [I] @@ -473,6 +485,11 @@ directory. Use I instead of F<.hashl.db> +=item B<-e>|B<--extra-db> I + +Use I in addition to F<.hashl.db> / B<-d>. May be specified +several times. Does not affect all commands. + =item B<-f>|B<--force> For use with C<< hashl add >>: If there are ignored files in the directory, -- cgit v1.2.3