update readme and add gitignore
[client-tools.git] / tools / find_unchecked.pl
blobed5bd89cd2ef9c89d4771086533920914913e8c4
1 #!/usr/bin/perl
3 use File::Find;
5 # process command line arguments
6 while ($ARGV[0] =~ /^-/)
8 $_ = shift;
10 if ($_ eq "--debug")
12 $debug = 1;
14 elsif ($_ eq "--delete")
16 $delete = 1;
18 else
20 die "unknown command line option";
24 sub CollectP4OpenedFiles
26 open(P4, "p4 opened |");
27 while (<P4>)
29 chomp;
30 $openedFiles{$_} = 1 if (s/#.*//);
32 close(P4);
35 sub FindHandler
37 if (-d $_)
39 # found a directory entry
41 # prune the directory if it's one we want to ignore
42 if (m/^(compile|external|Debug|Optimized|Production|Release|generated)$/)
44 # prune it
45 $File::Find::prune = 1;
46 print STDERR "[Pruned Directory Entry: $File::Find::name]\n" if ($debug);
49 elsif (-f and -w $_)
51 # handle writable non-directory entry
52 if (!m/^.*(\.(aps|ca|clw|class|dll|ews|exe|ncb|opt|plg|WW|tmp|db|bak|pyc|cfg|o)|~)$/)
54 # this is a writable file that should be checked against what's in Perforce.
55 my ($commandLine, $expectedDepotLocation);
57 $commandLine = `p4 where $File::Find::name`;
58 $commandLine =~ /([^ ]+) /;
60 $expectedDepotLocation = $1;
62 # this writable file is suspect (i.e. is missing) if the depot file
63 # is not opened. That implies the file is writable but not opened,
64 # most likely indicating it doesn't exist in the depot.
65 if (!$openedFiles{$expectedDepotLocation})
67 print $File::Find::name, "\n";
68 unlink $File::Find::name if ($delete);
70 else
72 print STDERR "<file [$File::Find::name] is in perforce>\n" if ($debug);
78 # collect opened depot files
79 CollectP4OpenedFiles();
81 # do a find
82 @ARGV = ('../') unless @ARGV;
83 find(\&FindHandler, @ARGV);