Commit fdb32c06 authored by Christoph Berg's avatar Christoph Berg

Clean up /var/lib/postgresql/X.Y if pg_createcluster fails early

Spotted by t/130_nonroot_admin.t
parent 33cba721
......@@ -298,6 +298,7 @@ foreach my $argv (@ARGV) {
push @initdb_opts_from_cli, $argv =~ /(.*)/; # untaint
}
my $datadirp_created;
if (!defined $datadir) {
$datadir = replace_v_c ($defaultconf{'data_directory'} || "/var/lib/postgresql/%v/%c", $version, $cluster);
$datadir =~ s!/+$!!;
......@@ -308,8 +309,8 @@ if (!defined $datadir) {
# it can be administrated without root permissions
if (!stat $pd) {
system 'install', '-d', '-o', $postgres_user[2], '-g', $postgres_user[3], $pd;
$datadirp_created = $pd; # clean up in case of error
}
}
$confdirp = "$PgCommon::confroot/$version";
$confdir = "$confdirp/$cluster";
......@@ -337,13 +338,13 @@ if (defined $port) {
if (!stat $confdirp) {
system 'install', '-d', '-o', $postgres_user[2], '-g', $postgres_user[3], $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;
error 'could not create configuration directory; you might ' .
'need to run this program with root privileges' if system ('install', '-d', $confdir);
# check whether we have an already existing cluster; check version and
# determine owner in this case
$newcluster = 0;
......@@ -593,6 +594,7 @@ END {
# clean up cruft if something went wrong
if ($cleanup_cruft && defined $version && defined $cluster) {
system "pg_dropcluster $version $cluster 2>/dev/null";
rmdir $datadirp_created; # clean up after early errors which pg_dropcluster doesn't handle
exit 1;
}
}
......
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