From 5d6a6dd6c012d3f308a9e174923f9bf92f7a765e Mon Sep 17 00:00:00 2001 From: m8rge Date: Sat, 28 May 2022 21:45:46 +0300 Subject: [PATCH] dropbox: migrate from deprecated api Change UploadSessionFinishBatch usage to UploadSessionFinishBatchV2. Change in sdk was made in https://github.com/dropbox/dropbox-sdk-go-unofficial/pull/106 --- backend/dropbox/batcher.go | 23 ++++------------------- 1 file changed, 4 insertions(+), 19 deletions(-) diff --git a/backend/dropbox/batcher.go b/backend/dropbox/batcher.go index 96185dde3..ac87c71e0 100644 --- a/backend/dropbox/batcher.go +++ b/backend/dropbox/batcher.go @@ -118,12 +118,12 @@ func (b *batcher) Batching() bool { } // finishBatch commits the batch, returning a batch status to poll or maybe complete -func (b *batcher) finishBatch(ctx context.Context, items []*files.UploadSessionFinishArg) (batchStatus *files.UploadSessionFinishBatchLaunch, err error) { +func (b *batcher) finishBatch(ctx context.Context, items []*files.UploadSessionFinishArg) (complete *files.UploadSessionFinishBatchResult, err error) { var arg = &files.UploadSessionFinishBatchArg{ Entries: items, } err = b.f.pacer.Call(func() (bool, error) { - batchStatus, err = b.f.srv.UploadSessionFinishBatch(arg) + complete, err = b.f.srv.UploadSessionFinishBatchV2(arg) // If error is insufficient space then don't retry if e, ok := err.(files.UploadSessionFinishAPIError); ok { if e.EndpointError != nil && e.EndpointError.Path != nil && e.EndpointError.Path.Tag == files.WriteErrorInsufficientSpace { @@ -137,7 +137,7 @@ func (b *batcher) finishBatch(ctx context.Context, items []*files.UploadSessionF if err != nil { return nil, fmt.Errorf("batch commit failed: %w", err) } - return batchStatus, nil + return complete, nil } // finishBatchJobStatus waits for the batch to complete returning completed entries @@ -199,26 +199,11 @@ func (b *batcher) commitBatch(ctx context.Context, items []*files.UploadSessionF fs.Debugf(b.f, "Committing %s", desc) // finalise the batch getting either a result or a job id to poll - batchStatus, err := b.finishBatch(ctx, items) + complete, err := b.finishBatch(ctx, items) if err != nil { return err } - // check whether batch is complete - var complete *files.UploadSessionFinishBatchResult - switch batchStatus.Tag { - case "async_job_id": - // wait for batch to complete - complete, err = b.finishBatchJobStatus(ctx, batchStatus) - if err != nil { - return err - } - case "complete": - complete = batchStatus.Complete - default: - return fmt.Errorf("batch returned unknown status %q", batchStatus.Tag) - } - // Check we got the right number of entries entries := complete.Entries if len(entries) != len(results) {