diff options
author | Daniel Friesel <derf@finalrewind.org> | 2010-12-31 12:40:18 +0100 |
---|---|---|
committer | Daniel Friesel <derf@finalrewind.org> | 2010-12-31 12:40:18 +0100 |
commit | fd438a0f26f3a4da414c8069213c608c74abb7b1 (patch) | |
tree | 392bbe6e770a547b4ee57c22f74f2ed06bc6bf57 /bin | |
parent | 0a88b5eb9ad126175317572e383930f52424757c (diff) |
Add 'hashl ignore' function
Diffstat (limited to 'bin')
-rwxr-xr-x | bin/hashl | 59 |
1 files changed, 59 insertions, 0 deletions
@@ -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(); } |