summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Pointner <equinox@helsinki.at>2016-06-24 02:38:59 (GMT)
committerChristian Pointner <equinox@helsinki.at>2016-06-24 02:38:59 (GMT)
commit70a371f16e7a92821161e771a40b63c84fd194ea (patch)
tree625ecc61e6c578d8442220636df683358a875258
parentb76cbf24f5880f8a070fb3111d2b268052bdf97d (diff)
fixed canceling when uploading connection is gone
-rw-r--r--rhimport/fetcher.go16
-rw-r--r--rhimport/session.go1
2 files changed, 15 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)
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 {