summaryrefslogtreecommitdiff
path: root/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)
commit4b0cb427306cb5bab60e6abdd16dbd7bd8df2a85 (patch)
tree9e40815ba3b45ae01af7665a4143583c1a6cd7d5 /fetcher.go
parentdb0d524595106b1e907df04baa3da8eb17527f6d (diff)
added support for progress callbacks
Diffstat (limited to 'fetcher.go')
-rw-r--r--fetcher.go11
1 files changed, 6 insertions, 5 deletions
diff --git a/fetcher.go b/fetcher.go
index b4e2f0c..03cf3da 100644
--- a/fetcher.go
+++ b/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