diff options
Diffstat (limited to 'rhimport/fetcher.go')
-rw-r--r-- | rhimport/fetcher.go | 31 |
1 files changed, 15 insertions, 16 deletions
diff --git a/rhimport/fetcher.go b/rhimport/fetcher.go index 0b1c3b2..d923f24 100644 --- a/rhimport/fetcher.go +++ b/rhimport/fetcher.go @@ -112,7 +112,7 @@ func curlProgressCallback(dltotal, dlnow, ultotal, ulnow float64, userdata inter } if data.ctx.ProgressCallBack != nil { - if keep := data.ctx.ProgressCallBack(1, "downloading", dlnow/dltotal, data.ctx.ProgressCallBackData); !keep { + if keep := data.ctx.ProgressCallBack(1, "downloading", dlnow, dltotal, data.ctx.ProgressCallBackData); !keep { data.ctx.ProgressCallBack = nil } } @@ -293,11 +293,6 @@ func fetchFileTmp(ctx *Context, res *Result, uri *url.URL) (err error) { func fetchFileDir(ctx *Context, res *Result, uri *url.URL, dir string) (err error) { rhl.Printf("Dir fetcher called for '%s'", ctx.SourceUri) - if ctx.ProgressCallBack != nil { - if keep := ctx.ProgressCallBack(1, "fetching", 0.0, ctx.ProgressCallBackData); !keep { - ctx.ProgressCallBack = nil - } - } ctx.SourceFile = filepath.Join(dir, path.Clean("/"+uri.Path)) var src *os.File @@ -306,20 +301,29 @@ func fetchFileDir(ctx *Context, res *Result, uri *url.URL, dir string) (err erro res.ErrorString = fmt.Sprintf("local-file open(): %s", err) return nil } + size := float64(0) if info, err := src.Stat(); err != nil { res.ResponseCode = http.StatusBadRequest res.ErrorString = fmt.Sprintf("local-file stat(): %s", err) return nil } else { + size = float64(info.Size()) if info.IsDir() { res.ResponseCode = http.StatusBadRequest res.ErrorString = fmt.Sprintf("'%s' is a directory", ctx.SourceFile) return nil } } + if ctx.ProgressCallBack != nil { + if keep := ctx.ProgressCallBack(1, "fetching", 0.0, size, ctx.ProgressCallBackData); !keep { + ctx.ProgressCallBack = nil + } + } + src.Close() + if ctx.ProgressCallBack != nil { - if keep := ctx.ProgressCallBack(1, "fetching", 1.0, ctx.ProgressCallBackData); !keep { + if keep := ctx.ProgressCallBack(1, "fetching", size, size, ctx.ProgressCallBackData); !keep { ctx.ProgressCallBack = nil } } @@ -348,14 +352,14 @@ func fetchFileFake(ctx *Context, res *Result, uri *url.URL) error { return nil } if ctx.ProgressCallBack != nil { - if keep := ctx.ProgressCallBack(1, "faking", float64(i)/float64(duration), ctx.ProgressCallBackData); !keep { + if keep := ctx.ProgressCallBack(1, "faking", float64(i), float64(duration), ctx.ProgressCallBackData); !keep { ctx.ProgressCallBack = nil } } time.Sleep(100 * time.Millisecond) } if ctx.ProgressCallBack != nil { - if keep := ctx.ProgressCallBack(1, "faking", 1.0, ctx.ProgressCallBackData); !keep { + if keep := ctx.ProgressCallBack(1, "faking", float64(duration), float64(duration), ctx.ProgressCallBackData); !keep { ctx.ProgressCallBack = nil } } @@ -396,13 +400,8 @@ func writeAttachmentFile(ctx *Context, res *Result, sizeTotal uint64, src *os.Fi } written += w - p := float64(written) / float64(sizeTotal) - if p > 1.0 { - p = 1.0 - } - if ctx.ProgressCallBack != nil { - if keep := ctx.ProgressCallBack(1, "receiving", p, ctx.ProgressCallBackData); !keep { + if keep := ctx.ProgressCallBack(1, "receiving", float64(written), float64(sizeTotal), ctx.ProgressCallBackData); !keep { ctx.ProgressCallBack = nil } } @@ -443,7 +442,7 @@ func fetchFileAttachment(ctx *Context, res *Result, uri *url.URL) error { defer src.Close() if ctx.ProgressCallBack != nil { - if keep := ctx.ProgressCallBack(1, "receiving", 0.0, ctx.ProgressCallBackData); !keep { + if keep := ctx.ProgressCallBack(1, "receiving", 0.0, float64(sizeTotal), ctx.ProgressCallBackData); !keep { ctx.ProgressCallBack = nil } } |