#!/usr/bin/perl -w # $Id: legalrpt.pl,v 1.1 2001/01/31 22:21:13 cpatti Exp $ # This script scans a specified directory tree for illegal filenames from # the Perforce SCM's perspective. # 12-23-00 -CAP use File::Find; use POSIX; use Getopt::Long; # Options my $verbose=''; my $nuke=''; my $tdcnt=0; my $bogcnt=0; my $upcnt=0; my $twincnt=0; my $pristinecnt=0; sub maybenuke { my $victim = shift; if ($nuke) { if (-d $victim) { print LOGFILE "Can't unlink $victim as it's a directory\n"; return; } if (unlink($victim) ne 1) { print LOGFILE "Can't unlink $victim\n"; return; } } } ##### MAIN PROGRAM ###### if (($#ARGV lt 1) || (! -d $ARGV[$#ARGV-1])) { print STDERR "Usage: $0 [--verbose|-v] [--nuke|-n] \n"; exit; } GetOptions('verbose'=>\$verbose,'nuke'=>\$nuke); $dir = $ARGV[$#ARGV-1]; $logfile = $ARGV[$#ARGV]; die "Could not open log: $logfile" unless open(LOGFILE,">$logfile"); if ($verbose) { print LOGFILE "FILES CONTAINING UNPRINTABLES\n"; print LOGFILE "-----------------------------\n\n"; } sub perflegal { $unprintable = (!POSIX::isprint($_)); $gotthreedots = /\.\.\./; $boguschar = m{[@#*%/"']}; $attictwin = (-f "$File::Find::dir/Attic/$_"); if ($verbose) { if ($unprintable) { print LOGFILE "$File::Find::name - unprintable\n"; $upcnt++; maybenuke($File::Find::name); } elsif ($gotthreedots) { print LOGFILE "$File::Find::name - has three dots\n"; $tdcnt++; maybenuke($File::Find::name); } elsif ($boguschar) { print LOGFILE "$File::Find::name - has illegal printable chars\n"; $bogcnt++; maybenuke($File::Find::name); } elsif ($attictwin) { print LOGFILE "$File::Find::name has a twin in the attic!\n"; $twincnt++; maybenuke("$File::Find::dir/Attic/$_"); } else { # These files are OK :) $pristinecnt++; } } else # We're not in verbose mode. { if ($unprintable || $gotthreedots || $boguschar) { maybenuke($File::Find::name); print LOGFILE "$File::Find::name\n"; } } } find(\&perflegal,$dir); if ($verbose) { print LOGFILE "\n\nThere were:\n"; print LOGFILE "$upcnt filenames containing unprintable characters\n"; print LOGFILE "$tdcnt filenames containing the illegal sequence ...\n"; print LOGFILE "$bogcnt filenames containing other illegal chars like #\n"; print LOGFILE "$twincnt filenames have twins in the attic!\n"; print LOGFILE "$pristinecnt filenames that are A-OK for import to Perforce\n"; }