summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Build.PL1
-rwxr-xr-xbin/hashl49
2 files changed, 28 insertions, 22 deletions
diff --git a/Build.PL b/Build.PL
index d3f575c..36c75aa 100644
--- a/Build.PL
+++ b/Build.PL
@@ -19,6 +19,7 @@ my $build = Module::Build->new(
'Digest::SHA' => 0,
'File::Find' => 0,
'Getopt::Long' => 0,
+ 'IO::Handle' => 0,
'Storable' => 0,
'Time::Progress' => 0,
},
diff --git a/bin/hashl b/bin/hashl
index 1f3af74..ba2dcb5 100755
--- a/bin/hashl
+++ b/bin/hashl
@@ -11,6 +11,7 @@ use Cwd;
use Digest::SHA qw(sha1_hex);
use File::Find;
use Getopt::Long;
+use IO::Handle;
use Storable qw(nstore retrieve);
use Time::Progress;
@@ -95,6 +96,29 @@ sub file_in_db {
return hash_in_db(hash_file($file));
}
+sub db_find {
+ if ($ARGV[1]) {
+ given ($action) {
+ when ('know-file') { exit (not defined file_in_db($ARGV[1])) }
+ when ('know-hash') { exit (not defined hash_in_db($ARGV[1])) }
+ when ('new-file') { exit (defined file_in_db($ARGV[1])) }
+ when ('new-hash') { exit (defined hash_in_db($ARGV[1])) }
+ }
+ }
+ else {
+ while (my $line = <STDIN>) {
+ chomp $line;
+ if (
+ ($action eq 'know-file' and file_in_db($line)) or
+ ($action eq 'know-hash' and hash_in_db($line)) or
+ ($action eq 'new-file' and not file_in_db($line)) or
+ ($action eq 'new-hash' and not hash_in_db($line))) {
+ say $line;
+ }
+ }
+ }
+}
+
sub db_info {
printf(
"Read size: %d bytes (%.f KiB)\n",
@@ -119,8 +143,6 @@ sub process_file {
my $path = $file;
my ($size, $mtime) = (stat($file))[7,9];
- local $| = 1;
-
if (not -f $file or -l $file or $file eq $db_file) {
return;
}
@@ -152,6 +174,8 @@ sub process_file {
if ($action eq 'update') {
+ STDOUT->autoflush(1);
+
drop_deleted();
find(\&get_total, $base);
@@ -172,26 +196,7 @@ elsif ($action eq 'list') {
}
}
elsif ($action ~~ [qw[know-file know-hash new-file new-hash]]) {
- if ($ARGV[1]) {
- given ($action) {
- when ('know-file') { exit (not defined file_in_db($ARGV[1])) }
- when ('know-hash') { exit (not defined hash_in_db($ARGV[1])) }
- when ('new-file') { exit (defined file_in_db($ARGV[1])) }
- when ('new-hash') { exit (defined hash_in_db($ARGV[1])) }
- }
- }
- else {
- while (my $line = <STDIN>) {
- chomp $line;
- if (
- ($action eq 'know-file' and file_in_db($line)) or
- ($action eq 'know-hash' and hash_in_db($line)) or
- ($action eq 'new-file' and not file_in_db($line)) or
- ($action eq 'new-hash' and not hash_in_db($line))) {
- say $line;
- }
- }
- }
+ db_find();
}
elsif ($action eq 'info') {
if ($ARGV[1]) {