diff options
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) |