Skip to content

Commit dfbad3f

Browse files
committed
Further portability hacking in pg_upgrade's test script.
I blew the dust off a Bourne shell (file date 1996, yea verily) and tried to run test.sh with it. It mostly worked, but I found that the temp-directory creation code introduced by commit be76a6d was not compatible, for a couple of reasons: this shell thinks "set -e" should force an exit if a command within backticks fails, and it also thinks code within braces should be executed by a sub-shell, meaning that variable settings don't propagate back up to the parent shell. In view of Victor Wagner's report that Solaris is still using pre-POSIX shells, seems like we oughta make this case work. It's not like the code is any less idiomatic this way; the prior coding technique appeared nowhere else. (There is a remaining bash-ism here, which is that $RANDOM doesn't do what the code hopes in non-bash shells. But the use of $$ elsewhere in that path should be enough to ensure uniqueness and some amount of randomness, so I think it's okay as-is.) Back-patch to all supported branches, as the previous commit was. Discussion: https://postgr.es/m/20180720153820.69e9ae6c@fafnir.local.vm
1 parent 8212004 commit dfbad3f

File tree

1 file changed

+10
-12
lines changed

1 file changed

+10
-12
lines changed

src/bin/pg_upgrade/test.sh

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -42,20 +42,18 @@ case $testhost in
4242
# script; the outcome mimics pg_regress.c:make_temp_sockdir().
4343
PGHOST=$PG_REGRESS_SOCK_DIR
4444
if [ "x$PGHOST" = x ]; then
45-
{
46-
dir=`(umask 077 &&
47-
mktemp -d /tmp/pg_upgrade_check-XXXXXX) 2>/dev/null` &&
48-
[ -d "$dir" ]
49-
} ||
50-
{
45+
set +e
46+
dir=`(umask 077 &&
47+
mktemp -d /tmp/pg_upgrade_check-XXXXXX) 2>/dev/null`
48+
if [ ! -d "$dir" ]; then
5149
dir=/tmp/pg_upgrade_check-$$-$RANDOM
5250
(umask 077 && mkdir "$dir")
53-
} ||
54-
{
55-
echo "could not create socket temporary directory in \"/tmp\""
56-
exit 1
57-
}
58-
51+
if [ ! -d "$dir" ]; then
52+
echo "could not create socket temporary directory in \"/tmp\""
53+
exit 1
54+
fi
55+
fi
56+
set -e
5957
PGHOST=$dir
6058
trap 'rm -rf "$PGHOST"' 0
6159
trap 'exit 3' 1 2 13 15

0 commit comments

Comments
 (0)