Skip to content

Commit 56a5df3

Browse files
committed
Try harder to find the initdb executable
1 parent 686a234 commit 56a5df3

File tree

1 file changed

+37
-15
lines changed

1 file changed

+37
-15
lines changed

t/CP_Testing.pm

Lines changed: 37 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ use strict;
77
use warnings;
88
use Data::Dumper;
99
use Time::HiRes qw/sleep/;
10+
use File::Spec::Functions;
1011
use DBI;
1112
use Cwd;
1213

@@ -99,26 +100,47 @@ sub _test_database_handle {
99100
mkdir $dbdir;
100101
}
101102

102-
my $datadir = "$dbdir/data space";
103-
if (! -e $datadir) {
103+
## Find a working initdb (which also helps us find other binaries)
104+
my $initdb =
105+
$ENV{PGINITDB} ? $ENV{PGINITDB}
106+
: $ENV{PGBINDIR} ? "$ENV{PGBINDIR}/initdb"
107+
: 'initdb';
104108

105-
my $initdb
106-
= $ENV{PGINITDB} ? $ENV{PGINITDB}
107-
: $ENV{PGBINDIR} ? "$ENV{PGBINDIR}/initdb"
108-
: 'initdb';
109+
my ($imaj,$imin);
109110

110-
## Grab the version for finicky items
111-
if (qx{$initdb --version} !~ /(\d+)(?:\.(\d+))?/) {
111+
my $initversion = qx{$initdb --version 2>/dev/null};
112+
if ($initversion =~ /(\d+)(?:\.(\d+))?/) {
113+
($imaj,$imin) = ($1,$2);
114+
}
115+
else {
116+
## Work harder to find initdb. First check Debian area
117+
my $basedir = '/usr/lib/postgresql/';
118+
if (opendir my $dh, $basedir) {
119+
for my $subdir (sort { $b <=> $a } grep { /^\d+[\d\.]+$/ } readdir $dh) {
120+
$initdb = catfile($basedir, $subdir, 'bin', 'initdb');
121+
if (-e $initdb) {
122+
$initversion = qx{$initdb --version 2>/dev/null};
123+
if ($initversion =~ /(\d+)(?:\.(\d+))?/) {
124+
($imaj,$imin) = ($1,$2);
125+
last;
126+
}
127+
}
128+
}
129+
closedir $dh;
130+
}
131+
if (!defined $imaj) {
112132
die qq{Could not determine the version of initdb in use!\n};
113133
}
114-
my ($imaj,$imin) = ($1,$2);
134+
}
115135

116-
# Speed up testing on 9.3+
117-
if ($imaj > 9 or ($imaj==9 and $imin >= 3)) {
118-
$initdb = "$initdb --nosync";
119-
}
136+
my $datadir = "$dbdir/data space";
137+
if (! -e $datadir) {
120138

121-
$com = qq{LANG=C $initdb --locale C -E UTF8 -D "$datadir" 2>&1};
139+
$com = sprintf q{LANG=C %s %s --locale C -E UTF8 -D "%s" 2>&1},
140+
$initdb,
141+
# Speed up testing on 9.3+
142+
($imaj > 9 or ($imaj==9 and $imin >= 3)) ? ' --nosync' : '',
143+
$datadir;
122144
eval {
123145
$DEBUG and warn qq{About to run: $com\n};
124146
$info = qx{$com};
@@ -201,7 +223,7 @@ sub _test_database_handle {
201223
my $pg_ctl
202224
= $ENV{PG_CTL} ? $ENV{PG_CTL}
203225
: $ENV{PGBINDIR} ? "$ENV{PGBINDIR}/pg_ctl"
204-
: 'pg_ctl';
226+
: $initdb =~ s/initdb$/pg_ctl/r;
205227

206228
if (qx{$pg_ctl --version} !~ /(\d+)(?:\.(\d+))?/) {
207229
die qq{Could not determine the version of pg_ctl in use!\n};

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