aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Ryder <tom@sanctum.geek.nz>2020-07-04 21:43:28 +1200
committerTom Ryder <tom@sanctum.geek.nz>2020-07-04 21:43:28 +1200
commit156999d0afae395f018cf3cec167d3973051c2b7 (patch)
treee5b1703641ae19417ec12eee7d612f43e5fdb011
parentMerge branch 'hotfix/v0.06' (diff)
parentBump VERSION (diff)
downloadinotifymask-156999d0afae395f018cf3cec167d3973051c2b7.tar.gz
inotifymask-156999d0afae395f018cf3cec167d3973051c2b7.zip
Merge branch 'release/v0.07'
* release/v0.07: Iterate through subdirectories
-rw-r--r--Makefile.PL1
-rw-r--r--bin/inotifymask24
2 files changed, 18 insertions, 7 deletions
diff --git a/Makefile.PL b/Makefile.PL
index 0bfc6f3..bfa5d9b 100644
--- a/Makefile.PL
+++ b/Makefile.PL
@@ -15,6 +15,7 @@ WriteMakefile(
},
PREREQ_PM => {
'Const::Fast' => 0,
+ 'File::Find' => 0,
'File::stat' => 0,
'Linux::Inotify2' => 0,
},
diff --git a/bin/inotifymask b/bin/inotifymask
index 8c8ad98..39b9c03 100644
--- a/bin/inotifymask
+++ b/bin/inotifymask
@@ -6,25 +6,35 @@ use warnings;
use utf8;
use Const::Fast;
+use File::Find;
use File::stat;
use Linux::Inotify2;
-our $VERSION = '0.06';
+our $VERSION = '0.07';
const our $SELF => 'inotifymask';
# Mask to remove the bits of stat->mode that we don't care about
const our $STAT_MASK => oct '07777';
-# Check argument count
+# Check argument count after processing options
if ( @ARGV < 2 ) {
- printf {*STDERR} "%s: Need a mask and at least one file\n", $SELF;
+ printf {*STDERR} "%s: Need a mask and at least one path\n", $SELF;
exit 2;
}
-# Shift off mask as octal, remaining arguments are files
+# Shift off mask as octal, remaining arguments are paths
my $mask = oct shift;
-my @files = @ARGV;
+my %paths = map { $_ => undef } @ARGV;
+
+# Expand paths list to include all subdirectories
+my $wanted = sub {
+ for ($File::Find::name) {
+ return if !-d;
+ $paths{$_} = undef;
+ }
+};
+find( $wanted, keys %paths );
# Process creation and move-in events
my $cb = sub {
@@ -43,7 +53,7 @@ my $cb = sub {
my $stat = stat $name
or return;
- # Get the mode we want for the file, masking off irrelevant file type bits
+ # Get the mode we want for the path, masking off irrelevant path type bits
my $mode = $stat->mode & $STAT_MASK;
#
@@ -65,7 +75,7 @@ my $cb = sub {
# Create object and set up watches with callback, start polling
my $in = Linux::Inotify2->new;
-for (@files) {
+for ( keys %paths ) {
$in->watch( $_, IN_ATTRIB | IN_CREATE | IN_MOVED_TO, $cb );
}
while (1) {