[postgis-tickets] [SCM] PostGIS branch stable-2.5 updated. 2.5.7-4-gbe4c7b69d

git at osgeo.org git at osgeo.org
Fri Aug 5 23:49:13 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-2.5 has been updated
       via  be4c7b69d697d0819aa68b8ca3af39a95936c1eb (commit)
      from  022edde0996644f506fd8a76b86303651cdcdf22 (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 be4c7b69d697d0819aa68b8ca3af39a95936c1eb
Author: Sandro Santilli <strk at kbt.io>
Date:   Sat Aug 6 07:07:48 2022 +0200

    Guard against downgrades
    
    Closes #5202 in 2.5 branch (2.5.8dev)

diff --git a/NEWS b/NEWS
index 49ff337ec..7c06e0f6f 100644
--- a/NEWS
+++ b/NEWS
@@ -1,8 +1,10 @@
-PostGIS 2.5.8
+PostGIS 2.5.8dev
 2022/xx/xx
 
  * Bug fixes *
 
+  - #5202, Guard against downgrades (Sandro Santilli)
+
 PostGIS 2.5.7
 2022/07/19
 
diff --git a/utils/postgis_proc_upgrade.pl b/utils/postgis_proc_upgrade.pl
index 7618d5e8f..fd42dcf64 100755
--- a/utils/postgis_proc_upgrade.pl
+++ b/utils/postgis_proc_upgrade.pl
@@ -70,6 +70,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;
@@ -108,10 +109,11 @@ 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 = $1 . "." . $2;
-	$version_to_num = 100 * $1 + $2;
+    $version_to_full = $1 . '.' . $2 . '.' . $3 . $4;
+    $version_to = $1 . "." . $2;
+    $version_to_num = 100 * $1 + $2;
 }
 else
 {
@@ -120,7 +122,7 @@ else
 
 print qq{
 --
--- UPGRADE SCRIPT TO PostGIS $version_to
+-- UPGRADE SCRIPT TO PostGIS $version_to_full
 --
 
 };
@@ -136,9 +138,9 @@ print "SET search_path TO $schema;\n" if $schema;
 #
 while(<DATA>)
 {
-	s/NEWVERSION/$version_to/g;
-  s/MODULE/$module/g;
-	print;
+    s/NEWVERSION/$version_to_full/g;
+    s/MODULE/$module/g;
+    print;
 }
 
 #
@@ -471,38 +473,79 @@ CREATE OR REPLACE FUNCTION postgis_major_version_check()
 RETURNS text
 AS '
 DECLARE
-	old_scripts text;
-	new_scripts text;
-	old_maj text;
-	new_maj text;
+    old_scripts text;
+    new_scripts text;
+    old_ver_int int[];
+    new_ver_int int[];
+    old_maj text;
+    new_maj text;
 BEGIN
-	--
-	-- This uses postgis_lib_version() rather then
-	-- MODULE_scripts_installed() as in 1.0 because
-	-- in the 1.0 => 1.1 transition that would result
-	-- in an impossible upgrade:
-	--
-	--   from 0.3.0 to 1.1.0
-	--
-	-- Next releases will still be ok as
-	-- postgis_lib_version() and MODULE_scripts_installed()
-	-- would both return actual PostGIS release number.
-	--
-	BEGIN
-		SELECT into old_scripts MODULE_lib_version();
-	EXCEPTION WHEN OTHERS THEN
-		RAISE DEBUG ''Got %'', SQLERRM;
-		SELECT into old_scripts MODULE_scripts_installed();
-	END;
-	SELECT into new_scripts ''NEWVERSION'';
-	SELECT into old_maj pg_catalog.substring(old_scripts, 1, 2);
-	SELECT into new_maj pg_catalog.substring(new_scripts, 1, 2);
-
-	IF old_maj != new_maj THEN
-		RAISE EXCEPTION ''Upgrade of MODULE from version % to version % requires a dump/reload. See PostGIS manual for instructions'', old_scripts, new_scripts;
-	ELSE
-		RETURN ''Scripts versions checked for upgrade: ok'';
-	END IF;
+    --
+    -- This uses postgis_lib_version() rather then
+    -- MODULE_scripts_installed() as in 1.0 because
+    -- in the 1.0 => 1.1 transition that would result
+    -- in an impossible upgrade:
+    --
+    --   from 0.3.0 to 1.1.0
+    --
+    -- Next releases will still be ok as
+    -- postgis_lib_version() and MODULE_scripts_installed()
+    -- would both return actual PostGIS release number.
+    --
+    BEGIN
+        SELECT into old_scripts MODULE_lib_version();
+    EXCEPTION WHEN OTHERS THEN
+        RAISE DEBUG 'Got %', SQLERRM;
+        SELECT into old_scripts MODULE_scripts_installed();
+    END;
+    SELECT into new_scripts 'NEWVERSION';
+
+    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
+    IF new_maj = '3' AND old_maj = '2' THEN
+        old_maj = '3'; -- let's pretend old major = new major
+    END IF;
+
+    IF old_maj != new_maj THEN
+        RAISE EXCEPTION 'Upgrade of MODULE from version % to version % requires a dump/reload. See PostGIS manual for instructions', old_scripts, new_scripts;
+    END IF;
 END
 '
 LANGUAGE 'plpgsql';

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

Summary of changes:
 NEWS                          |   4 +-
 utils/postgis_proc_upgrade.pl | 119 ++++++++++++++++++++++++++++--------------
 2 files changed, 84 insertions(+), 39 deletions(-)


hooks/post-receive
-- 
PostGIS


More information about the postgis-tickets mailing list