From f81340273fa6d7e87a5b9a032626d69b863cf679 Mon Sep 17 00:00:00 2001 From: Daniel Friesel Date: Sun, 16 Feb 2014 11:09:28 +0100 Subject: add -x / --one-file-system option --- Changelog | 1 + bin/hashl | 36 ++++++++++++++++++++++++++---------- 2 files changed, 27 insertions(+), 10 deletions(-) diff --git a/Changelog b/Changelog index 433930c..93ad14e 100644 --- a/Changelog +++ b/Changelog @@ -2,6 +2,7 @@ git HEAD * Set read size to 0 (zero) to hash whole files * Fix find-new and find-known output so it can be piped to other commands + * Add -x / --one-file-system option hashl 1.00 - Wed Nov 02 2011 diff --git a/bin/hashl b/bin/hashl index 39b76ef..2002973 100755 --- a/bin/hashl +++ b/bin/hashl @@ -24,6 +24,7 @@ my $db_file = '.hashl.db'; my $total = 0; my $cur = 0; my $show_progress = 1; +my $xdev_fsno; my @edb_files; my $timer; my $incoming_dir; @@ -38,12 +39,13 @@ our $VERSION = '1.00'; STDERR->autoflush(1); GetOptions( - 'd|database=s' => \$db_file, - 'e|extra-db=s' => \@edb_files, - '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 }, + 'd|database=s' => \$db_file, + 'e|extra-db=s' => \@edb_files, + '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 }, + 'x|one-file-system' => sub { $xdev_fsno = ( stat($base) )[0] }, ) or usage(); if ( substr( $db_file, 0, 1 ) ne q{/} ) { @@ -91,7 +93,11 @@ sub quit_save_db { sub get_total { my $file = $File::Find::name; - if ( -f $file and not -l $file and $file ne $db_file ) { + if ( -f $file + and not -l $file + and $file ne $db_file + and ( not $xdev_fsno or ( stat($file) )[0] == $xdev_fsno ) ) + { $total++; } @@ -183,7 +189,11 @@ sub process_file { my $file = $File::Find::name; my $path = $file; - if ( not -f $file or -l $file or $file eq $db_file ) { + if ( not -f $file + or -l $file + or $file eq $db_file + or ( $xdev_fsno and ( stat($file) )[0] != $xdev_fsno ) ) + { return; } @@ -450,7 +460,7 @@ B - Create database with partial file hashes, check if other files are in =head1 SYNOPSIS -B [B<-fn>] [B<-d> I] [B<-s> I] I [I] +B [B<-fnx>] [B<-d> I] [B<-s> I] I [I] =head1 VERSION @@ -547,6 +557,12 @@ with a database. Print version information. +=item B<-x>|B<--one-file-system> + +Do not cross filesystem boundaries when processing files. At the time of this +writing, this may not prevent hashl from recursing into other filesystems, +but they will never be hashed, copied or otherwise processed. + =back =head1 EXIT STATUS @@ -571,7 +587,7 @@ None, so far =head1 BUGS AND LIMITATIONS -Unknown. This is beta software. +Unknown. =head1 EXAMPLES -- cgit v1.2.3