Fix version numbering foulups exposed by 10.1. REL_10_1
authorTom Lane <tgl@sss.pgh.pa.us>
Tue, 7 Nov 2017 00:46:52 +0000 (19:46 -0500)
committerTom Lane <tgl@sss.pgh.pa.us>
Tue, 7 Nov 2017 00:46:52 +0000 (19:46 -0500)
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.

configure
configure.in
src/bin/pg_upgrade/exec.c
src/bin/pg_upgrade/server.c

index 353cbe00cae3cffe235cef2aa3b75c756c912684..d9298bf531195a51d828f3a04f07c1db8dc5d73e 100755 (executable)
--- a/configure
+++ b/configure
@@ -16749,7 +16749,7 @@ _ACEOF
 # awk -F is a regex on some platforms, and not on others, so make "." a tab
 PG_VERSION_NUM="`echo "$PACKAGE_VERSION" | sed 's/[A-Za-z].*$//' |
 tr '.' '   ' |
-$AWK '{printf "%d%02d%02d", $1, $2, (NF >= 3) ? $3 : 0}'`"
+$AWK '{printf "%d%04d", $1, $2}'`"
 
 cat >>confdefs.h <<_ACEOF
 #define PG_VERSION_NUM $PG_VERSION_NUM
index b553475c379b279998a7bcd9c3325d5b11d10d21..c694f7bd9267a93d7dbba6355e02a7055e39e7f0 100644 (file)
@@ -2193,7 +2193,7 @@ AC_DEFINE_UNQUOTED(PG_VERSION_STR,
 # awk -F is a regex on some platforms, and not on others, so make "." a tab
 [PG_VERSION_NUM="`echo "$PACKAGE_VERSION" | sed 's/[A-Za-z].*$//' |
 tr '.' '   ' |
-$AWK '{printf "%d%02d%02d", $1, $2, (NF >= 3) ? $3 : 0}'`"]
+$AWK '{printf "%d%04d", $1, $2}'`"]
 AC_DEFINE_UNQUOTED(PG_VERSION_NUM, $PG_VERSION_NUM, [PostgreSQL version as a number])
 AC_SUBST(PG_VERSION_NUM)
 
index 1cf64e1a4509501e32a32b68951b4ee387d84a70..59ddc16d6b863ed2ccd6dd810982676ff0d95ffe 100644 (file)
@@ -26,7 +26,7 @@ static int    win32_check_directory_write_permissions(void);
 /*
  * get_bin_version
  *
- * Fetch versions of binaries for cluster.
+ * Fetch major version of binaries for cluster.
  */
 static void
 get_bin_version(ClusterInfo *cluster)
@@ -34,8 +34,8 @@ get_bin_version(ClusterInfo *cluster)
    char        cmd[MAXPGPATH],
                cmd_output[MAX_STRING];
    FILE       *output;
-   int         pre_dot = 0,
-               post_dot = 0;
+   int         v1 = 0,
+               v2 = 0;
 
    snprintf(cmd, sizeof(cmd), "\"%s/pg_ctl\" --version", cluster->bindir);
 
@@ -46,14 +46,19 @@ get_bin_version(ClusterInfo *cluster)
 
    pclose(output);
 
-   /* Remove trailing newline */
-   if (strchr(cmd_output, '\n') != NULL)
-       *strchr(cmd_output, '\n') = '\0';
-
-   if (sscanf(cmd_output, "%*s %*s %d.%d", &pre_dot, &post_dot) < 1)
+   if (sscanf(cmd_output, "%*s %*s %d.%d", &v1, &v2) < 1)
        pg_fatal("could not get pg_ctl version output from %s\n", cmd);
 
-   cluster->bin_version = (pre_dot * 100 + post_dot) * 100;
+   if (v1 < 10)
+   {
+       /* old style, e.g. 9.6.1 */
+       cluster->bin_version = v1 * 10000 + v2 * 100;
+   }
+   else
+   {
+       /* new style, e.g. 10.1 */
+       cluster->bin_version = v1 * 10000;
+   }
 }
 
 
index 3e3323a6e8a4a6aacfc0b9056a908540d8b6ca10..a91f18916c72524401f93584c8a0bc4786fbdabb 100644 (file)
@@ -156,8 +156,8 @@ get_major_server_version(ClusterInfo *cluster)
 {
    FILE       *version_fd;
    char        ver_filename[MAXPGPATH];
-   int         integer_version = 0;
-   int         fractional_version = 0;
+   int         v1 = 0,
+               v2 = 0;
 
    snprintf(ver_filename, sizeof(ver_filename), "%s/PG_VERSION",
             cluster->pgdata);
@@ -165,13 +165,21 @@ get_major_server_version(ClusterInfo *cluster)
        pg_fatal("could not open version file: %s\n", ver_filename);
 
    if (fscanf(version_fd, "%63s", cluster->major_version_str) == 0 ||
-       sscanf(cluster->major_version_str, "%d.%d", &integer_version,
-              &fractional_version) < 1)
+       sscanf(cluster->major_version_str, "%d.%d", &v1, &v2) < 1)
        pg_fatal("could not parse PG_VERSION file from %s\n", cluster->pgdata);
 
    fclose(version_fd);
 
-   return (100 * integer_version + fractional_version) * 100;
+   if (v1 < 10)
+   {
+       /* old style, e.g. 9.6.1 */
+       return v1 * 10000 + v2 * 100;
+   }
+   else
+   {
+       /* new style, e.g. 10.1 */
+       return v1 * 10000;
+   }
 }