Commit c629c58a authored by Martin Pitt's avatar Martin Pitt

* t/030_errors.t: Check that pg_createcluster leaves the original one intact

  if the cluster already exists, also when the original one is not running.
  This reproduces #597097.
* pg_createcluster: Be more careful with cleaning up the created cluster if
  an error occurs: Do not start the cleanup until we actually passed our
  sanity checks and created files for the new cluster. Before, it would
  erroneously remove an already existing cluster on a sanity check fail, if
  that cluster happened to not be running at the time. (Closes: #597097)
parent 1722951e
postgresql-common (111) UNRELEASED; urgency=low
* t/030_errors.t: Check that pg_createcluster leaves the original one intact
if the cluster already exists, also when the original one is not running.
This reproduces #597097.
* pg_createcluster: Be more careful with cleaning up the created cluster if
an error occurs: Do not start the cleanup until we actually passed our
sanity checks and created files for the new cluster. Before, it would
erroneously remove an already existing cluster on a sanity check fail, if
that cluster happened to not be running at the time. (Closes: #597097)
-- Martin Pitt <mpitt@debian.org> Wed, 22 Sep 2010 11:17:48 +0200
postgresql-common (110) unstable; urgency=low
[ Martin Pitt ]
......
......@@ -180,7 +180,9 @@ sub setup_pg_hba {
my $startconf = 'auto';
my $createsuccess = 0;
# this flag gets set when we started creating the cluster, and thus we need to
# clean up on errors
my $cleanup_cruft = 0;
exit 1 unless GetOptions ('u|user=s' => \$owneruid, 'g|group=s' => \$ownergid,
's|socketdir=s' => \$socketdir, 'd|datadir=s' => \$datadir,
......@@ -286,6 +288,10 @@ if (!stat $confdirp) {
error 'could not create configuration directory; you might ' .
'need to run this program with root privileges' if system ('install', '-d', $confdir);
# now we created the first new directory for this cluster and start to rollback
# on error
$cleanup_cruft = 1;
# check whether we have an already existing cluster; check version and
# determine owner in this case
$newcluster = 0;
......@@ -433,7 +439,7 @@ close ENV;
chmod 0644, "$confdir/environment";
chown $owneruid, $ownergid, "$confdir/environment";
$createsuccess = 1;
$cleanup_cruft = 0;
# configure to create external PID file
if ($socketdir eq '/var/run/postgresql') {
......@@ -447,7 +453,7 @@ if ($start) {
END {
# clean up cruft if something went wrong
if (!$createsuccess && defined $version && defined $cluster) {
if ($cleanup_cruft && defined $version && defined $cluster) {
system "pg_dropcluster $version $cluster 2>/dev/null";
exit 1;
}
......
......@@ -6,7 +6,7 @@ require File::Temp;
use lib 't';
use TestLib;
use Test::More tests => 163;
use Test::More tests => 169;
use lib '/usr/share/postgresql-common';
use PgCommon;
......@@ -38,9 +38,16 @@ sub check_nonexisting_cluster_error {
# create cluster
ok ((system "pg_createcluster --socketdir '$socketdir' $version main >/dev/null") == 0,
"pg_createcluster --socketdir");
like_program_out 'postgres', 'pg_lsclusters -h', 0, qr/$version\s*main.*5432.*down/, 'cluster was created';
is ((get_cluster_port $version, 'main'), 5432, 'Port of created cluster is 5432');
# creating cluster with the same name should fail
like_program_out 'root', "pg_createcluster --socketdir '$socketdir' $version main", 1, qr/already exists/,
"pg_createcluster on existing cluster";
# and the original one still exists
like_program_out 'postgres', 'pg_lsclusters -h', 0, qr/$version\s*main.*5432.*down/, 'original cluster still exists';
# attempt to create clusters with an invalid port
like_program_out 0, "pg_createcluster $version test -p foo", 1,
qr/invalid.*number expected/,
......
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