summaryrefslogtreecommitdiff
path: root/rhimport/fetcher.go
diff options
context:
space:
mode:
authorChristian Pointner <equinox@helsinki.at>2016-07-15 13:10:29 (GMT)
committerChristian Pointner <equinox@helsinki.at>2016-07-15 13:14:03 (GMT)
commitb7456c5beafeeba5357db25eac195b93313647fe (patch)
tree9a8b32014d067abb7d8978980f3d9984798acc6d /rhimport/fetcher.go
parent032ef2074e691935a017d95fa5fd134317ef344f (diff)
simplified progress reports
Diffstat (limited to 'rhimport/fetcher.go')
-rw-r--r--rhimport/fetcher.go56
1 files changed, 10 insertions, 46 deletions
diff --git a/rhimport/fetcher.go b/rhimport/fetcher.go
index c9bfc2f..b4380fa 100644
--- a/rhimport/fetcher.go
+++ b/rhimport/fetcher.go
@@ -103,12 +103,7 @@ func curlWriteCallback(ptr []byte, userdata interface{}) bool {
data.writeError = fmt.Errorf("file exceeds maximum file size")
return false
}
-
- if data.ctx.ProgressCallBack != nil {
- if keep := data.ctx.ProgressCallBack(1, "downloading", float64(data.written), data.totalSize, 0, 0, data.ctx.ProgressCallBackData); !keep {
- data.ctx.ProgressCallBack = nil
- }
- }
+ data.ctx.reportProgress(1, "downloading", float64(data.written), data.totalSize)
return true
}
@@ -447,12 +442,7 @@ func fetchFileDirConvert(ctx *Context, res *Result, origSrc *os.File, sizeTotal
}
written += uint64(w)
- if ctx.ProgressCallBack != nil {
- if keep := ctx.ProgressCallBack(1, "fetching", float64(written), float64(sizeTotal), 0, 0, ctx.ProgressCallBackData); !keep {
- ctx.ProgressCallBack = nil
- }
- }
-
+ ctx.reportProgress(1, "fetching", float64(written), float64(sizeTotal))
if ctx.Cancel != nil && len(ctx.Cancel) > 0 {
res.ResponseCode = http.StatusNoContent
res.ErrorString = "canceled"
@@ -533,12 +523,7 @@ func fetchFileDir(ctx *Context, res *Result, uri *url.URL, dir string, convert b
return nil
}
- if ctx.ProgressCallBack != nil {
- if keep := ctx.ProgressCallBack(1, "fetching", 0.0, float64(size), 0, 0, ctx.ProgressCallBackData); !keep {
- ctx.ProgressCallBack = nil
- }
- }
-
+ ctx.reportProgress(1, "fetching", 0.0, float64(size))
if convert {
if err = fetchFileDirConvert(ctx, res, src, size); err != nil {
return
@@ -549,12 +534,7 @@ func fetchFileDir(ctx *Context, res *Result, uri *url.URL, dir string, convert b
ctx.DeleteSourceDir = false
}
}
-
- if ctx.ProgressCallBack != nil {
- if keep := ctx.ProgressCallBack(1, "fetching", float64(size), float64(size), 0, 0, ctx.ProgressCallBackData); !keep {
- ctx.ProgressCallBack = nil
- }
- }
+ ctx.reportProgress(1, "fetching", float64(size), float64(size))
return
}
@@ -575,18 +555,12 @@ func fetchFileFake(ctx *Context, res *Result, uri *url.URL) error {
res.ErrorString = "canceled"
return nil
}
- if ctx.ProgressCallBack != nil {
- if keep := ctx.ProgressCallBack(1, "faking", float64(i), float64(duration), 0, 0, ctx.ProgressCallBackData); !keep {
- ctx.ProgressCallBack = nil
- }
- }
+
+ ctx.reportProgress(1, "faking", float64(i), float64(duration))
time.Sleep(100 * time.Millisecond)
}
- if ctx.ProgressCallBack != nil {
- if keep := ctx.ProgressCallBack(1, "faking", float64(duration), float64(duration), 0, 0, ctx.ProgressCallBackData); !keep {
- ctx.ProgressCallBack = nil
- }
- }
+ ctx.reportProgress(1, "faking", float64(duration), float64(duration))
+
ctx.SourceFile = "/nonexistend/fake.mp3"
ctx.OrigFilename = ctx.SourceFile
if ctx.SourceFilePolicy == Auto {
@@ -626,12 +600,7 @@ func writeAttachmentFile(ctx *Context, res *Result, sizeTotal uint64, conv Fetch
}
written += uint64(w)
- if ctx.ProgressCallBack != nil {
- if keep := ctx.ProgressCallBack(1, "receiving", float64(written), float64(sizeTotal), 0, 0, ctx.ProgressCallBackData); !keep {
- ctx.ProgressCallBack = nil
- }
- }
-
+ ctx.reportProgress(1, "receiving", float64(written), float64(sizeTotal))
if uint64(written) >= sizeTotal {
return nil
}
@@ -672,12 +641,7 @@ func fetchFileAttachment(ctx *Context, res *Result, uri *url.URL) error {
return err
}
- if ctx.ProgressCallBack != nil {
- if keep := ctx.ProgressCallBack(1, "receiving", 0.0, float64(sizeTotal), 0, 0, ctx.ProgressCallBackData); !keep {
- ctx.ProgressCallBack = nil
- }
- }
-
+ ctx.reportProgress(1, "receiving", 0.0, float64(sizeTotal))
err = writeAttachmentFile(ctx, res, sizeTotal, conv)
conv.Close()
if res.ResponseCode == http.StatusNoContent {