From c921d8ab9482131e51141e0becdae6da609d5468 Mon Sep 17 00:00:00 2001 From: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com> Date: Wed, 21 Oct 2026 14:17:22 -0700 Subject: [PATCH] upload: stream -dir results as each file completes Batching the output until every upload finished meant an interrupted run lost the file ids of completed uploads. A per-index ready channel lets a printer emit each result in walk order as soon as it lands. Generated with [Devin](https://devin.ai) Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com> --- weed/command/upload.go | 34 ++++++++++++++++++++++------------ 1 file changed, 22 insertions(+), 12 deletions(-) diff --git a/weed/command/upload.go b/weed/command/upload.go index e9b2c6784b..b68839a8fa 100644 --- a/weed/command/upload.go +++ b/weed/command/upload.go @@ -123,12 +123,33 @@ func runUpload(cmd *Command, args []string) bool { MaxMB: *upload.maxMB, } results := make([][]operation.SubmitResult, len(filePaths)) + ready := make([]chan struct{}, len(filePaths)) + for index := range ready { + ready[index] = make(chan struct{}) + } + printDone := make(chan bool, 1) + go func() { + failed := false + for index := range ready { + <-ready[index] + bytes, _ := json.Marshal(results[index]) + fmt.Println(string(bytes)) + for _, r := range results[index] { + if r.Error != "" { + failed = true + } + } + } + printDone <- failed + }() + sem := make(chan struct{}, concurrency) var wg sync.WaitGroup for index, filePath := range filePaths { sem <- struct{}{} wg.Add(1) go func(index int, filePath string) { + defer close(ready[index]) defer wg.Done() defer func() { <-sem }() parts, e := operation.NewFileParts([]string{filePath}) @@ -148,18 +169,7 @@ func runUpload(cmd *Command, args []string) bool { }(index, filePath) } wg.Wait() - - failed := false - for _, fileResults := range results { - bytes, _ := json.Marshal(fileResults) - fmt.Println(string(bytes)) - for _, r := range fileResults { - if r.Error != "" { - failed = true - } - } - } - if failed { + if <-printDone { return false } } else {