From 84caf1e158d28d6eccac32dd57c91d30a995690f Mon Sep 17 00:00:00 2001 From: Nick Craig-Wood Date: Wed, 18 Mar 2020 11:53:06 +0000 Subject: [PATCH] qingstor: try harder to cancel failed multipart uploads --- backend/qingstor/upload.go | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/backend/qingstor/upload.go b/backend/qingstor/upload.go index 5103c1924..32fc33d26 100644 --- a/backend/qingstor/upload.go +++ b/backend/qingstor/upload.go @@ -341,12 +341,17 @@ func (mu *multiUploader) abort() error { } // multiPartUpload upload a multiple object into QingStor -func (mu *multiUploader) multiPartUpload(firstBuf io.ReadSeeker) error { - var err error - //Initiate an multi-part upload +func (mu *multiUploader) multiPartUpload(firstBuf io.ReadSeeker) (err error) { + // Initiate an multi-part upload if err = mu.initiate(); err != nil { return err } + defer func() { + // Abort the transfer if returning an error + if err != nil { + _ = mu.abort() + } + }() ch := make(chan chunk, mu.cfg.concurrency) for i := 0; i < mu.cfg.concurrency; i++ { @@ -400,9 +405,5 @@ func (mu *multiUploader) multiPartUpload(firstBuf io.ReadSeeker) error { close(ch) mu.wg.Wait() // Complete Multipart Upload - err = mu.complete() - if mu.getErr() != nil || err != nil { - _ = mu.abort() - } - return err + return mu.complete() }