summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xbin/hashl59
1 files changed, 59 insertions, 0 deletions
diff --git a/bin/hashl b/bin/hashl
index bc2fc2c..aa38749 100755
--- a/bin/hashl
+++ b/bin/hashl
@@ -92,6 +92,14 @@ sub hash_file {
sub hash_in_db {
my ($hash) = @_;
+ if ($db->{'ignored'}->{'hashes'}) {
+ for my $ihash (@{$db->{'ignored'}->{'hashes'}}) {
+ if ($hash eq $ihash) {
+ return '// ignored';
+ }
+ }
+ }
+
for my $name (keys %{$db->{'files'}}) {
my $file = $db->{'files'}->{$name};
@@ -184,6 +192,30 @@ sub process_file {
}
}
+sub ignore_file {
+ my $file = $File::Find::name;
+
+ if (not -f $file or -l $file or $file eq $db_file) {
+ return;
+ }
+
+ my $hash = hash_file($file);
+
+ $cur++;
+
+ print $timer->report("\r\e[2KUpdating: %p done, %L elapsed, %E remaining", $cur);
+
+ if (hash_in_db($hash)) {
+ return;
+ }
+
+ push(@{$db->{'ignored'}->{'hashes'}}, $hash);
+
+ if (($cur % 100) == 0) {
+ nstore($db, $db_file);
+ }
+}
+
sub mkdirs {
my ($base, $new) = @_;
@@ -245,6 +277,13 @@ elsif ($action eq 'list') {
printf("%s %s\n", $file->{'hash'}, $name);
}
}
+elsif ($action eq 'list-ignored') {
+ if (exists $db->{'ignored'}->{'hashes'}) {
+ for my $hash (@{$db->{'ignored'}->{'hashes'}}) {
+ say $hash;
+ }
+ }
+}
elsif ($action ~~ [qw[know-file know-hash new-file new-hash]]) {
db_find();
}
@@ -279,6 +318,26 @@ elsif ($action eq 'copy') {
find(\&maybe_copy_file, $base);
print "\n";
}
+elsif ($action eq 'ignore') {
+ my $ign_dir = $ARGV[1] // $base;
+
+ if (substr($ign_dir, 0, 1) ne '/') {
+ $ign_dir = $base . '/' . $ign_dir;
+ }
+
+ STDOUT->autoflush(1);
+ find(\&get_total, $base);
+
+ $timer = Time::Progress->new();
+ $timer->attr(
+ min => 1,
+ max => $total,
+ );
+
+ find(\&ignore_file, $base);
+ nstore($db, $db_file);
+ print "\n";
+}
else {
usage();
}