mirror of https://github.com/Xhofe/alist
fix(offline_download): don't wait for transfer task (close #5595)
parent
e4a6b758dc
commit
8bdfc7ac8e
|
@ -6,7 +6,6 @@ import (
|
|||
"github.com/pkg/errors"
|
||||
log "github.com/sirupsen/logrus"
|
||||
"github.com/xhofe/tache"
|
||||
"sync"
|
||||
"time"
|
||||
)
|
||||
|
||||
|
@ -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
|
||||
}
|
||||
|
@ -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,
|
||||
|
@ -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
|
||||
}
|
||||
|
||||
|
@ -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,
|
||||
})
|
||||
|
|
|
@ -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 {
|
||||
|
|
Loading…
Reference in New Issue