public inbox for [email protected]  
help / color / mirror / Atom feed
[pgAdmin][RM4421] Inno setup script version compare fix
4+ messages / 2 participants
[nested] [flat]

* [pgAdmin][RM4421] Inno setup script version compare fix
@ 2019-07-02 08:07 Aditya Toshniwal <[email protected]>
  2019-07-02 09:04 ` Re: [pgAdmin][RM4421] Inno setup script version compare fix Akshay Joshi <[email protected]>
  0 siblings, 1 reply; 4+ messages in thread

From: Aditya Toshniwal @ 2019-07-02 08:07 UTC (permalink / raw)
  To: pgadmin-hackers

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"


Attachments:

  [application/octet-stream] win.ver_compare.patch (663B, 3-win.ver_compare.patch)
  download | inline diff:
diff --git a/pkg/win32/installer.iss.in b/pkg/win32/installer.iss.in
index 299d7e27..245f5d93 100644
--- a/pkg/win32/installer.iss.in
+++ b/pkg/win32/installer.iss.in
@@ -103,7 +103,8 @@ begin
   begin
 	UpgradeMode := True;
     RegQueryStringValue(HKEY_LOCAL_MACHINE,'Software\{#MyAppName}\{#MyAppVersion}', 'Version', Version);
-    if Version > '{#MyAppFullVersion}' then
+    //pgAdmin version can be converted to float directly
+    if StrToFloat(Version) > StrToFloat('{#MyAppFullVersion}') then
     begin
       MsgBox(ExpandConstant('{cm:NewerVersionExists}' + '(v' + Version + ') is already installed' ), mbInformation, MB_OK);
       Result := False;


^ permalink  raw  reply  [nested|flat] 4+ messages in thread

* Re: [pgAdmin][RM4421] Inno setup script version compare fix
  2019-07-02 08:07 [pgAdmin][RM4421] Inno setup script version compare fix Aditya Toshniwal <[email protected]>
@ 2019-07-02 09:04 ` Akshay Joshi <[email protected]>
  2019-07-02 09:21   ` Re: [pgAdmin][RM4421] Inno setup script version compare fix Aditya Toshniwal <[email protected]>
  0 siblings, 1 reply; 4+ messages in thread

From: Akshay Joshi @ 2019-07-02 09:04 UTC (permalink / raw)
  To: Aditya Toshniwal <[email protected]>; +Cc: pgadmin-hackers

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*


^ permalink  raw  reply  [nested|flat] 4+ messages in thread

* Re: [pgAdmin][RM4421] Inno setup script version compare fix
  2019-07-02 08:07 [pgAdmin][RM4421] Inno setup script version compare fix Aditya Toshniwal <[email protected]>
  2019-07-02 09:04 ` Re: [pgAdmin][RM4421] Inno setup script version compare fix Akshay Joshi <[email protected]>
@ 2019-07-02 09:21   ` Aditya Toshniwal <[email protected]>
  2019-07-02 09:29     ` Re: [pgAdmin][RM4421] Inno setup script version compare fix Akshay Joshi <[email protected]>
  0 siblings, 1 reply; 4+ messages in thread

From: Aditya Toshniwal @ 2019-07-02 09:21 UTC (permalink / raw)
  To: Akshay Joshi <[email protected]>; +Cc: pgadmin-hackers

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;


^ permalink  raw  reply  [nested|flat] 4+ messages in thread

* Re: [pgAdmin][RM4421] Inno setup script version compare fix
  2019-07-02 08:07 [pgAdmin][RM4421] Inno setup script version compare fix Aditya Toshniwal <[email protected]>
  2019-07-02 09:04 ` Re: [pgAdmin][RM4421] Inno setup script version compare fix Akshay Joshi <[email protected]>
  2019-07-02 09:21   ` Re: [pgAdmin][RM4421] Inno setup script version compare fix Aditya Toshniwal <[email protected]>
@ 2019-07-02 09:29     ` Akshay Joshi <[email protected]>
  0 siblings, 0 replies; 4+ messages in thread

From: Akshay Joshi @ 2019-07-02 09:29 UTC (permalink / raw)
  To: Aditya Toshniwal <[email protected]>; +Cc: pgadmin-hackers

Thanks patch applied.

On Tue, Jul 2, 2019 at 2:51 PM Aditya Toshniwal <
[email protected]> wrote:

> 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"
>


-- 
*Thanks & Regards*
*Akshay Joshi*

*Sr. Software Architect*
*EnterpriseDB Software India Private Limited*
*Mobile: +91 976-788-8246*


^ permalink  raw  reply  [nested|flat] 4+ messages in thread


end of thread, other threads:[~2019-07-02 09:29 UTC | newest]

Thread overview: 4+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2019-07-02 08:07 [pgAdmin][RM4421] Inno setup script version compare fix Aditya Toshniwal <[email protected]>
2019-07-02 09:04 ` Akshay Joshi <[email protected]>
2019-07-02 09:21   ` Aditya Toshniwal <[email protected]>
2019-07-02 09:29     ` Akshay Joshi <[email protected]>

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