diff options
author | Christian Pointner <equinox@helsinki.at> | 2016-06-24 02:38:59 (GMT) |
---|---|---|
committer | Christian Pointner <equinox@helsinki.at> | 2016-06-24 02:38:59 (GMT) |
commit | 70a371f16e7a92821161e771a40b63c84fd194ea (patch) | |
tree | 625ecc61e6c578d8442220636df683358a875258 /rhimport/fetcher.go | |
parent | b76cbf24f5880f8a070fb3111d2b268052bdf97d (diff) |
fixed canceling when uploading connection is gone
Diffstat (limited to 'rhimport/fetcher.go')
-rw-r--r-- | rhimport/fetcher.go | 16 |
1 files changed, 14 insertions, 2 deletions
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) |