fix: add IsCreated flag to reliably track task creation state (#1314)

This commit is contained in:
Wang YiJia
2026-03-18 18:35:39 +08:00
committed by GitHub
parent 09f7c88ed3
commit 3d20e818e5
2 changed files with 6 additions and 5 deletions
+4 -5
View File
@@ -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 {
+2
View File
@@ -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,
}
}