From 32ab4e9ac691886ccff472cca4757eebe5a961b6 Mon Sep 17 00:00:00 2001 From: Nick Craig-Wood Date: Sat, 1 Sep 2018 10:01:02 +0100 Subject: [PATCH] pcloud: delete half uploaded files on upload error Sometimes pcloud will leave a half uploaded file when the transfer actually failed. This patch deletes the file if it exists. This problem was spotted by the integration tests. --- backend/pcloud/pcloud.go | 6 ++++++ fstest/fstests/fstests.go | 2 ++ 2 files changed, 8 insertions(+) diff --git a/backend/pcloud/pcloud.go b/backend/pcloud/pcloud.go index 8654e9ffa..ec390e513 100644 --- a/backend/pcloud/pcloud.go +++ b/backend/pcloud/pcloud.go @@ -1107,6 +1107,12 @@ func (o *Object) Update(in io.Reader, src fs.ObjectInfo, options ...fs.OpenOptio return shouldRetry(resp, err) }) if err != nil { + // sometimes pcloud leaves a half complete file on + // error, so delete it if it exists + delObj, delErr := o.fs.NewObject(o.remote) + if delErr == nil && delObj != nil { + _ = delObj.Remove() + } return err } if len(result.Items) != 1 { diff --git a/fstest/fstests/fstests.go b/fstest/fstests/fstests.go index 4f2738860..5c4feb1f3 100644 --- a/fstest/fstests/fstests.go +++ b/fstest/fstests/fstests.go @@ -379,6 +379,8 @@ func Run(t *testing.T, opt *Opt) { // // It makes sure that aborting a file half way through does not create // a file on the remote. + // + // go test -v -run 'TestIntegration/Test(Setup|Init|FsMkdir|FsPutError)$' t.Run("TestFsPutError", func(t *testing.T) { skipIfNotOk(t)