diff --git a/pkg/download/downloader.go b/pkg/download/downloader.go index 15a0e6c4e..382a5b7cd 100644 --- a/pkg/download/downloader.go +++ b/pkg/download/downloader.go @@ -1221,7 +1221,7 @@ func (d *Downloader) statusMut(task *Task, fn func() (bool, error)) (bool, error } func (d *Downloader) doStart(task *Task) (err error) { - var isCreate bool + var needCreate bool isReturn, err := d.statusMut(task, func() (isReturn bool, err error) { if task.Status == base.DownloadStatusRunning || task.Status == base.DownloadStatusDone { isReturn = true @@ -1233,7 +1233,7 @@ func (d *Downloader) doStart(task *Task) (err error) { d.Logger.Error().Stack().Err(err).Msgf("restore fetcher failed, task id: %s", task.ID) return } - isCreate = task.Status == base.DownloadStatusReady + needCreate = !task.IsCreated task.updateStatus(base.DownloadStatusRunning) return @@ -1259,7 +1259,7 @@ func (d *Downloader) doStart(task *Task) (err error) { task.Meta.Res = task.fetcher.Meta().Res } - if isCreate { + if needCreate { if task.fetcherManager.AutoRename() { d.checkDuplicateLock.Lock() defer d.checkDuplicateLock.Unlock() @@ -1283,10 +1283,9 @@ func (d *Downloader) doStart(task *Task) (err error) { task.Meta.Opts.Name = newName } } - + task.IsCreated = true task.Meta.Res.CalcSize(task.Meta.Opts.SelectFiles) } - task.Progress.Speed = 0 task.timer.Start() if err := task.fetcher.Start(); err != nil { diff --git a/pkg/download/model.go b/pkg/download/model.go index 0d3ce16e3..bbb57adeb 100644 --- a/pkg/download/model.go +++ b/pkg/download/model.go @@ -27,6 +27,7 @@ type Task struct { Status base.Status `json:"status"` Uploading bool `json:"uploading"` Progress *Progress `json:"progress"` + IsCreated bool `json:"isCreated"` CreatedAt time.Time `json:"createdAt"` UpdatedAt time.Time `json:"updatedAt"` @@ -49,6 +50,7 @@ func NewTask() *Task { Status: base.DownloadStatusReady, CreatedAt: time.Now(), UpdatedAt: time.Now(), + IsCreated: false, } }