Skip to content

Commit

Permalink
fix: aria2 download magnet link (close #1665)
Browse files Browse the repository at this point in the history
  • Loading branch information
xhofe committed Sep 18, 2022
1 parent b74b55f commit 6c89c6c
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
9 changes: 8 additions & 1 deletion internal/aria2/monitor.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,10 +76,15 @@ func (m *Monitor) Update() (bool, error) {
}
m.retried = 0
if len(info.FollowedBy) != 0 {
log.Debugf("followen by: %+v", info.FollowedBy)
gid := info.FollowedBy[0]
notify.Signals.Delete(m.tsk.ID)
oldId := m.tsk.ID
m.tsk.ID = gid
DownTaskManager.RawTasks().Delete(oldId)
DownTaskManager.RawTasks().Store(m.tsk.ID, m.tsk)
notify.Signals.Store(gid, m.c)
return false, nil
}
// update download status
total, err := strconv.ParseUint(info.TotalLength, 10, 64)
Expand Down Expand Up @@ -120,6 +125,7 @@ func (m *Monitor) Complete() error {
}
// get files
files, err := client.GetFiles(m.tsk.ID)
log.Debugf("files len: %d", len(files))
if err != nil {
return errors.Wrapf(err, "failed to get files of %s", m.tsk.ID)
}
Expand All @@ -134,7 +140,8 @@ func (m *Monitor) Complete() error {
log.Errorf("failed to remove aria2 temp dir: %+v", err.Error())
}
}()
for _, file := range files {
for i, _ := range files {
file := files[i]
TransferTaskManager.Submit(task.WithCancelCtx(&task.Task[uint64]{
Name: fmt.Sprintf("transfer %s to [%s](%s)", file.Path, storage.GetStorage().MountPath, dstDirActualPath),
Func: func(tsk *task.Task[uint64]) error {
Expand Down
4 changes: 4 additions & 0 deletions pkg/task/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,10 @@ func (tm *Manager[K]) ClearDone() {
tm.RemoveByStates(SUCCEEDED, CANCELED, ERRORED)
}

func (tm *Manager[K]) RawTasks() *generic_sync.MapOf[K, *Task[K]] {
return &tm.tasks
}

func NewTaskManager[K comparable](maxWorker int, updateID ...func(*K)) *Manager[K] {
tm := &Manager[K]{
tasks: generic_sync.MapOf[K, *Task[K]]{},
Expand Down

0 comments on commit 6c89c6c

Please sign in to comment.