diff options
Diffstat (limited to 'lib/File/CheckTree.pm')
-rw-r--r-- | lib/File/CheckTree.pm | 114 |
1 files changed, 47 insertions, 67 deletions
diff --git a/lib/File/CheckTree.pm b/lib/File/CheckTree.pm index ae1877741b..8b6ae0805a 100644 --- a/lib/File/CheckTree.pm +++ b/lib/File/CheckTree.pm @@ -1,4 +1,7 @@ package File::CheckTree; + +our $VERSION = '4.1'; + require 5.000; require Exporter; @@ -41,39 +44,8 @@ The routine returns the number of warnings issued. =cut -@ISA = qw(Exporter); -@EXPORT = qw(validate); - -# $RCSfile: validate.pl,v $$Revision: 4.1 $$Date: 92/08/07 18:24:19 $ - -# The validate routine takes a single multiline string consisting of -# lines containing a filename plus a file test to try on it. (The -# file test may also be a 'cd', causing subsequent relative filenames -# to be interpreted relative to that directory.) After the file test -# you may put '|| die' to make it a fatal error if the file test fails. -# The default is '|| warn'. The file test may optionally have a ! prepended -# to test for the opposite condition. If you do a cd and then list some -# relative filenames, you may want to indent them slightly for readability. -# If you supply your own "die" or "warn" message, you can use $file to -# interpolate the filename. - -# Filetests may be bunched: -rwx tests for all of -r, -w and -x. -# Only the first failed test of the bunch will produce a warning. - -# The routine returns the number of warnings issued. - -# Usage: -# use File::CheckTree; -# $warnings += validate(' -# /vmunix -e || die -# /boot -e || die -# /bin cd -# csh -ex -# csh !-ug -# sh -ex -# sh !-ug -# /usr -d || warn "What happened to $file?\n" -# '); +our @ISA = qw(Exporter); +our @EXPORT = qw(validate); sub validate { local($file,$test,$warnings,$oldwarnings); @@ -94,7 +66,8 @@ sub validate { $this =~ s/(-\w\b)/$1 \$file/g; $this =~ s/-Z/-$one/; $this .= ' || warn' unless $this =~ /\|\|/; - $this =~ s/^(.*\S)\s*\|\|\s*(die|warn)$/$1 || valmess('$2','$1')/; + $this =~ s/^(.*\S)\s*\|\|\s*(die|warn)$/$1 || + valmess('$2','$1')/; $this =~ s/\bcd\b/chdir (\$cwd = \$file)/g; eval $this; last if $warnings > $oldwarnings; @@ -103,47 +76,54 @@ sub validate { $warnings; } +our %Val_Switch = ( + 'r' => sub { "$_[0] is not readable by uid $>." }, + 'w' => sub { "$_[0] is not writable by uid $>." }, + 'x' => sub { "$_[0] is not executable by uid $>." }, + 'o' => sub { "$_[0] is not owned by uid $>." }, + 'R' => sub { "$_[0] is not readable by you." }, + 'W' => sub { "$_[0] is not writable by you." }, + 'X' => sub { "$_[0] is not executable by you." }, + 'O' => sub { "$_[0] is not owned by you." }, + 'e' => sub { "$_[0] does not exist." }, + 'z' => sub { "$_[0] does not have zero size." }, + 's' => sub { "$_[0] does not have non-zero size." }, + 'f' => sub { "$_[0] is not a plain file." }, + 'd' => sub { "$_[0] is not a directory." }, + 'l' => sub { "$_[0] is not a symbolic link." }, + 'p' => sub { "$_[0] is not a named pipe (FIFO)." }, + 'S' => sub { "$_[0] is not a socket." }, + 'b' => sub { "$_[0] is not a block special file." }, + 'c' => sub { "$_[0] is not a character special file." }, + 'u' => sub { "$_[0] does not have the setuid bit set." }, + 'g' => sub { "$_[0] does not have the setgid bit set." }, + 'k' => sub { "$_[0] does not have the sticky bit set." }, + 'T' => sub { "$_[0] is not a text file." }, + 'B' => sub { "$_[0] is not a binary file." }, +); + sub valmess { - local($disposition,$this) = @_; - $file = $cwd . '/' . $file unless $file =~ m|^/|s; + my($disposition,$this) = @_; + my $file = $cwd . '/' . $file unless $file =~ m|^/|s; + + my $ferror; if ($this =~ /^(!?)-(\w)\s+\$file\s*$/) { - $neg = $1; - $tmp = $2; - $tmp eq 'r' && ($mess = "$file is not readable by uid $>."); - $tmp eq 'w' && ($mess = "$file is not writable by uid $>."); - $tmp eq 'x' && ($mess = "$file is not executable by uid $>."); - $tmp eq 'o' && ($mess = "$file is not owned by uid $>."); - $tmp eq 'R' && ($mess = "$file is not readable by you."); - $tmp eq 'W' && ($mess = "$file is not writable by you."); - $tmp eq 'X' && ($mess = "$file is not executable by you."); - $tmp eq 'O' && ($mess = "$file is not owned by you."); - $tmp eq 'e' && ($mess = "$file does not exist."); - $tmp eq 'z' && ($mess = "$file does not have zero size."); - $tmp eq 's' && ($mess = "$file does not have non-zero size."); - $tmp eq 'f' && ($mess = "$file is not a plain file."); - $tmp eq 'd' && ($mess = "$file is not a directory."); - $tmp eq 'l' && ($mess = "$file is not a symbolic link."); - $tmp eq 'p' && ($mess = "$file is not a named pipe (FIFO)."); - $tmp eq 'S' && ($mess = "$file is not a socket."); - $tmp eq 'b' && ($mess = "$file is not a block special file."); - $tmp eq 'c' && ($mess = "$file is not a character special file."); - $tmp eq 'u' && ($mess = "$file does not have the setuid bit set."); - $tmp eq 'g' && ($mess = "$file does not have the setgid bit set."); - $tmp eq 'k' && ($mess = "$file does not have the sticky bit set."); - $tmp eq 'T' && ($mess = "$file is not a text file."); - $tmp eq 'B' && ($mess = "$file is not a binary file."); + my($neg,$ftype) = ($1,$2); + + $ferror = $Val_Switch{$tmp}->($file); + if ($neg eq '!') { - $mess =~ s/ is not / should not be / || - $mess =~ s/ does not / should not / || - $mess =~ s/ not / /; + $ferror =~ s/ is not / should not be / || + $ferror =~ s/ does not / should not / || + $ferror =~ s/ not / /; } } else { $this =~ s/\$file/'$file'/g; - $mess = "Can't do $this.\n"; + $ferror = "Can't do $this.\n"; } - die "$mess\n" if $disposition eq 'die'; - warn "$mess\n"; + die "$ferror\n" if $disposition eq 'die'; + warn "$ferror\n"; ++$warnings; } |