Skip to content

Commit 958fe54

Browse files
committed
Fix version numbering foulups exposed by 10.1.
configure computed PG_VERSION_NUM incorrectly. (Coulda sworn I tested that logic back when, but it had an obvious thinko.) pg_upgrade had not been taught about the new dispensation with just one part in the major version number. Both things accidentally failed to fail with 10.0, but with 10.1 we got the wrong results. Per buildfarm.
1 parent 0b35d54 commit 958fe54

File tree

4 files changed

+29
-16
lines changed

4 files changed

+29
-16
lines changed

Diff for: configure

+1-1
Original file line numberDiff line numberDiff line change
@@ -16749,7 +16749,7 @@ _ACEOF
1674916749
# awk -F is a regex on some platforms, and not on others, so make "." a tab
1675016750
PG_VERSION_NUM="`echo "$PACKAGE_VERSION" | sed 's/[A-Za-z].*$//' |
1675116751
tr '.' ' ' |
16752-
$AWK '{printf "%d%02d%02d", $1, $2, (NF >= 3) ? $3 : 0}'`"
16752+
$AWK '{printf "%d%04d", $1, $2}'`"
1675316753

1675416754
cat >>confdefs.h <<_ACEOF
1675516755
#define PG_VERSION_NUM $PG_VERSION_NUM

Diff for: configure.in

+1-1
Original file line numberDiff line numberDiff line change
@@ -2193,7 +2193,7 @@ AC_DEFINE_UNQUOTED(PG_VERSION_STR,
21932193
# awk -F is a regex on some platforms, and not on others, so make "." a tab
21942194
[PG_VERSION_NUM="`echo "$PACKAGE_VERSION" | sed 's/[A-Za-z].*$//' |
21952195
tr '.' ' ' |
2196-
$AWK '{printf "%d%02d%02d", $1, $2, (NF >= 3) ? $3 : 0}'`"]
2196+
$AWK '{printf "%d%04d", $1, $2}'`"]
21972197
AC_DEFINE_UNQUOTED(PG_VERSION_NUM, $PG_VERSION_NUM, [PostgreSQL version as a number])
21982198
AC_SUBST(PG_VERSION_NUM)
21992199

Diff for: src/bin/pg_upgrade/exec.c

+14-9
Original file line numberDiff line numberDiff line change
@@ -26,16 +26,16 @@ static int win32_check_directory_write_permissions(void);
2626
/*
2727
* get_bin_version
2828
*
29-
* Fetch versions of binaries for cluster.
29+
* Fetch major version of binaries for cluster.
3030
*/
3131
static void
3232
get_bin_version(ClusterInfo *cluster)
3333
{
3434
char cmd[MAXPGPATH],
3535
cmd_output[MAX_STRING];
3636
FILE *output;
37-
int pre_dot = 0,
38-
post_dot = 0;
37+
int v1 = 0,
38+
v2 = 0;
3939

4040
snprintf(cmd, sizeof(cmd), "\"%s/pg_ctl\" --version", cluster->bindir);
4141

@@ -46,14 +46,19 @@ get_bin_version(ClusterInfo *cluster)
4646

4747
pclose(output);
4848

49-
/* Remove trailing newline */
50-
if (strchr(cmd_output, '\n') != NULL)
51-
*strchr(cmd_output, '\n') = '\0';
52-
53-
if (sscanf(cmd_output, "%*s %*s %d.%d", &pre_dot, &post_dot) < 1)
49+
if (sscanf(cmd_output, "%*s %*s %d.%d", &v1, &v2) < 1)
5450
pg_fatal("could not get pg_ctl version output from %s\n", cmd);
5551

56-
cluster->bin_version = (pre_dot * 100 + post_dot) * 100;
52+
if (v1 < 10)
53+
{
54+
/* old style, e.g. 9.6.1 */
55+
cluster->bin_version = v1 * 10000 + v2 * 100;
56+
}
57+
else
58+
{
59+
/* new style, e.g. 10.1 */
60+
cluster->bin_version = v1 * 10000;
61+
}
5762
}
5863

5964

Diff for: src/bin/pg_upgrade/server.c

+13-5
Original file line numberDiff line numberDiff line change
@@ -156,22 +156,30 @@ get_major_server_version(ClusterInfo *cluster)
156156
{
157157
FILE *version_fd;
158158
char ver_filename[MAXPGPATH];
159-
int integer_version = 0;
160-
int fractional_version = 0;
159+
int v1 = 0,
160+
v2 = 0;
161161

162162
snprintf(ver_filename, sizeof(ver_filename), "%s/PG_VERSION",
163163
cluster->pgdata);
164164
if ((version_fd = fopen(ver_filename, "r")) == NULL)
165165
pg_fatal("could not open version file: %s\n", ver_filename);
166166

167167
if (fscanf(version_fd, "%63s", cluster->major_version_str) == 0 ||
168-
sscanf(cluster->major_version_str, "%d.%d", &integer_version,
169-
&fractional_version) < 1)
168+
sscanf(cluster->major_version_str, "%d.%d", &v1, &v2) < 1)
170169
pg_fatal("could not parse PG_VERSION file from %s\n", cluster->pgdata);
171170

172171
fclose(version_fd);
173172

174-
return (100 * integer_version + fractional_version) * 100;
173+
if (v1 < 10)
174+
{
175+
/* old style, e.g. 9.6.1 */
176+
return v1 * 10000 + v2 * 100;
177+
}
178+
else
179+
{
180+
/* new style, e.g. 10.1 */
181+
return v1 * 10000;
182+
}
175183
}
176184

177185

0 commit comments

Comments
 (0)