summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Changelog2
-rwxr-xr-xbin/hashl12
-rw-r--r--lib/App/Hashl.pm17
-rw-r--r--t/29-app-hashl.t15
4 files changed, 36 insertions, 10 deletions
diff --git a/Changelog b/Changelog
index f670ef5..5086df9 100644
--- a/Changelog
+++ b/Changelog
@@ -4,6 +4,8 @@ git HEAD
* hashl update no longer re-adds ignored (but existing) files
* hashl update now saves its state when being interrupted
(sigint/sigterm)
+ * add hashl -f update - update db, unignore and add any ignored files in
+ the scanned directory
hashl 0.1 - Fri May 06 2011
diff --git a/bin/hashl b/bin/hashl
index ec93f24..ca81dcd 100755
--- a/bin/hashl
+++ b/bin/hashl
@@ -14,6 +14,7 @@ use Getopt::Long;
use IO::Handle;
use Time::Progress;
+my $add_unignore = 0;
my $base = getcwd();
my $rel_paths = 1;
my $db_file = '.hashl.db';
@@ -33,6 +34,7 @@ STDERR->autoflush(1);
GetOptions(
'd|database=s' => \$db_file,
+ 'f|force' => \$add_unignore,
'n|no-progress' => sub { $show_progress = 0 },
's|read-size=i' => sub { $read_size = $_[1] * 1024 },
'V|version' => sub { say "hashl version ${VERSION}"; exit 0 },
@@ -186,8 +188,9 @@ sub db_update {
my ( $file, $path ) = @_;
$hashl->add_file(
- file => $file,
- path => $path,
+ file => $file,
+ path => $path,
+ unignore => $add_unignore,
);
return;
@@ -467,6 +470,11 @@ directory.
Use I<dbfile> instead of F<.hashl.db>
+=item B<-f>|B<--force>
+
+For use with C<< hashl add >>: If there are ignored files in the directory,
+unignore and add them.
+
=item B<-n>|B<--no-progress>
Do not show progress information. Most useful with C<< hashl find-new >>.
diff --git a/lib/App/Hashl.pm b/lib/App/Hashl.pm
index da06693..f1fc299 100644
--- a/lib/App/Hashl.pm
+++ b/lib/App/Hashl.pm
@@ -112,9 +112,9 @@ sub files {
}
sub add_file {
- my ( $self, %data ) = @_;
- my $file = $data{file};
- my $path = $data{path};
+ my ( $self, %opt ) = @_;
+ my $file = $opt{file};
+ my $path = $opt{path};
my ( $size, $mtime ) = ( stat($path) )[ 7, 9 ];
if ( $self->file($file)
@@ -127,7 +127,12 @@ sub add_file {
my $hash = $self->hash_file($path);
if ( $self->{ignored}->{$hash} ) {
- return;
+ if ( $opt{unignore} ) {
+ $self->unignore($hash);
+ }
+ else {
+ return;
+ }
}
$self->{files}->{$file} = {
@@ -159,9 +164,9 @@ sub ignore {
}
sub unignore {
- my ( $self, $path ) = @_;
+ my ( $self, $hash ) = @_;
- delete $self->{ignored}->{ $self->hash_file($path) };
+ delete $self->{ignored}->{$hash};
return 1;
}
diff --git a/t/29-app-hashl.t b/t/29-app-hashl.t
index e5b6fe3..4fc1a5f 100644
--- a/t/29-app-hashl.t
+++ b/t/29-app-hashl.t
@@ -3,7 +3,7 @@ use strict;
use warnings;
use 5.010;
-use Test::More tests => 35;
+use Test::More tests => 38;
use_ok('App::Hashl');
@@ -84,11 +84,22 @@ $hashl->add_file(
is_deeply([$hashl->files()], [], 'ignored file not added');
-$hashl->unignore('t/in/1k');
+$hashl->unignore($hashl->hash_file('t/in/1k'));
is_deeply([$hashl->ignored()], [$test_hash], 'unignore worked');
ok(
$hashl->add_file(
+ file => 't/in/4',
+ path => 't/in/4',
+ unignore => 1,
+ ),
+ 'Forcefully re-add file to db (unignore => 1)'
+);
+is_deeply([$hashl->ignored()], [], 'add(unignore => 1) unignore worked');
+is_deeply([$hashl->files()], ['t/in/4'], 'add(unignore => 1) add worked');
+
+ok(
+ $hashl->add_file(
file => 't/in/1k',
path => 't/in/1k',
),