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"
|
"github.com/pkg/errors"
|
||||||
log "github.com/sirupsen/logrus"
|
log "github.com/sirupsen/logrus"
|
||||||
"github.com/xhofe/tache"
|
"github.com/xhofe/tache"
|
||||||
"sync"
|
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -20,7 +19,6 @@ type DownloadTask struct {
|
||||||
Status string `json:"status"`
|
Status string `json:"status"`
|
||||||
Signal chan int `json:"-"`
|
Signal chan int `json:"-"`
|
||||||
GID string `json:"-"`
|
GID string `json:"-"`
|
||||||
finish chan struct{}
|
|
||||||
tool Tool
|
tool Tool
|
||||||
callStatusRetried int
|
callStatusRetried int
|
||||||
}
|
}
|
||||||
|
@ -33,10 +31,8 @@ func (t *DownloadTask) Run() error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
t.Signal = make(chan int)
|
t.Signal = make(chan int)
|
||||||
t.finish = make(chan struct{})
|
|
||||||
defer func() {
|
defer func() {
|
||||||
t.Signal = nil
|
t.Signal = nil
|
||||||
t.finish = nil
|
|
||||||
}()
|
}()
|
||||||
gid, err := t.tool.AddURL(&AddUrlArgs{
|
gid, err := t.tool.AddURL(&AddUrlArgs{
|
||||||
Url: t.Url,
|
Url: t.Url,
|
||||||
|
@ -72,9 +68,7 @@ outer:
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
t.Status = "aria2 download completed, maybe transferring"
|
t.Status = "offline download completed, maybe transferring"
|
||||||
t.finish <- struct{}{}
|
|
||||||
t.Status = "offline download completed"
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -123,18 +117,11 @@ func (t *DownloadTask) Complete() error {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// upload files
|
// upload files
|
||||||
var wg sync.WaitGroup
|
|
||||||
wg.Add(len(files))
|
|
||||||
go func() {
|
|
||||||
wg.Wait()
|
|
||||||
t.finish <- struct{}{}
|
|
||||||
}()
|
|
||||||
for i, _ := range files {
|
for i, _ := range files {
|
||||||
file := files[i]
|
file := files[i]
|
||||||
TransferTaskManager.Add(&TransferTask{
|
TransferTaskManager.Add(&TransferTask{
|
||||||
file: file,
|
file: file,
|
||||||
dstDirPath: t.DstDirPath,
|
dstDirPath: t.DstDirPath,
|
||||||
wg: &wg,
|
|
||||||
tempDir: t.TempDir,
|
tempDir: t.TempDir,
|
||||||
deletePolicy: t.DeletePolicy,
|
deletePolicy: t.DeletePolicy,
|
||||||
})
|
})
|
||||||
|
|
|
@ -11,20 +11,17 @@ import (
|
||||||
"github.com/xhofe/tache"
|
"github.com/xhofe/tache"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"sync"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type TransferTask struct {
|
type TransferTask struct {
|
||||||
tache.Base
|
tache.Base
|
||||||
file File
|
file File
|
||||||
dstDirPath string
|
dstDirPath string
|
||||||
wg *sync.WaitGroup
|
|
||||||
tempDir string
|
tempDir string
|
||||||
deletePolicy DeletePolicy
|
deletePolicy DeletePolicy
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *TransferTask) Run() error {
|
func (t *TransferTask) Run() error {
|
||||||
defer t.wg.Done()
|
|
||||||
// check dstDir again
|
// check dstDir again
|
||||||
storage, dstDirActualPath, err := op.GetStorageAndActualPath(t.dstDirPath)
|
storage, dstDirActualPath, err := op.GetStorageAndActualPath(t.dstDirPath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
Loading…
Reference in New Issue