summaryrefslogtreecommitdiff
path: root/src/helsinki.at/rhimport/fetcher.go
diff options
context:
space:
mode:
authorChristian Pointner <equinox@helsinki.at>2015-12-10 16:30:40 (GMT)
committerChristian Pointner <equinox@helsinki.at>2015-12-10 16:30:40 (GMT)
commitfa921c13ae7d2fb82ab5801244b6b1e9ef7db371 (patch)
tree9e0abeebd534f179fab16042cd8f5e867bbcb66d /src/helsinki.at/rhimport/fetcher.go
parentce68e63d07aa6efa926601298a472818ae6a37a6 (diff)
added support for progress callbacks
Diffstat (limited to 'src/helsinki.at/rhimport/fetcher.go')
-rw-r--r--src/helsinki.at/rhimport/fetcher.go11
1 files changed, 6 insertions, 5 deletions
diff --git a/src/helsinki.at/rhimport/fetcher.go b/src/helsinki.at/rhimport/fetcher.go
index b4e2f0c..03cf3da 100644
--- a/src/helsinki.at/rhimport/fetcher.go
+++ b/src/helsinki.at/rhimport/fetcher.go
@@ -33,7 +33,6 @@ import (
"os"
"path"
"strings"
- "time"
)
type CurlCBData struct {
@@ -107,12 +106,11 @@ func FetchFileCurl(ctx *ImportContext, uri *url.URL) (err error) {
easy.Setopt(curl.OPT_WRITEDATA, cbdata)
easy.Setopt(curl.OPT_NOPROGRESS, false)
- started := int64(0)
easy.Setopt(curl.OPT_PROGRESSFUNCTION, func(dltotal, dlnow, ultotal, ulnow float64, userdata interface{}) bool {
- if started == 0 {
- started = time.Now().Unix()
+ ctx := userdata.(*ImportContext)
+ if ctx.ProgressCallBack != nil {
+ ctx.ProgressCallBack(1, "downloading", dlnow/dltotal, ctx.ProgressCallBackData)
}
- fmt.Printf("Downloaded: %3.2f%%, Speed: %.1fKiB/s \r", dlnow/dltotal*100, dlnow/1000/float64((time.Now().Unix()-started)))
return true
})
easy.Setopt(curl.OPT_PROGRESSDATA, ctx)
@@ -131,6 +129,9 @@ func FetchFileCurl(ctx *ImportContext, uri *url.URL) (err error) {
func FetchFileLocal(ctx *ImportContext, uri *url.URL) (err error) {
rhl.Printf("Local fetcher called for '%s'", ctx.SourceUri)
+ if ctx.ProgressCallBack != nil {
+ ctx.ProgressCallBack(1, "fetching", 1.0, ctx.ProgressCallBackData)
+ }
ctx.SourceFile = uri.Path
ctx.DeleteSourceFile = false
ctx.DeleteSourceDir = false