# HG changeset patch # User Matthias Förste foerste@schlittermann.de # Date 1335429770 -7200 # Node ID 5bb3d096ca223a6074777b36a10f12deaf5bea32 # Parent a774bc526f8c149900911318d7908edd17206f66 [savepoint] diff -r a774bc526f8c -r 5bb3d096ca22 .hgignore --- a/.hgignore Tue Apr 24 16:50:45 2012 +0200 +++ b/.hgignore Thu Apr 26 10:42:50 2012 +0200 @@ -1,5 +1,5 @@ syntax: glob -wiegand-mkstruct.map.pl +wgnd-mkstruct.map.pl Build _build/ blib/ diff -r a774bc526f8c -r 5bb3d096ca22 Build.PL --- a/Build.PL Tue Apr 24 16:50:45 2012 +0200 +++ b/Build.PL Thu Apr 26 10:42:50 2012 +0200 @@ -1,7 +1,7 @@ # 'script_files' requires 0.18 use Module::Build 0.18; my $build = Module::Build->new( - module_name => 'IUS::WiegandMkStruct', + module_name => 'IUS::wgndMkStruct', create_license => 1, license => 'gpl3', requires => { @@ -9,7 +9,7 @@ 'Pod::Usage' => 0, 'Linux::Inotify2' => 0 }, - script_files => ['wiegand-mkstruct'], - dist_version_from => 'wiegand-mkstruct' + script_files => ['wgnd-mkstruct'], + dist_version_from => 'wgnd-mkstruct' ); $build->create_build_script; diff -r a774bc526f8c -r 5bb3d096ca22 MANIFEST.SKIP --- a/MANIFEST.SKIP Tue Apr 24 16:50:45 2012 +0200 +++ b/MANIFEST.SKIP Thu Apr 26 10:42:50 2012 +0200 @@ -45,6 +45,4 @@ \bBuild.COM$ \bBUILD.COM$ \bbuild.com$ - -# Avoid archives of this distribution \bIUS-WiegandMkStruct-[\d\.\_]+ diff -r a774bc526f8c -r 5bb3d096ca22 wgnd-mkstruct --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/wgnd-mkstruct Thu Apr 26 10:42:50 2012 +0200 @@ -0,0 +1,137 @@ +#!/usr/bin/perl + +# Copyright (C) 2012 Matthias Förste +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . +# +# Matthias Förste + +=encoding utf8 +=cut + +use strict; +use warnings; + +my $VERSION = '0.1'; +my $ME = $0; +use Getopt::Long; +use Pod::Usage; +use Linux::Inotify2; +# File::Rsync in squeeze does not support --xattrs yet +#use File::Rsync; + +my $map = 'wgnd-mkstruct.map.pl'; + +sub trace { print @_ if $ENV{DEBUG}; } + +GetOptions( + "map=s" => \$map, + "h|help" => sub { pod2usage( -verbose => 0, -exitval => 0 ) }, + "m|man" => sub { + pod2usage( + -verbose => 2, + -exitval => 0, + -noperldoc => ( `perldoc -V 2>/dev/null`, $? != 0 )[-1] + ); + }, +) or pod2usage(); + +our $source; +use lib ('.', $ENV{HOME}, '/etc'); +require $map; + +my $inotify = new Linux::Inotify2 + or die "Can't create new inotify object: $!"; +my @rsync = qw(/usr/bin/rsync -ihv -aAX); + +for (keys %{$source}) { + + # add watchers + $inotify->watch ("$_", IN_CREATE, sub { + + my $pid = fork; + + if (not defined $pid) { + warn "Can't fork: $!\n"; + } elsif ($pid == 0) { + my $e = shift; + my $name = $e->fullname; + print "$name was created\n" if $e->IN_CREATE; + print "$name is no longer mounted\n" if $e->IN_UNMOUNT; + print "$name is gone\n" if $e->IN_IGNORED; + print "events for $name have been lost\n" if $e->IN_Q_OVERFLOW; + exec @rsync, $source->{$e->{w}->{name}}, $name; + warn "Can't exec: $!\n"; + } + + }) or die "Can't add watch: $!\n"; +} + +while (1) { + + $inotify->poll; + while (-1 != (my $pid = wait)) { + my $e = $? >> 8; + print "${ME}[$pid]: exit $e\n"; + } + +} + + +__END__ + +=pod + +=head1 NAME + +wgnd-mkstruct - instantiate a directory structure template + +=head1 SYNOPSIS + +wgnd-mkstruct [--map filename] + +wgnd-mkstruct -m|--man + -h|--help + +=head1 DESCRIPTION + +wgnd-mkstruct watches some directories for newly created subdirectories and +synchronises these from a given template directory. + +=head1 OPTIONS + +=over + +=item B<--map> I + +Name of a file containing mappings between templates and directories. Defaults +to F. + +=back + +=head1 FILES + +=over + +=item F + +default for B<--map> + +=back + +=head1 AUTHOR + +Matthias Förste + +=cut diff -r a774bc526f8c -r 5bb3d096ca22 wgnd-mkstruct.map.pl.ex --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/wgnd-mkstruct.map.pl.ex Thu Apr 26 10:42:50 2012 +0200 @@ -0,0 +1,3 @@ +our $source = { + '/tmp' => './' +}; diff -r a774bc526f8c -r 5bb3d096ca22 wiegand-mkstruct --- a/wiegand-mkstruct Tue Apr 24 16:50:45 2012 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,137 +0,0 @@ -#!/usr/bin/perl - -# Copyright (C) 2012 Matthias Förste -# -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program. If not, see . -# -# Matthias Förste - -=encoding utf8 -=cut - -use strict; -use warnings; - -my $VERSION = '0.1'; -my $ME = $0; -use Getopt::Long; -use Pod::Usage; -use Linux::Inotify2; -# File::Rsync in squeeze does not support --xattrs yet -#use File::Rsync; - -my $map = 'wiegand-mkstruct.map.pl'; - -sub trace { print @_ if $ENV{DEBUG}; } - -GetOptions( - "map=s" => \$map, - "h|help" => sub { pod2usage( -verbose => 0, -exitval => 0 ) }, - "m|man" => sub { - pod2usage( - -verbose => 2, - -exitval => 0, - -noperldoc => ( `perldoc -V 2>/dev/null`, $? != 0 )[-1] - ); - }, -) or pod2usage(); - -our $source; -use lib ('.', $ENV{HOME}, '/etc'); -require $map; - -my $inotify = new Linux::Inotify2 - or die "Can't create new inotify object: $!"; -my @rsync = qw(/usr/bin/rsync -ihv -aAX); - -for (keys %{$source}) { - - # add watchers - $inotify->watch ("$_", IN_CREATE, sub { - - my $pid = fork; - - if (not defined $pid) { - warn "Can't fork: $!\n"; - } elsif ($pid == 0) { - my $e = shift; - my $name = $e->fullname; - print "$name was created\n" if $e->IN_CREATE; - print "$name is no longer mounted\n" if $e->IN_UNMOUNT; - print "$name is gone\n" if $e->IN_IGNORED; - print "events for $name have been lost\n" if $e->IN_Q_OVERFLOW; - exec @rsync, $source->{$e->{w}->{name}}, $name; - warn "Can't exec: $!\n"; - } - - }) or die "Can't add watch: $!\n"; -} - -while (1) { - - $inotify->poll; - while (-1 != (my $pid = wait)) { - my $e = $? >> 8; - print "${ME}[$pid]: exit $e\n"; - } - -} - - -__END__ - -=pod - -=head1 NAME - -wiegand-mkstruct - instantiate a directory structure template - -=head1 SYNOPSIS - -wiegand-mkstruct [--map filename] - -wiegand-mkstruct -m|--man - -h|--help - -=head1 DESCRIPTION - -wiegand-mkstruct watches some directories for newly created subdirectories and -synchronises these from a given template directory. - -=head1 OPTIONS - -=over - -=item B<--map> I - -Name of a file containing mappings between templates and directories. Defaults -to F. - -=back - -=head1 FILES - -=over - -=item F - -default for B<--map> - -=back - -=head1 AUTHOR - -Matthias Förste - -=cut diff -r a774bc526f8c -r 5bb3d096ca22 wiegand-mkstruct.map.pl.ex --- a/wiegand-mkstruct.map.pl.ex Tue Apr 24 16:50:45 2012 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,3 +0,0 @@ -our $source = { - '/tmp' => './' -};