public inbox for [email protected]  
help / color / mirror / Atom feed
From: Aditya Toshniwal <[email protected]>
To: Akshay Joshi <[email protected]>
Cc: pgadmin-hackers <[email protected]>
Subject: Re: [pgAdmin][RM4421] Inno setup script version compare fix
Date: Tue, 2 Jul 2019 14:51:18 +0530
Message-ID: <CAM9w-_k6dPTtdWpQFNJ0+nYUP0nafzJS4kn+WXXmQ4xyPTHemg@mail.gmail.com> (raw)
In-Reply-To: <CANxoLDdjtQK1sqmAhE4JsjdiM_5rvZnF31Po8NeDfGbmWyA8Aw@mail.gmail.com>
References: <CAM9w-_mnD3MQBMLZdY9oKwSsu6fiwWUFY9ZZob6fPUfiormy1A@mail.gmail.com>
	<CANxoLDdjtQK1sqmAhE4JsjdiM_5rvZnF31Po8NeDfGbmWyA8Aw@mail.gmail.com>

Hi Hackers,

Attached is the updated patch. Instead of float comparison, string
comparison is done now with the help of a nice article here -
http://www.arvydas.co.uk/2015/04/compare-version-strings-with-innosetup/

Kindly review.

On Tue, Jul 2, 2019 at 2:34 PM Akshay Joshi <[email protected]>
wrote:

> Hi Aditya
>
> I have asked Paresh to review the patch, he has given some review
> comments. Please fix those and the updated patch asap.
>
> On Tue, Jul 2, 2019 at 1:38 PM Aditya Toshniwal <
> [email protected]> wrote:
>
>> Hi Hackers,
>>
>> Attached is the patch to fix a potential issue where version compare
>> while upgrading will be incorrect. Currently, it is comparing strings. So
>> while comparing '4.9' and '4.10' it will consider '4.9' as greater.
>> The patch will convert the values to float and compare.
>>
>> Kindly review.
>>
>> --
>> Thanks and Regards,
>> Aditya Toshniwal
>> Software Engineer | EnterpriseDB India | Pune
>> "Don't Complain about Heat, Plant a TREE"
>>
>
>
> --
> *Thanks & Regards*
> *Akshay Joshi*
>
> *Sr. Software Architect*
> *EnterpriseDB Software India Private Limited*
> *Mobile: +91 976-788-8246*
>


-- 
Thanks and Regards,
Aditya Toshniwal
Software Engineer | EnterpriseDB India | Pune
"Don't Complain about Heat, Plant a TREE"


Attachments:

  [application/octet-stream] win.ver_compare_v2.patch (2.6K, 3-win.ver_compare_v2.patch)
  download | inline diff:
diff --git a/pkg/win32/installer.iss.in b/pkg/win32/installer.iss.in
index 299d7e27..4546fdf4 100644
--- a/pkg/win32/installer.iss.in
+++ b/pkg/win32/installer.iss.in
@@ -64,6 +64,81 @@ Root: HKLM; Subkey: "Software\{#MyAppName}\{#MyAppVersion}"; ValueType: string;
 var
   UpgradeMode: Boolean;
 
+// Procedure to split a string into an array of integers
+procedure Explode(var Dest: TArrayOfInteger; Text: String; Separator: String);
+var
+  i, p: Integer;
+begin
+  i := 0;
+  repeat
+    SetArrayLength(Dest, i+1);
+    p := Pos(Separator,Text);
+    if p > 0 then begin
+      Dest[i] := StrToInt(Copy(Text, 1, p-1));
+      Text := Copy(Text, p + Length(Separator), Length(Text));
+      i := i + 1;
+    end else begin
+      Dest[i] := StrToInt(Text);
+      Text := '';
+    end;
+  until Length(Text)=0;
+end;
+
+// Function compares version strings numerically:
+//     * when v1 = v2, result = 0
+//     * when v1 < v2, result = -1
+//     * when v1 > v2, result = 1
+//
+// Supports version numbers with trailing zeroes, for example 1.02.05.
+// Supports comparison of two version number of different lengths, for example
+//     CompareVersions('1.2', '2.0.3')
+// When any of the parameters is '' (empty string) it considers version number as 0
+function CompareVersions(v1: String; v2: String): Integer;
+var
+  v1parts: TArrayOfInteger;
+  v2parts: TArrayOfInteger;
+  i: Integer;
+begin
+  if v1 = '' then
+  begin
+    v1 := '0';
+  end;
+
+  if v2 = '' then
+  begin
+    v2 := '0';
+  end;
+
+  Explode(v1parts, v1, '.');
+  Explode(v2parts, v2, '.');
+
+  if (GetArrayLength(v1parts) > GetArrayLength(v2parts)) then
+  begin
+    SetArrayLength(v2parts, GetArrayLength(v1parts))
+  end else if (GetArrayLength(v2parts) > GetArrayLength(v1parts)) then
+  begin
+    SetArrayLength(v1parts, GetArrayLength(v2parts))
+  end;
+
+  for i := 0 to GetArrayLength(v1parts) - 1 do
+  begin
+    if v1parts[i] > v2parts[i] then
+    begin
+      { v1 is greater }
+      Result := 1;
+      exit;
+    end else if v1parts[i] < v2parts[i] then
+    begin
+      { v2 is greater }
+      Result := -1;
+      exit;
+    end;
+  end;
+
+  { Are Equal }
+  Result := 0;
+end;
+
 function IsPathValid(Path: string): Boolean;
 var
   I: Integer;
@@ -103,7 +178,7 @@ begin
   begin
 	UpgradeMode := True;
     RegQueryStringValue(HKEY_LOCAL_MACHINE,'Software\{#MyAppName}\{#MyAppVersion}', 'Version', Version);
-    if Version > '{#MyAppFullVersion}' then
+    if CompareVersions(Version, '{#MyAppFullVersion}') = -1 then
     begin
       MsgBox(ExpandConstant('{cm:NewerVersionExists}' + '(v' + Version + ') is already installed' ), mbInformation, MB_OK);
       Result := False;


view thread (4+ messages)  latest in thread

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: [email protected]
  Cc: [email protected], [email protected]
  Subject: Re: [pgAdmin][RM4421] Inno setup script version compare fix
  In-Reply-To: <CAM9w-_k6dPTtdWpQFNJ0+nYUP0nafzJS4kn+WXXmQ4xyPTHemg@mail.gmail.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox