| 1 | package main |
| 2 | |
| 3 | import ( |
| 4 | "fmt" |
| 5 | |
| 6 | "reasonix/internal/agent" |
| 7 | "reasonix/internal/boot" |
| 8 | "reasonix/internal/control" |
| 9 | "reasonix/internal/provider" |
| 10 | ) |
| 11 | |
| 12 | func (a *App) buildLegacySettingReplacement( |
| 13 | tab *WorkspaceTab, |
| 14 | runtime normalizedTabRuntime, |
| 15 | opts boot.Options, |
| 16 | oldCtrl control.SessionAPI, |
| 17 | carried []provider.Message, |
| 18 | prevPath, setting string, |
| 19 | ) (control.SessionAPI, normalizedTabRuntime, string, error) { |
| 20 | if old, ok := oldCtrl.(*control.Controller); ok && old != nil && opts.SessionTemp == nil { |
| 21 | opts.SessionTemp = old.SessionTemp() |
| 22 | } |
| 23 | restoreLegacyEvents := func() {} |
| 24 | if old, ok := oldCtrl.(*control.Controller); ok && old != nil { |
| 25 | var err error |
| 26 | restoreLegacyEvents, err = old.SuspendLegacyEventStoreForImport(a.bootContext()) |
| 27 | if err != nil { |
| 28 | return nil, normalizedTabRuntime{}, "", fmt.Errorf("freeze settings rebuild source: %w", err) |
| 29 | } |
| 30 | } |
| 31 | published := false |
| 32 | defer func() { |
| 33 | if !published { |
| 34 | restoreLegacyEvents() |
| 35 | } |
| 36 | }() |
| 37 | ctrl, err := boot.Build(a.bootContext(), opts) |
| 38 | if err != nil { |
| 39 | return nil, normalizedTabRuntime{}, "", err |
| 40 | } |
| 41 | a.bindControllerDisplayRecorder(ctrl) |
| 42 | configureControllerRuntime(ctrl, oldCtrl, runtime) |
| 43 | path := agent.ContinueSessionPath(prevPath, ctrl.SessionDir(), ctrl.Label()) |
| 44 | if err := a.ensureTabSessionLeaseForRebuild(tab, path, setting); err != nil { |
| 45 | ctrl.Close() |
| 46 | return nil, normalizedTabRuntime{}, "", err |
| 47 | } |
| 48 | restored, err := resumeControllerRuntimeWithMessages(ctrl, carried, path, runtime) |
| 49 | if err != nil { |
| 50 | ctrl.Close() |
| 51 | return nil, normalizedTabRuntime{}, "", err |
| 52 | } |
| 53 | published = true |
| 54 | return ctrl, restored, path, nil |
| 55 | } |
| 56 |