From 8c7d075484eb8153dd294bce73c428a0cf3535a6 Mon Sep 17 00:00:00 2001 From: HFO4 <912394456@qq.com> Date: Tue, 7 Apr 2020 10:51:54 +0800 Subject: [PATCH] Fix: repeated return of capacity when OneDrive WebDAV upload canceled --- assets | 2 +- pkg/filesystem/driver/onedrive/api.go | 3 -- pkg/filesystem/driver/onedrive/api_test.go | 49 ---------------------- 3 files changed, 1 insertion(+), 53 deletions(-) diff --git a/assets b/assets index 15a7805..f544486 160000 --- a/assets +++ b/assets @@ -1 +1 @@ -Subproject commit 15a7805c2e1dc90a4c92c8165ce44d0f315a5d39 +Subproject commit f544486b6ae2440df197630601b1827ed6977c0b diff --git a/pkg/filesystem/driver/onedrive/api.go b/pkg/filesystem/driver/onedrive/api.go index 5c58344..ca19426 100644 --- a/pkg/filesystem/driver/onedrive/api.go +++ b/pkg/filesystem/driver/onedrive/api.go @@ -216,9 +216,6 @@ func (client *Client) Upload(ctx context.Context, dst string, size int, file io. // 因为后面需要错误重试,这里要把分片内容读到内存中 chunkContent := chunkData[:chunkSize] _, err := io.ReadFull(file, chunkContent) - if err != nil { - return err - } chunk := Chunk{ Offset: offset, diff --git a/pkg/filesystem/driver/onedrive/api_test.go b/pkg/filesystem/driver/onedrive/api_test.go index 718ffab..d06469e 100644 --- a/pkg/filesystem/driver/onedrive/api_test.go +++ b/pkg/filesystem/driver/onedrive/api_test.go @@ -506,55 +506,6 @@ func TestClient_Upload(t *testing.T) { asserts.Error(err) } - // 大文件 分两个分片 ,reader 返回EOF - { - client.Credential.ExpiresIn = time.Now().Add(time.Duration(100) * time.Hour).Unix() - clientMock := ClientMock{} - clientMock.On( - "Request", - "POST", - testMock.Anything, - testMock.Anything, - testMock.Anything, - ).Return(&request.Response{ - Err: nil, - Response: &http.Response{ - StatusCode: 200, - Body: ioutil.NopCloser(strings.NewReader(`{"uploadUrl":"123321"}`)), - }, - }) - client.Request = clientMock - - err := client.Upload(context.Background(), "123.jpg", 15*1024*1024, strings.NewReader("123")) - clientMock.AssertExpectations(t) - asserts.Error(err) - } - - // 大文件 分两个分片 失败 - { - cache.Set("setting_onedrive_chunk_retries", "0", 0) - client.Credential.ExpiresIn = time.Now().Add(time.Duration(100) * time.Hour).Unix() - clientMock := ClientMock{} - clientMock.On( - "Request", - "POST", - testMock.Anything, - testMock.Anything, - testMock.Anything, - ).Return(&request.Response{ - Err: nil, - Response: &http.Response{ - StatusCode: 200, - Body: ioutil.NopCloser(strings.NewReader(`{"uploadUrl":"123321"}`)), - }, - }) - client.Request = clientMock - - err := client.Upload(context.Background(), "123.jpg", 15*1024*1024, strings.NewReader("123")) - clientMock.AssertExpectations(t) - asserts.Error(err) - } - // 上下文取消 { client.Credential.ExpiresIn = time.Now().Add(time.Duration(100) * time.Hour).Unix()