commit 062c073b84705a9cf8449739355508fda1c30415
parent 6d89666746ff01cd3a7fd41505936bf925e13a74
Author: n0tr1v <n0tr1v@protonmail.com>
Date: Fri, 3 Feb 2023 19:13:50 -0800
cleanup
Diffstat:
1 file changed, 9 insertions(+), 5 deletions(-)
diff --git a/cmd/dkfdownload/main.go b/cmd/dkfdownload/main.go
@@ -123,7 +123,7 @@ func main() {
time.Sleep(25 * time.Millisecond)
}
wg.Wait()
- logrus.Infof("All chunks downloaded in %s", ShortDur(time.Since(start)))
+ logrus.Infof("all chunks downloaded in %s", ShortDur(time.Since(start)))
// Get sorted chunks file names
dirEntries, _ := os.ReadDir(filedropUUID)
@@ -176,19 +176,19 @@ func main() {
// Ensure downloaded file sha256 is correct
newFileSha256 := hex.EncodeToString(h.Sum(nil))
if newFileSha256 == fileSha256 {
- logrus.Infof("Downloaded sha256 is valid %s", newFileSha256)
+ logrus.Infof("downloaded sha256 is valid %s", newFileSha256)
} else {
- logrus.Fatalf("Downloaded sha256 doesn't match %s != %s", newFileSha256, fileSha256)
+ logrus.Fatalf("downloaded sha256 doesn't match %s != %s", newFileSha256, fileSha256)
}
// Cleanup
- logrus.Info("Cleanup chunks files")
+ logrus.Info("cleanup chunks files")
for _, chunkFileName := range fileNames {
_ = os.Remove(filepath.Join(filedropUUID, chunkFileName))
}
_ = os.Remove(filepath.Join(filedropUUID, "metadata"))
- logrus.Infof("All done in %s", ShortDur(time.Since(start)))
+ logrus.Infof("all done in %s", ShortDur(time.Since(start)))
}
func work(i int, wg *sync.WaitGroup, baseUrl, filedropUUID string, chunksCh chan int64, isLocal bool, httpTimeout time.Duration, nbChunks int64) {
@@ -225,6 +225,10 @@ func work(i int, wg *sync.WaitGroup, baseUrl, filedropUUID string, chunksCh chan
}
defer f.Close()
if _, err = io.Copy(f, resp.Body); err != nil {
+ if os.IsTimeout(err) {
+ logrus.Infof("thread #%03d gets a new client\n", i)
+ client = doGetClient(isLocal, httpTimeout)
+ }
return err
}
return nil