@@ -66,7 +66,7 @@ DestDir: "{app}"; Flags: ignoreversion; Source:"{#LayoutDir}\GVFS.Service.exe";
6666; goes directly to {app} so the restarted service has PendingUpgradeHandler code.
6767; The service is briefly stopped/restarted (mounts are independent processes).
6868DestDir : " {app} \PendingUpgrade" ; Flags : ignoreversion recursesubdirs ; Source :" {#LayoutDir}\*" ; Check : IsStagingInstall
69- DestDir : " {app} " ; Flags : ignoreversion ; Source :" {#LayoutDir}\GVFS.Service.exe" ; AfterInstall : StagingUpdateService; Check : IsStagingInstall
69+ DestDir : " {app} " ; Flags : ignoreversion ; Source :" {#LayoutDir}\GVFS.Service.exe" ; Check : IsStagingInstall
7070
7171[Dirs]
7272Name : " {app} \ProgramData\{#ServiceName}" ; Permissions: users-readexec
@@ -166,11 +166,17 @@ var
166166 ResultCode: integer;
167167begin
168168 Log(' StopService: stopping: ' + ServiceName);
169- // ErrorCode 1060 means service not installed, 1062 means service not started
170- if not Exec(ExpandConstant(' {sys}\SC.EXE' ), ' stop ' + ServiceName, ' ' , SW_HIDE, ewWaitUntilTerminated, ResultCode) and (ResultCode <> 1060 ) and (ResultCode <> 1062 ) then
169+ if not Exec(ExpandConstant(' {sys}\SC.EXE' ), ' stop ' + ServiceName, ' ' , SW_HIDE, ewWaitUntilTerminated, ResultCode) then
171170 begin
171+ Log(' StopService: Failed to launch sc.exe' );
172172 RaiseException(' Fatal: Could not stop service: ' + ServiceName);
173173 end ;
174+ // 1060 = service not installed, 1062 = service not started
175+ if (ResultCode <> 0 ) and (ResultCode <> 1060 ) and (ResultCode <> 1062 ) then
176+ begin
177+ Log(' StopService: sc stop returned error code ' + IntToStr(ResultCode));
178+ RaiseException(' Fatal: Could not stop service: ' + ServiceName + ' (exit code ' + IntToStr(ResultCode) + ' )' );
179+ end ;
174180end ;
175181
176182procedure WaitForServiceProcessToExit (ServiceName: string);
@@ -328,9 +334,14 @@ begin
328334
329335 try
330336 Log(' StagingUpdateService: Starting service with new binary' );
331- if not Exec(ExpandConstant(' {sys}\SC.EXE' ), ' start GVFS.Service' , ' ' , SW_HIDE, ewWaitUntilTerminated, ResultCode) then
337+ if Exec(ExpandConstant(' {sys}\SC.EXE' ), ' start GVFS.Service' , ' ' , SW_HIDE, ewWaitUntilTerminated, ResultCode) then
338+ begin
339+ if ResultCode <> 0 then
340+ Log(' StagingUpdateService: Warning - sc start returned error code ' + IntToStr(ResultCode));
341+ end
342+ else
332343 begin
333- Log(' StagingUpdateService: Warning - could not start service: ' + SysErrorMessage(ResultCode) );
344+ Log(' StagingUpdateService: Warning - could not launch sc.exe ' );
334345 end ;
335346
336347 WriteOnDiskVersion16CapableFile();
@@ -721,6 +732,11 @@ begin
721732 // complete and safe to apply.
722733 SaveStringToFile(ExpandConstant(' {app}\PendingUpgrade\.ready' ), ' ' , False);
723734 Log(' CurStepChanged: Wrote PendingUpgrade .ready marker' );
735+
736+ // Start the service AFTER .ready is written. Previously this
737+ // was an AfterInstall hook on GVFS.Service.exe, but that races:
738+ // the service's debounce timer could fire before .ready exists.
739+ StagingUpdateService();
724740 end ;
725741 MigrateConfigAndStatusCacheFiles();
726742 if (not KeepMountsRunning) and (ExpandConstant(' {param:REMOUNTREPOS|true}' ) = ' true' ) then
0 commit comments