Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit d0c80c1

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 92d830f commit d0c80c1

File tree

4 files changed

+29
-16
lines changed

4 files changed

+29
-16
lines changed

configure

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16807,7 +16807,7 @@ _ACEOF
1680716807
# awk -F is a regex on some platforms, and not on others, so make "." a tab
1680816808
PG_VERSION_NUM="`echo "$PACKAGE_VERSION" | sed 's/[A-Za-z].*$//' |
1680916809
tr '.' ' ' |
16810-
$AWK '{printf "%d%02d%02d", $1, $2, (NF >= 3) ? $3 : 0}'`"
16810+
$AWK '{printf "%d%04d", $1, $2}'`"
1681116811

1681216812
cat >>confdefs.h <<_ACEOF
1681316813
#define PG_VERSION_NUM $PG_VERSION_NUM

configure.in

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2181,7 +2181,7 @@ AC_DEFINE_UNQUOTED(PG_VERSION_STR,
21812181
# awk -F is a regex on some platforms, and not on others, so make "." a tab
21822182
[PG_VERSION_NUM="`echo "$PACKAGE_VERSION" | sed 's/[A-Za-z].*$//' |
21832183
tr '.' ' ' |
2184-
$AWK '{printf "%d%02d%02d", $1, $2, (NF >= 3) ? $3 : 0}'`"]
2184+
$AWK '{printf "%d%04d", $1, $2}'`"]
21852185
AC_DEFINE_UNQUOTED(PG_VERSION_NUM, $PG_VERSION_NUM, [PostgreSQL version as a number])
21862186
AC_SUBST(PG_VERSION_NUM)
21872187

src/bin/pg_upgrade/exec.c

Lines changed: 14 additions & 9 deletions
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

src/bin/pg_upgrade/server.c

Lines changed: 13 additions & 5 deletions
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)