fix(downloader): persist completed aria2 seeds

This commit is contained in:
saltbo
2026-06-05 23:12:54 -04:00
parent 09a1f257b0
commit e02531308e
2 changed files with 36 additions and 8 deletions
+17 -8
View File
@@ -62,10 +62,24 @@ func (a Aria2) Start(ctx context.Context) (*exec.Cmd, error) {
if err != nil {
return nil, err
}
args, err := a.startArgs(rpcURL.port)
if err != nil {
return nil, err
}
cmd := exec.Command(path, args...)
configureEngineProcess(cmd)
if err := cmd.Start(); err != nil {
return nil, err
}
go func() { _ = cmd.Wait() }()
return cmd, nil
}
func (a Aria2) startArgs(rpcPort string) ([]string, error) {
args := []string{
"--enable-rpc=true",
"--rpc-listen-all=false",
"--rpc-listen-port=" + rpcURL.port,
"--rpc-listen-port=" + rpcPort,
"--dir=" + a.Dir,
"--continue=true",
"--allow-overwrite=true",
@@ -85,18 +99,13 @@ func (a Aria2) Start(ctx context.Context) (*exec.Cmd, error) {
"--input-file="+sessionPath,
"--save-session="+sessionPath,
"--save-session-interval=30",
"--force-save=true",
)
}
if a.Secret != "" {
args = append(args, "--rpc-secret="+a.Secret)
}
cmd := exec.Command(path, args...)
configureEngineProcess(cmd)
if err := cmd.Start(); err != nil {
return nil, err
}
go func() { _ = cmd.Wait() }()
return cmd, nil
return args, nil
}
func (a Aria2) Check(ctx context.Context) error {
+19
View File
@@ -74,6 +74,25 @@ func TestHTTPRejectsMagnet(t *testing.T) {
}
}
func TestAria2StartArgsForceSaveCompletedSeeds(t *testing.T) {
stateDir := t.TempDir()
args, err := (Aria2{Dir: t.TempDir(), StateDir: stateDir}).startArgs("6800")
if err != nil {
t.Fatal(err)
}
joined := strings.Join(args, "\n")
for _, expected := range []string{
"--input-file=" + filepath.Join(stateDir, "aria2.session"),
"--save-session=" + filepath.Join(stateDir, "aria2.session"),
"--save-session-interval=30",
"--force-save=true",
} {
if !strings.Contains(joined, expected) {
t.Fatalf("expected aria2 args to contain %q, got %v", expected, args)
}
}
}
func TestHTTPDownloadResumesExistingFile(t *testing.T) {
var rangeHeader string
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {