MCPcopy
hub / github.com/SurgeDM/Surge / buildResumeConfig

Function buildResumeConfig

internal/processing/pause_resume.go:313–388  ·  view source on GitHub ↗

buildResumeConfig constructs a DownloadConfig for a cold-path resume from saved state. When entry is non-nil it provides identity fields (URL, filename, destPath); savedState takes precedence for progress, elapsed time, and mirror topology. If savedState is nil, SupportsRange is false and the downlo

(id, outputPath string, entry *types.DownloadEntry, savedState *types.DownloadState, settings *config.Settings)

Source from the content-addressed store, hash-verified

311// takes precedence for progress, elapsed time, and mirror topology. If savedState is nil,
312// SupportsRange is false and the download restarts from the entry's Downloaded offset.
313func buildResumeConfig(id, outputPath string, entry *types.DownloadEntry, savedState *types.DownloadState, settings *config.Settings) types.DownloadConfig {
314 var destPath, url, filename string
315 var totalSize, downloaded int64
316 var rateLimit int64
317 var rateLimitSet bool
318
319 if entry != nil {
320 destPath = entry.DestPath
321 url = entry.URL
322 filename = entry.Filename
323 totalSize = entry.TotalSize
324 downloaded = entry.Downloaded
325 rateLimit = entry.RateLimit
326 rateLimitSet = entry.RateLimitSet
327 } else if savedState != nil {
328 destPath = savedState.DestPath
329 url = savedState.URL
330 filename = savedState.Filename
331 totalSize = savedState.TotalSize
332 downloaded = savedState.Downloaded
333 rateLimit = savedState.RateLimit
334 rateLimitSet = savedState.RateLimitSet
335 }
336
337 runtime := settings.ToRuntimeConfig()
338 if !rateLimitSet {
339 rateLimit = runtime.DefaultDownloadRateLimitBps
340 }
341
342 var mirrorURLs []string
343 var dmState *types.ProgressState
344
345 if savedState != nil {
346 dmState = types.NewProgressState(id, savedState.TotalSize)
347 dmState.Downloaded.Store(savedState.Downloaded)
348 dmState.VerifiedProgress.Store(savedState.Downloaded)
349 if savedState.Elapsed > 0 {
350 dmState.SetSavedElapsed(time.Duration(savedState.Elapsed))
351 }
352 if len(savedState.Mirrors) > 0 {
353 var mirrors []types.MirrorStatus
354 for _, u := range savedState.Mirrors {
355 mirrors = append(mirrors, types.MirrorStatus{URL: u, Active: true})
356 mirrorURLs = append(mirrorURLs, u)
357 }
358 dmState.SetMirrors(mirrors)
359 }
360 dmState.DestPath = destPath
361 dmState.SyncSessionStart()
362 } else {
363 dmState = types.NewProgressState(id, totalSize)
364 dmState.Downloaded.Store(downloaded)
365 dmState.VerifiedProgress.Store(downloaded)
366 dmState.DestPath = destPath
367 dmState.SyncSessionStart()
368 mirrorURLs = []string{url}
369 }
370 dmState.SetRateLimit(rateLimit, rateLimitSet)

Callers 2

ResumeMethod · 0.85
ResumeBatchMethod · 0.85

Calls 6

SetSavedElapsedMethod · 0.95
SetMirrorsMethod · 0.95
SyncSessionStartMethod · 0.95
SetRateLimitMethod · 0.95
NewProgressStateFunction · 0.92
ToRuntimeConfigMethod · 0.80

Tested by

no test coverage detected