diff options
Diffstat (limited to 'rhimport/fetcher.go')
-rw-r--r-- | rhimport/fetcher.go | 40 |
1 files changed, 28 insertions, 12 deletions
diff --git a/rhimport/fetcher.go b/rhimport/fetcher.go index 4d942fa..1a957c3 100644 --- a/rhimport/fetcher.go +++ b/rhimport/fetcher.go @@ -364,6 +364,7 @@ func fetchFileArchiv(ctx *Context, res *Result, uri *url.URL) (err error) { rhdl.Printf("importing archiv file from %s", scpuri) err = easy.Perform() + var convOut string var convErr error if cbdata.conv != nil { @@ -412,7 +413,6 @@ func fetchFileTmp(ctx *Context, res *Result, uri *url.URL) (err error) { } func fetchFileDirConvert(ctx *Context, res *Result, origSrc *os.File, sizeTotal int64) (err error) { - basepath, err := ioutil.TempDir(ctx.conf.TempDir, "rhimportd-") if err != nil { return err @@ -452,14 +452,28 @@ func fetchFileDirConvert(ctx *Context, res *Result, origSrc *os.File, sizeTotal ctx.ProgressCallBack = nil } } + + if ctx.Cancel != nil && len(ctx.Cancel) > 0 { + res.ResponseCode = http.StatusNoContent + res.ErrorString = "canceled" + break + } } conv.Close() + if res.ResponseCode == http.StatusNoContent { + rhl.Printf("converting of '%s' got canceled", ctx.SourceUri) + return nil + } + rhl.Printf("waiting for converter to finish...") - if convOut, convErr := conv.GetResult(ctx, res); convErr != nil { - if convOut != "" { - rhl.Printf("converter error: %v; converter output: %s", convErr, convOut) + convOut, convErr := conv.GetResult(ctx, res) + if convErr != nil { + if res.ResponseCode == http.StatusNoContent { + rhl.Printf("converting of '%s' got canceled", ctx.SourceUri) + return nil } + rhl.Printf("converter error: %v; converter output: %s", convErr, convOut) return fmt.Errorf("converter error: %v; converter output: %s", convErr, convOut) } rhdl.Printf("converter: loudness correction = %.2f dB", ctx.LoudnessCorr) @@ -583,15 +597,10 @@ func fetchFileFake(ctx *Context, res *Result, uri *url.URL) error { } func writeAttachmentFile(ctx *Context, res *Result, sizeTotal uint64, conv FetchConverter) error { - cancel := ctx.Cancel - if cancel == nil { - cancel = make(<-chan bool) - } - written := uint64(0) for { select { - case <-cancel: + case <-ctx.Cancel: rhl.Printf("receiving attachment '%s' got canceled", ctx.SourceFile) res.ResponseCode = http.StatusNoContent res.ErrorString = "canceled" @@ -671,15 +680,22 @@ func fetchFileAttachment(ctx *Context, res *Result, uri *url.URL) error { err = writeAttachmentFile(ctx, res, sizeTotal, conv) conv.Close() + if res.ResponseCode == http.StatusNoContent { + rhl.Printf("download of '%s' got canceled", ctx.SourceUri) + return nil + } + rhl.Printf("waiting for converter to finish...") convOut, convErr := conv.GetResult(ctx, res) if err != nil { return err } if convErr != nil { - if convOut != "" { - rhl.Printf("converter error: %v; converter output: %s", convErr, convOut) + if res.ResponseCode == http.StatusNoContent { + rhl.Printf("download of '%s' got canceled", ctx.SourceUri) + return nil } + rhl.Printf("converter error: %v; converter output: %s", convErr, convOut) return fmt.Errorf("converter error: %v; converter output: %s", convErr, convOut) } rhdl.Printf("converter: loudness correction = %.2f dB", ctx.LoudnessCorr) |