aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Ryder <tom@sanctum.geek.nz>2020-07-04 21:42:00 +1200
committerTom Ryder <tom@sanctum.geek.nz>2020-07-04 21:42:00 +1200
commita99cd729d37109cad8db343a729ab2bf72f94c71 (patch)
tree83930354f39badc9f4feb292f26d82211a7e21f1
parentMerge branch 'hotfix/v0.06' into develop (diff)
downloadinotifymask-a99cd729d37109cad8db343a729ab2bf72f94c71.tar.gz
inotifymask-a99cd729d37109cad8db343a729ab2bf72f94c71.zip
Iterate through subdirectories
-rw-r--r--Makefile.PL1
-rw-r--r--bin/inotifymask22
2 files changed, 17 insertions, 6 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..5145183 100644
--- a/bin/inotifymask
+++ b/bin/inotifymask
@@ -6,6 +6,7 @@ use warnings;
use utf8;
use Const::Fast;
+use File::Find;
use File::stat;
use Linux::Inotify2;
@@ -16,15 +17,24 @@ 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) {