Resume resumes a paused download. Hot path: download is still in pool memory (same session) - extract config directly. Cold path: download was paused in a prior session, only stored in DB.
(id string)
| 88 | // Hot path: download is still in pool memory (same session) - extract config directly. |
| 89 | // Cold path: download was paused in a prior session, only stored in DB. |
| 90 | func (mgr *LifecycleManager) Resume(id string) error { |
| 91 | hooks := mgr.getEngineHooks() |
| 92 | |
| 93 | // Guard: still transitioning to paused |
| 94 | if hooks.GetStatus != nil { |
| 95 | if st := hooks.GetStatus(id); st != nil && st.Status == "pausing" { |
| 96 | return types.ErrPausing |
| 97 | } |
| 98 | } |
| 99 | |
| 100 | // Hot path: pool still holds the paused download in memory. |
| 101 | if hooks.ExtractPausedConfig != nil { |
| 102 | if cfg := hooks.ExtractPausedConfig(id); cfg != nil { |
| 103 | hydrateConfigFromDisk(cfg) |
| 104 | cfg.IsResume = true |
| 105 | if hooks.AddConfig != nil { |
| 106 | hooks.AddConfig(*cfg) |
| 107 | } |
| 108 | if hooks.PublishEvent != nil { |
| 109 | _ = hooks.PublishEvent(events.DownloadResumedMsg{ |
| 110 | DownloadID: id, |
| 111 | Filename: cfg.Filename, |
| 112 | }) |
| 113 | } |
| 114 | return nil |
| 115 | } |
| 116 | } |
| 117 | |
| 118 | // Cold path: download from a prior session (only in DB). |
| 119 | entry, err := state.GetDownload(id) |
| 120 | if err != nil || entry == nil { |
| 121 | return types.ErrNotFound |
| 122 | } |
| 123 | |
| 124 | if entry.Status == "completed" { |
| 125 | return types.ErrCompleted |
| 126 | } |
| 127 | |
| 128 | settings := mgr.GetSettings() |
| 129 | |
| 130 | outputPath := config.Resolve[string](settings.General.DefaultDownloadDir) |
| 131 | if outputPath == "" { |
| 132 | outputPath = "." |
| 133 | } |
| 134 | |
| 135 | savedState, stateErr := state.LoadState(entry.URL, entry.DestPath) |
| 136 | if stateErr != nil { |
| 137 | savedState = nil |
| 138 | } |
| 139 | |
| 140 | cfg := buildResumeConfig(id, outputPath, entry, savedState, settings) |
| 141 | |
| 142 | if hooks.AddConfig != nil { |
| 143 | hooks.AddConfig(cfg) |
| 144 | } |
| 145 | if hooks.PublishEvent != nil { |
| 146 | _ = hooks.PublishEvent(events.DownloadResumedMsg{ |
| 147 | DownloadID: id, |
nothing calls this directly
no test coverage detected