#!/usr/bin/perl
#==============================================================================
# Copyright and license info is available in the LICENSE file included with
# the Server Deployment Package (SDP), and also available online:
# https://swarm.workshop.perforce.com/projects/perforce-software-sdp/view/main/LICENSE
#------------------------------------------------------------------------------
# Verifies a depot path one directory at a time.
#
# The required arguments are:
# 1. Depot path to start searching in. Must end with a trailing '/...'.
# 2. Perforce command string
# subs
sub verify_dirs($);
my $TmpFile = sprintf ("%s/tmp.%d.%05d.txt", $ENV{'P4TMP'}, $$, int(rand(32768)+1));
#
# verify_dirs: Runs p4 verify on a dir and all sub-dirs
#
sub verify_dirs($) {
my ($dir) = @_;
$dir = $dir . '/*';
print ("CALL verify_dirs ($dir)\n") if ($ENV{'P4VERIFY_DEBUG'});
my $verifyCmd = $ENV{'P4BIN'} . ' -s verify -qz ';
my $verifyFixCmd;
my $verifyList;
my $verifyFixList;
$verifyCmd = $verifyCmd . '"' . $dir . '"';
print (" VCMD: $verifyCmd\n") if ($ENV{'P4VERIFY_DEBUG'});
$verifyList = `$verifyCmd 2>&1`;
if($verifyList !~ /^exit: 0$/ and $verifyList !~ /no such file/) {
print $verifyList;
if ($verifyList =~ /BAD\!/ and $verifyList =~ /\(text\+k/) {
$verifyList =~ s/^error: //mg;
$verifyList =~ s/ - .* change .*$//mg;
$verifyList =~ s/\nexit: .*$//m;
open (TMP, ">$TmpFile") or
die "\nError: Could not open file $TmpFile: $!\n";
print TMP $verifyList;
close (TMP);
$verifyFixCmd = $ENV{'P4BIN'} . " -x $TmpFile verify -v";
print (" VFIXCMD: $verifyFixCmd\n") if ($ENV{'P4VERIFY_DEBUG'});
$verifyFixList = `$verifyFixCmd 2>&1`;
print "Fixed BAD files with type containing text+k:\n$verifyFixList\n";
print $verifyFixList;
}
}
my $dirListCmd = $ENV{'P4BIN'} . ' dirs "' . $dir . '"';
my $dirList = `$dirListCmd 2>&1`;
if($dirList !~ /no such file/) {
foreach my $adir (split(/\n/, $dirList)) {
next unless $adir =~ /\/\//;
verify_dirs($adir);
}
}
} # end verify_dirs
# parse command line:
# - depot path to search
if($#ARGV ne 0) {
die "\n\nUsage: p4verify.pl <depot path for search>\n\nThe depot path to search must end in '/...'\n\n";
}
my $depotDir = $ARGV[0];
if($depotDir !~ /\/\.\.\.$/) {
die "\n\n\nUsage Error: Depot path for search must end with '/...'.\n\n";
}
die "\nError: SDP shell environment not set. Source /p4/common/bin/p4_vars first.\n\n" unless ($ENV{'P4BIN'});
# Don't run p4verify_fix.pl on a replica.
if ($ENV{'P4REPLICA'} eq 'TRUE') {
die "\n\nError: Don't run p4verify_fix.pl on a replica. This host is a replica.\n\n";
}
# run 'p4 verify' on each directory in the tree
verify_dirs(substr($depotDir, 0, -4));
unlink ($TmpFile);
exit(0);