dkforest

A forum and chat platform (onion)
git clone https://git.dasho.dev/n0tr1v/dkforest.git
Log | Files | Refs | LICENSE

commit d9270063dcf9ad5f14c2ec5ded84b7296e58ec52
parent c10d229fa083bc96b7f14e27dbea6718d82e8c83
Author: n0tr1v <n0tr1v@protonmail.com>
Date:   Fri,  3 Feb 2023 17:25:53 -0800

client must check http status

Diffstat:
Mcmd/dkfdownload/main.go | 11+++++++----
1 file changed, 7 insertions(+), 4 deletions(-)

diff --git a/cmd/dkfdownload/main.go b/cmd/dkfdownload/main.go @@ -196,11 +196,11 @@ func work(i int, wg *sync.WaitGroup, baseUrl, filedropUUID string, chunksCh chan client := doGetClient(isLocal, httpTimeout) for chunkNum := range chunksCh { start := time.Now() - logrus.Infof("Thread #%03d | chunk #%03d", i, chunkNum) + logrus.Infof("thread #%03d | chunk #%03d", i, chunkNum) hasToSucceed(func() error { partFileName := fmt.Sprintf("part_%d", chunkNum) if _, err := os.Stat(filepath.Join(filedropUUID, partFileName)); err == nil { - logrus.Infof("Thread #%03d | chunk #%03d; skip", i, chunkNum) + logrus.Infof("thread #%03d | chunk #%03d; skip", i, chunkNum) return nil } @@ -213,12 +213,15 @@ func work(i int, wg *sync.WaitGroup, baseUrl, filedropUUID string, chunksCh chan resp, err := client.Do(req) if err != nil { if os.IsTimeout(err) { - logrus.Infof("Thread #%03d gets a new client\n", i) + logrus.Infof("thread #%03d gets a new client\n", i) client = doGetClient(isLocal, httpTimeout) } return err } defer resp.Body.Close() + if resp.StatusCode != http.StatusOK { + return fmt.Errorf("thread #%03d | chunk #%03d | invalid status code %s", i, chunkNum, resp.Status) + } f, err := os.OpenFile(filepath.Join(filedropUUID, "part_"+strconv.FormatInt(chunkNum, 10)), os.O_TRUNC|os.O_CREATE|os.O_WRONLY, 0644) if err != nil { return err @@ -228,7 +231,7 @@ func work(i int, wg *sync.WaitGroup, baseUrl, filedropUUID string, chunksCh chan return nil }) newChunksCompleted := atomic.AddInt64(&chunksCompleted, 1) - logrus.Infof("Thread #%03d | chunk #%03d | completed in %s (%d/%d)\n", i, chunkNum, ShortDur(time.Since(start)), newChunksCompleted, nbChunks) + logrus.Infof("thread #%03d | chunk #%03d | completed in %s (%d/%d)\n", i, chunkNum, ShortDur(time.Since(start)), newChunksCompleted, nbChunks) } }