Skip to content

Commit 15d07f3

Browse files
author
David Christensen
committed
Tighten up full-version detection with Pg 10
1 parent a4a1d23 commit 15d07f3

File tree

1 file changed

+24
-30
lines changed

1 file changed

+24
-30
lines changed

check_postgres.pl

Lines changed: 24 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -2605,7 +2605,7 @@ sub run_command {
26052605
else {
26062606
$string = $arg->{oldstring} || $arg->{string};
26072607
for my $row (@{$arg->{version}}) {
2608-
if ($row !~ s/^([<>]?)(\d+\.?\d+)\s+//) {
2608+
if ($row !~ s/^([<>]?)(\d+\.?\d+|1\d+)\s+//) {
26092609
ndie msg('die-badversion', $row);
26102610
}
26112611
my ($mod,$ver) = ($1||'',$2);
@@ -2728,7 +2728,7 @@ sub run_command {
27282728
if ($db->{error}) {
27292729
ndie $db->{error};
27302730
}
2731-
if ($db->{slurp} !~ /(\d+\.?\d+)/) {
2731+
if ($db->{slurp} !~ /(\d+(?:\.?\d+))?/) {
27322732
ndie msg('die-badversion', $db->{slurp});
27332733
}
27342734
$db->{version} = $1;
@@ -2979,8 +2979,7 @@ sub verify_version {
29792979
my $limit = $testaction{lc $action} || '';
29802980

29812981
my $versiononly = shift || 0;
2982-
2983-
return if ! $limit and ! $versiononly;
2982+
return if ! $limit and ! $versiononly and !defined wantarray;
29842983

29852984
## We almost always need the version, so just grab it for any limitation
29862985
$SQL = q{SELECT setting FROM pg_settings WHERE name = 'server_version'};
@@ -2998,8 +2997,11 @@ sub verify_version {
29982997
}
29992998

30002999
my ($sver,$smaj,$smin);
3000+
if (
3001+
$info->{db}[0]{slurp}[0]{setting} !~ /^(([2-9])\.(\d+))/ &&
3002+
$info->{db}[0]{slurp}[0]{setting} !~ /^((1\d+)())/
3003+
){
30013004

3002-
if ($info->{db}[0]{slurp}[0]{setting} !~ /^((\d+)(\.(:?\d+))?)/) {
30033005
ndie msg('die-badversion', $SQL);
30043006
}
30053007
else {
@@ -5779,14 +5781,9 @@ sub find_new_version {
57795781
my $version = verify_version();
57805782

57815783
## The format is X.Y.Z [optional message]
5782-
my $versionre = qr{((\d+)\.(\d+)\.(\d+))\s*(.*)};
5783-
my ($cversion,$cmajor,$cminor,$crevision,$cmessage) = ('','','','','');
5784+
my $versionre = qr{((\d+)\.(\d+)(?:\.(\d+))?)(?:\s+(.*))?};
57845785

5785-
## If we're running on PG10, then format is X.Y [optional message]
5786-
if ($version >= 10) {
5787-
$versionre = qr{((\d+)\.(\d+))\s*(.*)};
5788-
($cversion,$cmajor,$cminor,$cmessage) = ('','','','');
5789-
}
5786+
my ($cversion,$cmajor,$cminor,$crevision,$cmessage) = ('','','','','');
57905787

57915788
my $found = 0;
57925789

@@ -5799,24 +5796,21 @@ sub find_new_version {
57995796
## Postgres is slightly different
58005797
if ($program eq 'Postgres') {
58015798
$cmajor = {};
5802-
if ($version >= 10) {
5803-
while ($info =~ /<title>(\d+)\.(\d+)/g) {
5804-
$found = 1;
5805-
$cmajor->{"$1"} = $2;
5806-
}
5807-
}
5808-
else {
5809-
while ($info =~ /<title>(\d+)\.(\d+)\.(\d+)/g) {
5810-
$found = 1;
5799+
while ($info =~ /<title>(\d+)\.(\d+)(?:\.(\d+))?/g) {
5800+
$found = 1;
5801+
if (defined $3) {
58115802
$cmajor->{"$1.$2"} = $3;
58125803
}
5804+
else {
5805+
$cmajor->{$1} = $2;
5806+
}
58135807
}
58145808
}
58155809
elsif ($info =~ $versionre) {
58165810
$found = 1;
58175811
($cversion,$cmajor,$cminor,$crevision,$cmessage) = ($1, int $2, int $3, int $4, $5);
5812+
$info =~ s/\s+$//s;
58185813
if ($VERBOSE >= 1) {
5819-
$info =~ s/\s+$//s;
58205814
warn "Remote version string: $info\n";
58215815
warn "Remote version: $cversion\n";
58225816
}
@@ -5854,30 +5848,30 @@ sub find_new_version {
58545848
return;
58555849
}
58565850
my ($lversion,$lmajor,$lminor,$lrevision) = ('',0,0,0);
5857-
if ($version >= 10) {
5858-
($lversion, $lmajor, $lminor) = ($1, int $2, int $3);
5851+
if ($2 >= 10 && $program eq 'Postgres') {
5852+
($lversion,$lmajor,$lrevision) = ($1, int $2, int $3);
58595853
} else {
58605854
($lversion,$lmajor,$lminor,$lrevision) = ($1, int $2, int $3, int $4);
58615855
}
58625856

5857+
$output =~ s/\s+$//s;
58635858
if ($VERBOSE >= 1) {
5864-
$output =~ s/\s+$//s;
58655859
warn "Local version string: $output\n";
58665860
warn "Local version: $lversion\n";
58675861
}
58685862

58695863
## Postgres is a special case
58705864
if ($program eq 'Postgres') {
5871-
my $lver = "$lmajor.$lminor";
5865+
my $lver = $lmajor >= 10 ? $lmajor : "$lmajor.$lminor";
58725866
if (! exists $cmajor->{$lver}) {
58735867
add_unknown msg('new-ver-nocver', $program);
58745868
return;
58755869
}
58765870
$crevision = $cmajor->{$lver};
58775871
$cmajor = $lmajor;
58785872
$cminor = $lminor;
5879-
if ($version >= 10) {
5880-
$cversion = "$cmajor.$cminor";
5873+
if ($lmajor >= 10) {
5874+
$cversion = "$cmajor.$crevision";
58815875
} else {
58825876
$cversion = "$cmajor.$cminor.$crevision";
58835877
}
@@ -5954,7 +5948,7 @@ sub check_new_version_pg {
59545948
my $info = run_command('SELECT version() AS version');
59555949
my $lversion = $info->{db}[0]{slurp}[0]{version};
59565950
## Make sure it is parseable and check for development versions
5957-
if ($lversion !~ /\d+\.\d+\.\d+/) {
5951+
if ($lversion !~ /1\d+\.\d+|\d+\.\d+\.\d+/) {
59585952
if ($lversion =~ /(\d+\.\d+\S+)/) {
59595953
add_ok msg('new-ver-dev', 'Postgres', $1);
59605954
return;
@@ -8351,7 +8345,7 @@ sub check_version {
83518345

83528346
my ($warning, $critical) = validate_range({type => 'version', forcemrtg => 1});
83538347

8354-
my ($warnfull, $critfull) = (($warning =~ /^\d+\.?\d+$/ ? 0 : 1),($critical =~ /^\d+\.?\d+$/ ? 0 : 1));
8348+
my ($warnfull, $critfull) = (($warning =~ /^(?:1\d+|[8-9]\.\d+)$/ ? 0 : 1),($critical =~ /^(?:1\d+|[8-9]\.\d+)$/ ? 0 : 1));
83558349

83568350
my $info = run_command('SELECT version() AS version');
83578351

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy