From 87e91b6487644ab9de12d0cb031b90cc599062e1 Mon Sep 17 00:00:00 2001 From: Christian Pointner Date: Mon, 21 Dec 2015 08:46:24 +0100 Subject: added a cancel channel to fetcher/importer (untestedgit show) diff --git a/src/helsinki.at/rhimport/fetcher.go b/src/helsinki.at/rhimport/fetcher.go index a8ac22c..bff62bc 100644 --- a/src/helsinki.at/rhimport/fetcher.go +++ b/src/helsinki.at/rhimport/fetcher.go @@ -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/src/helsinki.at/rhimport/importer.go b/src/helsinki.at/rhimport/importer.go index 292d376..9be1257 100644 --- a/src/helsinki.at/rhimport/importer.go +++ b/src/helsinki.at/rhimport/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) -- cgit v0.10.2