Minimise output on patch failure where alternatives exist.

This commit is contained in:
Andrew McMillan 2007-12-04 08:46:47 +13:00
parent 91f1d2324c
commit c2115a22d8

View File

@ -12,7 +12,7 @@ use Getopt::Long qw(:config permute); # allow mixed args.
# Options variables
my $debug = 0;
my $dbname = "davical";
my $dbname = "rscds";
my $dbport = 5432;
my $dbuser = "";
my $dbpass = "";
@ -52,18 +52,24 @@ closedir(PATCHDIR);
@patches = sort { compare_revisions(revision_hash($a),revision_hash($b), 1); } @patches;
my $applied = 0;
my $last_results = ''; # Will hold the last SQL result from applying a patch
for ( my $i=0; $i <= $#patches; $i++ ) {
printf( "Looking at patches[%d] (%s)\n", $i, $patches[$i]) if ( $debug );
if ( compare_revisions(revision_hash($patches[$i]),$current_revision) > 0 ) {
print "Applying patch $patches[$i]\n";
print "Applying patch $patches[$i] ... ";
if ( !apply_patch( $patches[$i] ) ) {
# Skip to the end unless the next patch is an alternate for the same version.
last unless ( compare_revisions(revision_hash($patches[$i]),revision_hash($patches[$i+1])) == 0 );
print "Patch failed, but alternatives exist. Attempting next alternative.\n";
if ( defined($patches[$i+1]) && compare_revisions(revision_hash($patches[$i]),revision_hash($patches[$i+1])) == 0 ) {
print "failed. Attempting next alternative.\n";
$applied--;
}
else {
print "failed!\n$last_results \n ==> No further patches will be attempted!\n";
}
}
else {
print "Patch succeeded.\n";
print "succeeded.\n";
}
$applied++;
}
@ -181,7 +187,7 @@ sub apply_patch {
$current_revision = get_current_revision();
if ( compare_revisions($current_revision,revision_hash($patch)) != 0 ) {
printf( "Failed to apply revision %s to the database!\n", $patch );
printf( "Failed to apply revision %s to the database!\n", $patch ) if ( $debug );
return 0;
}
return 1; # Success
@ -204,11 +210,10 @@ sub apply_sql_file {
$ENV{'PGPASS'} = $dbpass if ( $dbpass ne "" );
my $command = join ' ', @psql_opts;
my $results = `$command 2>&1 1>/dev/null`;
$last_results = `$command 2>&1 1>/dev/null`;
$results =~ s/^.*WARNING: there is no transaction in progress\s$//m;
print $results;
$last_results =~ s/^.*WARNING: there is no transaction in progress\s$//m;
$last_results =~ s/^.*NOTICE: //m;
}