Implement controlled app launch (T-401)

This commit is contained in:
ila
2026-07-19 21:10:59 +08:00
parent d0cf333394
commit 87083c387f
32 changed files with 1802 additions and 31 deletions
+26 -2
View File
@@ -195,9 +195,13 @@ func (service *InstallService) Install(request InstallRequest) (InstallResult, e
SHA256: file.SHA256,
})
}
record.Entrypoint = expectation.App.Entrypoint
record.WorkingDirectory = extracted.WorkingDir
record.MinOS = expectation.App.MinOS
record.RequiresAdmin = expectation.App.RequiresAdmin
var recordWriteErr error
switcher := installer.NewSwitcher(func(currentPath string) error {
switcher := installer.NewSwitcherWithPreSwitchCheck(func(currentPath string) error {
if err := service.health(currentPath); err != nil {
return err
}
@@ -206,7 +210,7 @@ func (service *InstallService) Install(request InstallRequest) (InstallResult, e
return fmt.Errorf("%w: %w", ErrInstallRecordWrite, err)
}
return nil
})
}, service.preSwitchCheck(appRoot, record.ID, expectation.App.Entrypoint))
if err := switcher.Switch(appRoot); err != nil {
return InstallResult{}, service.installError(stageForSwitchError(err, recordWriteErr), err)
}
@@ -218,6 +222,26 @@ func (service *InstallService) Install(request InstallRequest) (InstallResult, e
}, nil
}
func (service *InstallService) preSwitchCheck(
appRoot string,
appID string,
entrypoint string,
) installer.PreSwitchCheck {
return func() error {
running, err := service.targetState.IsRunning(
appID,
filepath.Join(appRoot, "current", entrypoint),
)
if err != nil {
return fmt.Errorf("%w: %w", ErrTargetStateCheck, err)
}
if running {
return ErrTargetRunning
}
return nil
}
}
func (service *InstallService) preExtractCheck(
appRoot string,
appID string,