Commit 124ff6b7 authored by Christoph Berg's avatar Christoph Berg

Replace version string comparisions in perl scripts to use numerical

operators, so things will continue to work when PostgreSQL 10.0 is
released.
parent a4db22ca
......@@ -599,7 +599,7 @@ sub cluster_info {
}
# autovacuum defaults to on since 8.3
$result{'avac_enable'} = config_bool $postgresql_conf{'autovacuum'} || ($_[0] ge '8.3');
$result{'avac_enable'} = config_bool $postgresql_conf{'autovacuum'} || ($_[0] >= '8.3');
return %result;
}
......@@ -895,7 +895,7 @@ sub get_cluster_locales {
my ($version, $cluster) = @_;
my ($lc_ctype, $lc_collate) = (undef, undef);
if ($version ge '8.4') {
if ($version >= '8.4') {
print STDERR "Error: get_cluster_locales() does not work for 8.4+\n";
exit 1;
}
......
......@@ -27,6 +27,9 @@ postgresql-common (137) UNRELEASED; urgency=low
(Closes: #646700)
* supported-versions: Add debian-backports and pgdg sections.
(Closes: #650680)
* Replace version string comparisions in perl scripts to use numerical
operators, so things will continue to work when PostgreSQL 10.0 is
released.
* debian/rules: Use sort -n for sorting supported-versions output.
* debian/rules: Use apt-cache policy instead of apt-cache show to determine
the "candidate" logrotate version.
......
......@@ -28,12 +28,12 @@ my @postgres_user = getpwnam 'postgres';
# Arguments: <version> <data directory> <owner uid> <owner gid>
sub init_db {
$datadir = (-l $_[1]) ? readlink $_[1] : $_[1];
if ($_[0] ge '8.4') {
if ($_[0] >= '8.4') {
$ident_method = 'ident';
} else {
$ident_method = 'ident sameuser';
}
if ($_[0] ge '9.1') {
if ($_[0] >= '9.1') {
$peer_method = 'peer';
} else {
$peer_method = $ident_method;
......@@ -45,7 +45,7 @@ sub init_db {
@initdb = ((get_program_path 'initdb', $_[0]), '-D', $datadir);
die 'Internal error: could not determine initdb path' unless $initdb[0];
if ($_[0] ge '9.2') {
if ($_[0] >= '9.2') {
push @initdb, ('--auth-local', $peer_method);
push @initdb, ('--auth-host', 'md5');
} else {
......@@ -62,7 +62,7 @@ sub init_db {
# pre-8.2 servers do not ignore LANG when LC_ALL is set; work around this
# bug
if ($_[0] le '8.2' && $ENV{'LC_ALL'}) {
if ($_[0] <= '8.2' && $ENV{'LC_ALL'}) {
$ENV{'LANG'} = $ENV{'LC_ALL'};
}
......@@ -427,7 +427,7 @@ die "changing egid back: $!" if $) != $egid;
# enable SSL if we have the snakeoil default certificate
if ($newcluster && -e '/etc/ssl/certs/ssl-cert-snakeoil.pem' &&
$ssl_key_access) {
if ($version ge '9.2') {
if ($version >= '9.2') {
PgCommon::set_conf_value $version, $cluster, 'postgresql.conf',
'ssl_cert_file', '/etc/ssl/certs/ssl-cert-snakeoil.pem';
PgCommon::set_conf_value $version, $cluster, 'postgresql.conf',
......
......@@ -362,7 +362,7 @@ if ($info{'logfile'} && ! -e $info{'logfile'}) {
if ($> == 0) {
# have the postmaster start with increased OOM killer protection; 9.1 and
# later has builtin support for resetting the adjustment of child processes
if ($action eq 'start' && $version ge '9.1') {
if ($action eq 'start' && $version >= '9.1') {
if (-w '/proc/self/oom_score_adj') {
open F, '>/proc/self/oom_score_adj';
print F "-900\n";
......
......@@ -73,7 +73,7 @@ sub adapt_conffiles {
PgCommon::set_conf_value $newversion, $cluster, 'postgresql.conf',
'data_directory', $newinfo{'pgdata'};
if ($newversion ge '8.2') {
if ($newversion >= '8.2') {
# preload_libraries -> shared_preload_libraries transition
rename_ \%c, 'preload_libraries', 'shared_preload_libraries';
......@@ -86,7 +86,7 @@ sub adapt_conffiles {
}
}
if ($newversion ge '8.3') {
if ($newversion >= '8.3') {
deprecate \%c, 'bgwriter_lru_percent', 'deprecated';
deprecate \%c, 'bgwriter_all_percent', 'deprecated';
deprecate \%c, 'bgwriter_all_maxpages', 'deprecated';
......@@ -112,7 +112,7 @@ sub adapt_conffiles {
}
}
if ($newversion ge '8.4') {
if ($newversion >= '8.4') {
deprecate \%c, 'max_fsm_pages', 'not needed any more';
deprecate \%c, 'max_fsm_relations', 'not needed any more';
deprecate \%c, 'krb_server_hostname', 'does not exist any more';
......@@ -134,12 +134,12 @@ sub adapt_conffiles {
rename "$hba.new", $hba or error "rename: $!";
}
if ($newversion ge '9.0') {
if ($newversion >= '9.0') {
deprecate \%c, 'add_missing_from', 'does not exist any more';
deprecate \%c, 'regex_flavor', 'does not exist any more';
}
if ($newversion ge '9.2') {
if ($newversion >= '9.2') {
deprecate \%c, 'wal_sender_delay', 'does not exist any more';
deprecate \%c, 'silent_mode', 'does not exist any more';
deprecate \%c, 'custom_variable_classes', 'does not exist any more';
......@@ -172,7 +172,7 @@ sub disable_connections {
}
chmod 0400, $hba;
chown $_[3], 0, $hba;
if ($_[0] ge '8.4') {
if ($_[0] >= '8.4') {
print F "local all $_[2] ident";
} else {
print F "local all $_[2] ident sameuser";
......@@ -243,7 +243,7 @@ error 'could not get name of cluster owner' unless $owner;
if ($info{'running'}) {
print "Stopping old cluster...\n";
my @argv = ('pg_ctlcluster', $version, $cluster, 'stop', '--');
push @argv, ('-t', '5') if $version ge '8.4';
push @argv, ('-t', '5') if $version >= '8.4';
error "Could not stop old cluster" if system @argv;
}
......@@ -258,7 +258,7 @@ error "Could not restart old cluster" if system @argv;
# get encodings of cluster
my $encoding = get_db_encoding $version, $cluster, 'template1';
my ($old_lc_ctype, $old_lc_collate);
if ($version le '8.3') {
if ($version <= '8.3') {
($old_lc_ctype, $old_lc_collate) = get_cluster_locales $version, $cluster;
} else {
($old_lc_ctype, $old_lc_collate) = get_db_locales $version, $cluster, 'template1';
......@@ -412,7 +412,7 @@ if (!fork) {
print "Fixing hardcoded library paths for stored procedures...\n";
# starting from 9.0, replace() works on strings; for ealier versions it
# works on bytea
if ($version ge '9.0') {
if ($version >= '9.0') {
(system $psql, '-h', $oldsocket, '-p', $info{'port'}, '-q', '-d',
$db, '-c', "BEGIN READ WRITE; \
UPDATE pg_proc SET probin = replace(\
......@@ -437,7 +437,7 @@ if (!fork) {
my @restore_argv = ($pg_restore, '-h', $newsocket, '-p',
$newinfo{'port'}, '--data-only', '-d', $db);
if ($newversion ge '8.3') {
if ($newversion >= '8.3') {
push @restore_argv, '--disable-triggers';
}
......
......@@ -13,7 +13,7 @@ print "Info: PostgreSQL versions installed: @MAJORS\n";
foreach my $v (@MAJORS) {
ok ((deb_installed "postgresql-$v"), "postgresql-$v installed");
ok ((deb_installed "postgresql-plpython-$v"), "postgresql-plpython-$v installed");
if ($v ge '9.1') {
if ($v >= '9.1') {
ok ((deb_installed "postgresql-plpython3-$v"), "postgresql-plpython3-$v installed");
} else {
pass "no Python 3 package for version $v";
......
......@@ -25,7 +25,7 @@ sub check_major {
'Socket and pid file are in /var/run/postgresql/';
# verify that exactly one postmaster is running
my @pm_pids = pidof (($v ge '8.2') ? 'postgres' : 'postmaster');
my @pm_pids = pidof (($v >= '8.2') ? 'postgres' : 'postmaster');
is $#pm_pids, 0, 'Exactly one postmaster process running';
# check environment
......@@ -46,7 +46,7 @@ sub check_major {
is_program_out 'postgres', "pg_ctlcluster $v main restart", 0, '',
'cluster restarts with new environment file';
@pm_pids = pidof (($v ge '8.2') ? 'postgres' : 'postmaster');
@pm_pids = pidof (($v >= '8.2') ? 'postgres' : 'postmaster');
is $#pm_pids, 0, 'Exactly one postmaster process running';
%env = pid_env $pm_pids[0];
is $env{'PGEXTRAVAR1'}, '1', 'correct value of PGEXTRAVAR1 in environment';
......@@ -116,7 +116,7 @@ sub check_major {
# verify that explicitly configured log file trumps log symlink
PgCommon::set_conf_value ($v, 'main', 'postgresql.conf',
($v ge '8.3' ? 'logging_collector' : 'redirect_stderr'), 'on');
($v >= '8.3' ? 'logging_collector' : 'redirect_stderr'), 'on');
PgCommon::set_conf_value $v, 'main', 'postgresql.conf', 'log_filename', "$v#main.log";
is ((exec_as 'root', "pg_ctlcluster $v main start"), 0,
'restarting cluster with explicitly configured log file');
......@@ -191,7 +191,7 @@ Bob|1
0, "Foo2\n", 'calling PL/Python function';
# Check PL/Python3 (untrusted)
if ($v ge '9.1') {
if ($v >= '9.1') {
is_program_out 'postgres', 'createlang plpython3u nobodydb', 0, '', 'createlang plpython3u succeeds for user postgres';
is_program_out 'postgres', 'psql nobodydb -qc "CREATE FUNCTION capitalize3(text) RETURNS text AS \'import sys; return args[0].capitalize() + sys.version[0]\' LANGUAGE plpython3u;"',
0, '', 'creating PL/Python3 function as user postgres succeeds';
......@@ -273,7 +273,7 @@ Bob|1
$adj = <F>;
chomp $adj;
close F;
if ($v ge '9.1') {
if ($v >= '9.1') {
cmp_ok $adj, '<=', -5, 'postgres >= 9.1 master has OOM killer protection';
} else {
is $adj, 0, 'postgres < 9.1 master has no OOM adjustment';
......
......@@ -192,7 +192,7 @@ print F "foo\n";
close F;
chmod 0644, "/etc/postgresql/$version/main/pg_hba.conf" or die "chmod: $!";
if ($version lt '8.4') {
if ($version < '8.4') {
like_program_out 'postgres', "pg_ctlcluster $version main start", 0,
qr/WARNING.*connection to the database failed.*pg_hba.conf/is,
'pg_ctlcluster start warns about invalid pg_hba.conf';
......
......@@ -47,7 +47,7 @@ is_program_out 'nobody', 'psql -Atc "SELECT nextval(\'odd10\')" test', 0, "3\n",
'check next sequence value';
# create stored procedures
if ($MAJORS[0] lt '9.0') {
if ($MAJORS[0] < '9.0') {
is_program_out 'postgres', 'createlang plpgsql test', 0, '', 'createlang plpgsql test';
} else {
pass '>= 9.0 enables PL/pgsql by default';
......
......@@ -84,7 +84,7 @@ sub check_cluster {
'printf "set client_encoding=\'SJIS\'; select \'\\\\\\\'a\'" | psql -Atq template1',
0, qr/(\\' is insecure)|(unterminated quoted string)/,
'Server rejects \\\' escaping in unsafe client encoding (CVE-2006-2314)';
if ($v ge '9.1') {
if ($v >= '9.1') {
like_program_out 'postgres',
"printf \"set client_encoding='UTF-8'; set escape_string_warning='off'; select '\\\\\\'a'\" | psql -Atq template1",
0, qr/unterminated quoted string/,
......
......@@ -7,7 +7,7 @@ use strict;
use lib 't';
use TestLib;
use Test::More tests => ($#MAJORS == 0 || $MAJORS[0] ge '8.3') ? 1 : 19 * 3 + 10;
use Test::More tests => ($#MAJORS == 0 || $MAJORS[0] >= '8.3') ? 1 : 19 * 3 + 10;
use lib '/usr/share/postgresql-common';
use PgCommon;
......@@ -17,7 +17,7 @@ if ($#MAJORS == 0) {
exit 0;
}
if ($MAJORS[0] ge '8.3') {
if ($MAJORS[0] >= '8.3') {
pass 'test only relevant for oldest version < 8.3, skipping';
exit 0;
}
......
......@@ -24,7 +24,7 @@ is ((exec_as 0, "pg_createcluster --start --locale=ru_RU $oldv main", $outref),
is ((exec_as 'postgres', 'psql -c "create database latintest" template1', $outref), 0,
"creating latintest DB with LATIN encoding");
if ($oldv le '8.3') {
if ($oldv <= '8.3') {
is ((exec_as 'postgres', 'psql -c "create database asctest encoding = \'SQL_ASCII\'" template1', $outref), 0,
"creating asctest DB with ASCII encoding");
} else {
......
......@@ -20,7 +20,7 @@ like_program_out $owner, 'pg_lsclusters -h', 0,
qr/^$v\s+main\s+5432\s+online\s+$owner/,
'pg_lsclusters shows running cluster';
my $master_process = ($v ge '8.2') ? 'postgres' : 'postmaster';
my $master_process = ($v >= '8.2') ? 'postgres' : 'postmaster';
like ((ps $master_process), qr/^$owner.*bin\/$master_process .*\/var\/lib\/postgresql\/$v\/main/m,
"$master_process is running as user $owner");
......
......@@ -13,7 +13,7 @@ use PgCommon;
# check version specific output
my $version;
foreach $version (@MAJORS) {
if ($version lt '8.2') {
if ($version < '8.2') {
pass "Skipping known-broken pg_config check for version $version";
for (my $i = 0; $i < 7; ++$i) { pass '...'; }
next;
......
......@@ -12,7 +12,7 @@ use PgCommon;
my $v = $MAJORS[-1];
if ($v lt '9.1') {
if ($v < '9.1') {
pass 'No extensions for version < 9.1';
done_testing(1);
exit 0;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment