diff options
author | Christian Pointner <equinox@helsinki.at> | 2015-12-21 07:46:24 (GMT) |
---|---|---|
committer | Christian Pointner <equinox@helsinki.at> | 2015-12-21 07:46:24 (GMT) |
commit | 0c5eb4132e9c5af37cf073c957e21529487a78f4 (patch) | |
tree | 7d93d380393030fc0244229dafda8b5bbc6d4a50 | |
parent | 7ba1348b1a9cbfc53f902ea43282d6207fc40313 (diff) |
added a cancel channel to fetcher/importer (untestedgit show)
-rw-r--r-- | fetcher.go | 4 | ||||
-rw-r--r-- | importer.go | 6 |
2 files changed, 10 insertions, 0 deletions
@@ -113,6 +113,10 @@ func FetchFileCurl(ctx *ImportContext, res *FetchResult, uri *url.URL) (err erro easy.Setopt(curl.OPT_NOPROGRESS, false) easy.Setopt(curl.OPT_PROGRESSFUNCTION, func(dltotal, dlnow, ultotal, ulnow float64, userdata interface{}) bool { + if ctx.Cancel != nil && len(ctx.Cancel) > 0 { + return false + } + ctx := userdata.(*ImportContext) if ctx.ProgressCallBack != nil { ctx.ProgressCallBack(1, "downloading", dlnow/dltotal, ctx.ProgressCallBackData) diff --git a/importer.go b/importer.go index 292d376..9be1257 100644 --- a/importer.go +++ b/importer.go @@ -63,6 +63,7 @@ type ImportContext struct { DeleteSourceDir bool ProgressCallBack ImportProgressCB ProgressCallBackData interface{} + Cancel <-chan bool } func NewImportContext(conf *Config, rddb *RdDbChan, user string) *ImportContext { @@ -86,6 +87,7 @@ func NewImportContext(conf *Config, rddb *RdDbChan, user string) *ImportContext ctx.DeleteSourceFile = false ctx.DeleteSourceDir = false ctx.ProgressCallBack = nil + ctx.Cancel = nil return ctx } @@ -482,6 +484,10 @@ func import_audio(ctx *ImportContext, res *ImportResult) (err error) { easy.Setopt(curl.OPT_NOPROGRESS, false) easy.Setopt(curl.OPT_PROGRESSFUNCTION, func(dltotal, dlnow, ultotal, ulnow float64, userdata interface{}) bool { + if ctx.Cancel != nil && len(ctx.Cancel) > 0 { + return false + } + ctx := userdata.(*ImportContext) if ctx.ProgressCallBack != nil { ctx.ProgressCallBack(2, "importing", ulnow/ultotal, ctx.ProgressCallBackData) |