--- - Tue Jan 29 18:06:25 2002 +++ do_unlinks Fri Nov 2 20:29:14 2001 @@ -1,4 +1,4 @@ -#!/usr/bin/perl -s +#!/usr/bin/perl -w # # # @@ -30,19 +30,40 @@ # -a1 The original mirror used algorithm 1 so rmdir can safely delete # an entire directory tree +## Modified by Dirk Eddelbuettel in February 1999 +## to add more explicit command-line argument parsing + +use English; +use vars qw($opt_h $opt_d $opt_v $opt_n $opt_a); +use Getopt::Std; + +$PROGRAM_NAME =~ s|.*/||; # strip everything before last slash +$#ARGV >= 0 && getopts('hd:nva') && $#ARGV >= 0 or die("Try `$PROGRAM_NAME -h` for help screen.\n"); + + +if ($opt_h) { + print "Usage:\n $PROGRAM_NAME [options] [...path]\n"; + print "Options:\n"; + print " -d root\troot of the file tree\n"; + print " -a\t\talgorithm 1 was used, so we can delete entire tree\n"; + print " -n\t\tsimulate only what would be done, but don't do it\n"; + print " -v\t\tverbose operation, echo command before execution\n"; + print " -h\t\tshow this help\n"; + print "path\t\tpath to a mirror log file\n"; + print "See also:\ndo_unlinks(1), mirror(1).\n"; + exit 0; +} + # A simple safety check - only delete if the pathname begins with this -$del_only = '/public'; +$del_only = $opt_d ? $opt_d : '/home/ftp/pub/'; $rm = '/bin/rm -r'; $algorithm = 0; -if( $n ){ - $show_only = 1; -} -if( $show_only ){ - $show = 1; -} +$show_only = $opt_n ? 1 : 0; +$show = $opt_v ? 1 : 0; +$a1 = $opt_a ? 1 : 0; while( <> ){ # Skip local: and remote: lines quickly @@ -64,12 +85,13 @@ s/^(rmdir)\( (.*) \) before symlink failed: File exists$/rmdir $2/; if( /^(NEED TO )?(unlink|rmdir) ($del_only.*)/ ){ - local( $need, $cmd, $path ) = ($1, $2, $3); + local( $need, $cmd, $path ) = ( $1, $2, $3 ); + $need = ' ' if ! defined( $need ); $zap = "$cmd('$path')"; if( $algorithm == 1 && $cmd eq 'rmdir' ){ $path =~ s/([^A-Za-z0-9\-_\/\.])/\\$1/g; if( ! $a1 ){ - print "no -a1 so skipping: $rm $path\n"; + print "no a1 so skipping: $rm $path\n"; next; } $zap = "system('$rm $path');1";