Skip to content
Snippets Groups Projects
Commit e1a8e15d authored by Christoph Berg's avatar Christoph Berg 📡
Browse files

pg_conftool: Fix operation when no cluster exists yet.

parent 7f4e0df0
Branches
Tags
No related merge requests found
......@@ -34,6 +34,7 @@ postgresql-common (183) UNRELEASED; urgency=medium
config snippets.
* t/051_inconsistent_encoding_upgrade.t: Remove, only relevant for <= 8.2.
* logrotate config: Ship as static conffile again and remove ucf handling.
* pg_conftool: Fix operation when no cluster exists yet.
* pg_conftool: --boolean normalizes boolean variable in output; use this in
debian/maintscripts-functions.
* debian/maintscripts-functions: Unconditionally call invoke-rc.d, and drop
......
......@@ -68,22 +68,28 @@ for (my $i = 0; $i < @ARGV; $i++) {
help(1, 'No command given') unless (defined $cmdidx);
my ($version, $cluster, $conffile);
if ($cmdidx == 0) {
if ($cmdidx == 0) { # operate on postgresql.conf in default cluster
($version, $cluster) = user_cluster_map();
error "No default cluster found" unless ($cluster);
$conffile = 'postgresql.conf';
} elsif ($cmdidx == 1) {
($version, $cluster) = user_cluster_map();
} elsif ($cmdidx == 1) { # operate on given file; default cluster must exist if file is relative
$conffile = $ARGV[0];
} elsif ($cmdidx == 2) {
unless ($conffile =~ m!^/!) {
($version, $cluster) = user_cluster_map();
error "No default cluster found" unless ($cluster);
}
} elsif ($cmdidx == 2) { # version cluster, postgresql.conf
($version, $cluster, $conffile) = ($ARGV[0], $ARGV[1], 'postgresql.conf');
} elsif ($cmdidx == 3) {
} elsif ($cmdidx == 3) { # version cluster conffile
($version, $cluster, $conffile) = ($ARGV[0], $ARGV[1], $ARGV[2]);
} else {
help(1, 'Too many arguments before command');
}
error "Cluster $version $cluster does not exist"
unless (cluster_exists $version, $cluster);
if ($cluster) { # the cluster needs to exist unless an absolute conffile was given
error "Cluster $version $cluster does not exist"
unless (cluster_exists $version, $cluster);
}
splice @ARGV, 0, $cmdidx; # remove everything before the command
$ARGV[0] = 'show' if ($ARGV[0] eq 'get'); # accept alternative variants of some commands
......@@ -106,7 +112,7 @@ if ($ARGV[0] =~ /^(edit)$/) {
if ($cmd eq 'show') {
my %conf;
if ($conffile =~ m!/!) {
if ($conffile =~ m!^/!) {
%conf = read_conf_file ($conffile);
} else {
%conf = read_cluster_conf_file ($version, $cluster, $conffile);
......@@ -129,14 +135,14 @@ if ($cmd eq 'show') {
}
} elsif ($cmd eq 'set') {
if ($conffile =~ m!/!) {
if ($conffile =~ m!^/!) {
set_conffile_value ($conffile, $key, $value);
} else {
set_conf_value ($version, $cluster, $conffile, $key, $value);
}
} elsif ($cmd eq 'remove') {
if ($conffile =~ m!/!) {
if ($conffile =~ m!^/!) {
disable_conffile_value ($conffile, $key);
} else {
disable_conf_value ($version, $cluster, $conffile, $key);
......@@ -147,7 +153,7 @@ if ($cmd eq 'show') {
if ($ENV{EDITOR}) {
($editor) = $ENV{EDITOR} =~ /(.*)/; # untaint
}
if ($conffile =~ m!/!) {
if ($conffile =~ m!^/!) {
system $editor, $conffile;
} else {
system $editor, "$PgCommon::confroot/$version/$cluster/$conffile";
......
......@@ -3,7 +3,7 @@
use strict;
use warnings;
use Test::More tests => 33;
use Test::More tests => 41;
use File::Temp qw/tempdir/;
use lib '.';
use PgCommon;
......@@ -13,7 +13,19 @@ use TestLib;
my $tdir = tempdir (CLEANUP => 1);
$ENV{'PG_CLUSTER_CONF_ROOT'} = $tdir;
open F, "> $tdir/different.conf";
print F "a = '5'\n";
print F "#b = '6'\n";
close F;
note 'test without cluster';
is_program_out 0, "pg_conftool show all", 1, "Error: No default cluster found\n";
is_program_out 0, "pg_conftool foo.conf show all", 1, "Error: No default cluster found\n";
is_program_out 0, "pg_conftool $tdir/different.conf show all", 0, "a = 5\n";
is_program_out 0, "pg_conftool 9.7 main show all", 1, "Error: Cluster 9.7 main does not exist\n";
my $version = $MAJORS[-1];
die "Tests past this point need PostgreSQL installed" unless ($version);
mkdir "$tdir/$version";
mkdir "$tdir/$version/main";
......@@ -27,11 +39,6 @@ print F "a = '3'\n";
print F "#b = '4'\n";
close F;
open F, "> $tdir/different.conf";
print F "a = '5'\n";
print F "#b = '6'\n";
close F;
sub pgconf {
undef $/;
open F, "$tdir/$version/main/postgresql.conf";
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment