Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 4 additions & 5 deletions pkg/download/downloader.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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()
Expand All @@ -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 {
Expand Down
2 changes: 2 additions & 0 deletions pkg/download/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`

Expand All @@ -49,6 +50,7 @@ func NewTask() *Task {
Status: base.DownloadStatusReady,
CreatedAt: time.Now(),
UpdatedAt: time.Now(),
IsCreated: false,
}
}

Expand Down
Loading