[postgis-tickets] [SCM] PostGIS branch stable-3.0 updated. 3.0.6-5-g1c3ae9145

git at osgeo.org git at osgeo.org
Fri Aug 5 23:38:58 PDT 2022


This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "PostGIS".

The branch, stable-3.0 has been updated
       via  1c3ae9145e4b71abac8d70064173d73c4df326b0 (commit)
      from  453bebc078518b109cc756da1ecbdc9260b15bc6 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
commit 1c3ae9145e4b71abac8d70064173d73c4df326b0
Author: Sandro Santilli <strk at kbt.io>
Date:   Sat Aug 6 07:07:48 2022 +0200

    Guard against downgrades
    
    References #5202 in 3.0 branch (3.0.7dev)

diff --git a/NEWS b/NEWS
index d56c8e7c2..37c34ced6 100644
--- a/NEWS
+++ b/NEWS
@@ -1,4 +1,9 @@
-PostGIS 3.0.6
+PostGIS 3.0.7dev
+2022/xx/xx
+
+* Bug Fixes
+  - #5202, Guard against downgrades (Sandro Santilli)
+
 2022/07/20
 
 * Bug Fixes and Enhancements *
diff --git a/utils/postgis_proc_upgrade.pl b/utils/postgis_proc_upgrade.pl
index 8c2761ac9..a011b3e11 100755
--- a/utils/postgis_proc_upgrade.pl
+++ b/utils/postgis_proc_upgrade.pl
@@ -72,6 +72,7 @@ my $sql_file = $ARGV[0];
 my $module = 'postgis';
 my $soname = '';
 my $version_to = "";
+my $version_to_full = "";
 my $version_to_num = 0;
 my $version_from = $ARGV[1];
 my $version_from_num = 0;
@@ -111,8 +112,9 @@ close(INPUT);
 die "Unable to locate target new version number in $sql_file\n"
   if( !$version_to );
 
-if ( $version_to =~ /(\d+)\.(\d+)\..*/ )
+if ( $version_to =~ /(\d+)\.(\d+)\.(\d+)([^' ]*)/ )
 {
+    $version_to_full = $1 . '.' . $2 . '.' . $3 . $4;
     $version_to = $1 . "." . $2;
     $version_to_num = 100 * $1 + $2;
 }
@@ -123,7 +125,7 @@ else
 
 print qq{
 --
--- UPGRADE SCRIPT TO PostGIS $version_to
+-- UPGRADE SCRIPT TO PostGIS $version_to_full
 --
 
 };
@@ -139,7 +141,7 @@ print "SET search_path TO $schema;\n" if $schema;
 #
 while(<DATA>)
 {
-    s/NEWVERSION/$version_to/g;
+    s/NEWVERSION/$version_to_full/g;
     s/MODULE/$module/g;
     print;
 }
@@ -523,6 +525,8 @@ DO $$
 DECLARE
     old_scripts text;
     new_scripts text;
+    old_ver_int int[];
+    new_ver_int int[];
     old_maj text;
     new_maj text;
 BEGIN
@@ -545,8 +549,43 @@ BEGIN
         SELECT into old_scripts MODULE_scripts_installed();
     END;
     SELECT into new_scripts 'NEWVERSION';
-    SELECT into old_maj pg_catalog.substring(old_scripts, 1, 1);
-    SELECT into new_maj pg_catalog.substring(new_scripts, 1,1);
+
+    BEGIN
+        new_ver_int := pg_catalog.string_to_array(
+            pg_catalog.regexp_replace(
+                new_scripts,
+                '[^\d.].*',
+                ''
+            ),
+            '.'
+        )::int[];
+    EXCEPTION WHEN OTHERS THEN
+        RAISE EXCEPTION 'Cannot parse new version % into integers', new_scripts;
+    END;
+
+    BEGIN
+        old_ver_int := pg_catalog.string_to_array(
+            pg_catalog.regexp_replace(
+                old_scripts,
+                '[^\d.].*',
+                ''
+            ),
+            '.'
+        )::int[];
+    EXCEPTION WHEN OTHERS THEN
+        RAISE EXCEPTION 'Cannot parse old version % into integers', old_scripts;
+    END;
+
+    -- Guard against downgrade
+    IF new_ver_int < old_ver_int
+    THEN
+        RAISE EXCEPTION 'Downgrade of MODULE from version % to version % is forbidden', old_scripts, new_scripts;
+    END IF;
+
+
+    -- Check for hard-upgrade being required
+    SELECT into old_maj pg_catalog.substring(old_scripts,1, 1);
+    SELECT into new_maj pg_catalog.substring(new_scripts,1, 1);
 
     -- 2.x to 3.x was upgrade-compatible, see
     -- https://trac.osgeo.org/postgis/ticket/4170#comment:1

-----------------------------------------------------------------------

Summary of changes:
 NEWS                          |  7 ++++++-
 utils/postgis_proc_upgrade.pl | 49 ++++++++++++++++++++++++++++++++++++++-----
 2 files changed, 50 insertions(+), 6 deletions(-)


hooks/post-receive
-- 
PostGIS


More information about the postgis-tickets mailing list