Skip to content

Commit

Permalink
fix(offline_download): don't wait for transfer task (close #5595)
Browse files Browse the repository at this point in the history
  • Loading branch information
xhofe committed Dec 3, 2023
1 parent e4a6b75 commit 8bdfc7a
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 17 deletions.
15 changes: 1 addition & 14 deletions internal/offline_download/tool/download.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"github.com/pkg/errors"
log "github.com/sirupsen/logrus"
"github.com/xhofe/tache"
"sync"
"time"
)

Expand All @@ -20,7 +19,6 @@ type DownloadTask struct {
Status string `json:"status"`
Signal chan int `json:"-"`
GID string `json:"-"`
finish chan struct{}
tool Tool
callStatusRetried int
}
Expand All @@ -33,10 +31,8 @@ func (t *DownloadTask) Run() error {
return err
}
t.Signal = make(chan int)
t.finish = make(chan struct{})
defer func() {
t.Signal = nil
t.finish = nil
}()
gid, err := t.tool.AddURL(&AddUrlArgs{
Url: t.Url,
Expand Down Expand Up @@ -72,9 +68,7 @@ outer:
if err != nil {
return err
}
t.Status = "aria2 download completed, maybe transferring"
t.finish <- struct{}{}
t.Status = "offline download completed"
t.Status = "offline download completed, maybe transferring"
return nil
}

Expand Down Expand Up @@ -123,18 +117,11 @@ func (t *DownloadTask) Complete() error {
}
}
// upload files
var wg sync.WaitGroup
wg.Add(len(files))
go func() {
wg.Wait()
t.finish <- struct{}{}
}()
for i, _ := range files {
file := files[i]
TransferTaskManager.Add(&TransferTask{
file: file,
dstDirPath: t.DstDirPath,
wg: &wg,
tempDir: t.TempDir,
deletePolicy: t.DeletePolicy,
})
Expand Down
3 changes: 0 additions & 3 deletions internal/offline_download/tool/transfer.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,17 @@ import (
"github.com/xhofe/tache"
"os"
"path/filepath"
"sync"
)

type TransferTask struct {
tache.Base
file File
dstDirPath string
wg *sync.WaitGroup
tempDir string
deletePolicy DeletePolicy
}

func (t *TransferTask) Run() error {
defer t.wg.Done()
// check dstDir again
storage, dstDirActualPath, err := op.GetStorageAndActualPath(t.dstDirPath)
if err != nil {
Expand Down

0 comments on commit 8bdfc7a

Please sign in to comment.