mirror of
https://github.com/GopeedLab/gopeed.git
synced 2026-11-09 10:00:27 +00:00
fix: add IsCreated flag to reliably track task creation state (#1314)
This commit is contained in:
1 parent
09f7c88ed3
commit
3d20e818e5
2 files changed
+6
-5
No files matched your search
@@ -1221,7 +1221,7 @@ func (d *Downloader) statusMut(task *Task, fn func() (bool, error)) (bool, error
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (d *Downloader) doStart(task *Task) (err 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) {
|
isReturn, err := d.statusMut(task, func() (isReturn bool, err error) {
|
||||||
if task.Status == base.DownloadStatusRunning || task.Status == base.DownloadStatusDone {
|
if task.Status == base.DownloadStatusRunning || task.Status == base.DownloadStatusDone {
|
||||||
isReturn = true
|
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)
|
d.Logger.Error().Stack().Err(err).Msgf("restore fetcher failed, task id: %s", task.ID)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
isCreate = task.Status == base.DownloadStatusReady
|
needCreate = !task.IsCreated
|
||||||
task.updateStatus(base.DownloadStatusRunning)
|
task.updateStatus(base.DownloadStatusRunning)
|
||||||
|
|
||||||
return
|
return
|
||||||
@@ -1259,7 +1259,7 @@ func (d *Downloader) doStart(task *Task) (err error) {
|
|||||||
task.Meta.Res = task.fetcher.Meta().Res
|
task.Meta.Res = task.fetcher.Meta().Res
|
||||||
}
|
}
|
||||||
|
|
||||||
if isCreate {
|
if needCreate {
|
||||||
if task.fetcherManager.AutoRename() {
|
if task.fetcherManager.AutoRename() {
|
||||||
d.checkDuplicateLock.Lock()
|
d.checkDuplicateLock.Lock()
|
||||||
defer d.checkDuplicateLock.Unlock()
|
defer d.checkDuplicateLock.Unlock()
|
||||||
@@ -1283,10 +1283,9 @@ func (d *Downloader) doStart(task *Task) (err error) {
|
|||||||
task.Meta.Opts.Name = newName
|
task.Meta.Opts.Name = newName
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
task.IsCreated = true
|
||||||
task.Meta.Res.CalcSize(task.Meta.Opts.SelectFiles)
|
task.Meta.Res.CalcSize(task.Meta.Opts.SelectFiles)
|
||||||
}
|
}
|
||||||
|
|
||||||
task.Progress.Speed = 0
|
task.Progress.Speed = 0
|
||||||
task.timer.Start()
|
task.timer.Start()
|
||||||
if err := task.fetcher.Start(); err != nil {
|
if err := task.fetcher.Start(); err != nil {
|
||||||
|
|||||||
@@ -27,6 +27,7 @@ type Task struct {
|
|||||||
Status base.Status `json:"status"`
|
Status base.Status `json:"status"`
|
||||||
Uploading bool `json:"uploading"`
|
Uploading bool `json:"uploading"`
|
||||||
Progress *Progress `json:"progress"`
|
Progress *Progress `json:"progress"`
|
||||||
|
IsCreated bool `json:"isCreated"`
|
||||||
CreatedAt time.Time `json:"createdAt"`
|
CreatedAt time.Time `json:"createdAt"`
|
||||||
UpdatedAt time.Time `json:"updatedAt"`
|
UpdatedAt time.Time `json:"updatedAt"`
|
||||||
|
|
||||||
@@ -49,6 +50,7 @@ func NewTask() *Task {
|
|||||||
Status: base.DownloadStatusReady,
|
Status: base.DownloadStatusReady,
|
||||||
CreatedAt: time.Now(),
|
CreatedAt: time.Now(),
|
||||||
UpdatedAt: time.Now(),
|
UpdatedAt: time.Now(),
|
||||||
|
IsCreated: false,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user