#!/usr/bin/perl -lw # FAM test # 2004.01.31 altblue@n0i.net package N0i::FAM::Chmod; use strict; use SGI::FAM qw(FAM_DEBUG_VERBOSE); use File::Spec; use constant DEBUG => 1; ### BEGIN Configuration my $MODS = { FILE => '0664', DIR => '0775', }; my $MON_DEPTH = 10; ### END Configuration my $fam = SGI::FAM->new(__PACKAGE__) or die "ERROR: $!\n"; { $fam->debug_level(FAM_DEBUG_VERBOSE) if DEBUG; $fam->monitor($_) foreach @ARGV; my @monitored = $fam->monitored; die "Nothing to monitor!\n" unless @monitored; local $" = "$/\t"; warn qq{Monitoring:$"@monitored$/} if DEBUG; } sub chmod_it { my $file = shift || return; my $tomod = (-d $file) ? $MODS->{DIR} : $MODS->{FILE}; my $mode = sprintf "%04o", (stat($file))[2] & 07777; return if $tomod eq $mode; warn "Chmodding $file$/" if DEBUG; chmod oct($tomod), $file or warn "Chmod Error: $! ($file)\n"; } my $ev; while (1) { do { $ev = $fam->next_event; if ($ev->type =~ /^(?:change|create)$/) { chmod_it(File::Spec->catfile($fam->which($ev), $ev->filename)); } } while $fam->pending; } __END__