From 70a371f16e7a92821161e771a40b63c84fd194ea Mon Sep 17 00:00:00 2001 From: Christian Pointner Date: Fri, 24 Jun 2016 04:38:59 +0200 Subject: fixed canceling when uploading connection is gone diff --git a/rhimport/fetcher.go b/rhimport/fetcher.go index 5779631..0b1c3b2 100644 --- a/rhimport/fetcher.go +++ b/rhimport/fetcher.go @@ -368,15 +368,27 @@ func fetchFileFake(ctx *Context, res *Result, uri *url.URL) error { } func writeAttachmentFile(ctx *Context, res *Result, sizeTotal uint64, src *os.File) error { + cancel := ctx.Cancel + if cancel == nil { + cancel = make(<-chan bool) + } + written := 0 for { select { - case <-ctx.Cancel: + case <-cancel: rhl.Printf("receiving attachment '%s' got canceled", ctx.SourceFile) res.ResponseCode = http.StatusNoContent res.ErrorString = "canceled" return nil - case data := <-ctx.AttachmentChan: + case data, ok := <-ctx.AttachmentChan: + if !ok { + rhl.Printf("receiving attachment '%s' got canceled (channel has been closed)", ctx.SourceFile) + res.ResponseCode = http.StatusNoContent + res.ErrorString = "canceled" + return nil + } + w, err := src.Write(data) if err != nil { rhl.Printf("Unable to write file %s: %s", ctx.SourceFile, err) diff --git a/rhimport/session.go b/rhimport/session.go index e04066a..84d283e 100644 --- a/rhimport/session.go +++ b/rhimport/session.go @@ -221,6 +221,7 @@ func (self *Session) dispatchRequests() { if progressPending > 1 && lastProgress != nil { self.callProgressHandler(lastProgress) } + progressPending = 0 lastProgress = nil case p := <-self.progressIntChan: if self.state == SESSION_RUNNING { -- cgit v0.10.2