fix: tasks block when paused while not ready (#648)

This commit is contained in:
Levi authored and GitHub committed 2024-08-14 21:22:23 +08:00
1 parent e3ccecbd9c
commit d9f04ae928
1 file changed
+11 -13
+11 -13
View File
@@ -362,18 +362,10 @@ func (d *Downloader) Pause(id string) (err error) {
return ErrTaskNotFound
}
func() {
task.lock.Lock()
defer task.lock.Unlock()
if task.Status == base.DownloadStatusPause {
return
}
if err = d.doPause(task); err != nil {
return
}
d.notifyRunning()
}()
if err = d.doPause(task); err != nil {
return
}
d.notifyRunning()
return
}
@@ -592,11 +584,11 @@ func (d *Downloader) Close() error {
closeArr := []func() error{
d.PauseAll,
d.storage.Close,
}
for _, fm := range d.cfg.FetchManagers {
closeArr = append(closeArr, fm.Close)
}
closeArr = append(closeArr, d.storage.Close)
// Make sure all resources are released, if had error, return the last error
var lastErr error
for i, close := range closeArr {
@@ -732,6 +724,12 @@ func (d *Downloader) watch(task *Task) {
d.doOnError(task, err)
return
}
// When delete a not resolved task, need check if the task resource is nil
if task.Meta.Res == nil {
return
}
task.Progress.Used = task.timer.Used()
if task.Meta.Res.Size == 0 {
task.Meta.Res.Size = task.fetcher.Progress().TotalDownloaded()