Skip to content

Commit dbbfe25

Browse files
committed
installer: do detect downgrades _to_ -rc<N> versions
The `-rc<N>` versions reduce to a registry value `CurrentVersion` that looks like it is a _later_ version than the final version. Example: v2.24.0.windows.1 would reduce to `2.24.0.1` while v2.24.0.rc2.windows.1` would reduce to `2.24.0.2.1`, i.e. the -rc2 version would be mistaken for being an _upgrade_ relative to the final v2.24.0. To fix this, let's detect whether the version we are about to install, or the version we want to upgrade, are potentially `-rc<N>` versions, simply by counting the dots, and fall back to the (a little bit more expensive) test via `git version` if that is the case. Signed-off-by: Johannes Schindelin <[email protected]>
1 parent 53c07da commit dbbfe25

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

installer/install.iss

+12-2
Original file line numberDiff line numberDiff line change
@@ -869,15 +869,25 @@ begin
869869
ExitProcess(0);
870870
end;
871871
872+
function CountDots(S:String):Integer;
873+
var
874+
i:Integer;
875+
begin
876+
Result:=0;
877+
for i:=1 to Length(S) do
878+
if (S[i]=#46) then
879+
Result:=Result+1;
880+
end;
881+
872882
function IsDowngrade(CurrentVersion,PreviousVersion:String):Boolean;
873883
var
874884
Path:String;
875885
i,j,CurrentLength,PreviousLength:Integer;
876886
begin
877887
Result:=(VersionCompare(CurrentVersion,PreviousVersion)<0);
878888
#ifdef GIT_VERSION
879-
if Result then begin
880-
// maybe the previous version was a prerelease?
889+
if Result or (CountDots(CurrentVersion)>3) or (CountDots(PreviousVersion)>3) then begin
890+
// maybe the previous version was a prerelease (prereleases have five numbers: v2.24.0-rc1.windows.1 reduces to '2.24.0.1.1')?
881891
if (RegQueryStringValue(HKEY_LOCAL_MACHINE,'Software\GitForWindows','InstallPath',Path))
882892
and (Exec(ExpandConstant('{cmd}'),'/c ""'+Path+'\cmd\git.exe" version >"'+ExpandConstant('{tmp}')+'\previous.version""','',SW_HIDE,ewWaitUntilTerminated,i))
883893
and (i=0) then begin

0 commit comments

Comments
 (0)