From ea73873ffbbfdd74473a1eda8451213439a7c32d Mon Sep 17 00:00:00 2001 From: Vaibhav Kamra Date: Mon, 26 Sep 2022 15:20:54 -0700 Subject: [PATCH] Fix OneDrive restore regressions (#953) ## Description Fixes a couple of regressions that got introduced on the restore path via code review changes and kopia wrapper refactor. Found while writing the OneDrive restore test. Would have been prevented if we had said test. ## Type of change - [ ] :sunflower: Feature - [x] :bug: Bugfix - [ ] :world_map: Documentation - [ ] :robot: Test - [ ] :computer: CI/Deployment - [ ] :hamster: Trivial/Minor ## Test Plan - [x] :muscle: Manual - [x] :zap: Unit test - [ ] :green_heart: E2E --- src/internal/connector/onedrive/item.go | 10 +++++----- src/internal/connector/onedrive/restore.go | 2 +- src/internal/connector/support/status.go | 3 ++- src/internal/kopia/wrapper.go | 1 + src/internal/kopia/wrapper_test.go | 4 ++++ 5 files changed, 13 insertions(+), 7 deletions(-) diff --git a/src/internal/connector/onedrive/item.go b/src/internal/connector/onedrive/item.go index 4cf8a91f7..f76e989f2 100644 --- a/src/internal/connector/onedrive/item.go +++ b/src/internal/connector/onedrive/item.go @@ -96,10 +96,10 @@ type itemWriter struct { } const ( - contentRangeHeaderKey = "Content-Range" - contentLengthHeaderKey = "Content-Length" - // Format for Content-Length is "bytes -/" - contentLengthHeaderValueFmt = "bytes %d-%d/%d" + contentRangeHeaderKey = "Content-Range" + // Format for Content-Range is "bytes -/" + contentRangeHeaderValueFmt = "bytes %d-%d/%d" + contentLengthHeaderKey = "Content-Length" ) // Write will upload the provided data to OneDrive. It sets the `Content-Length` and `Content-Range` headers based on @@ -117,7 +117,7 @@ func (iw *itemWriter) Write(p []byte) (n int, err error) { // data in the current request resp, err := client.R(). SetHeaders(map[string]string{ - contentRangeHeaderKey: fmt.Sprintf(contentLengthHeaderValueFmt, + contentRangeHeaderKey: fmt.Sprintf(contentRangeHeaderValueFmt, iw.lastWrittenOffset, endOffset-1, iw.contentLength), diff --git a/src/internal/connector/onedrive/restore.go b/src/internal/connector/onedrive/restore.go index 0a06abeb5..d514a0aa6 100644 --- a/src/internal/connector/onedrive/restore.go +++ b/src/internal/connector/onedrive/restore.go @@ -136,7 +136,7 @@ func createRestoreFolders(ctx context.Context, service graph.Service, driveID st continue } - if err != errFolderNotFound { + if !errors.Is(err, errFolderNotFound) { return "", errors.Wrapf(err, "folder %s not found in drive(%s) parentFolder(%s)", folder, driveID, parentFolderID) } diff --git a/src/internal/connector/support/status.go b/src/internal/connector/support/status.go index 095d79851..3d691a4d7 100644 --- a/src/internal/connector/support/status.go +++ b/src/internal/connector/support/status.go @@ -56,7 +56,8 @@ func CreateStatus( "status object count does not match errors + successes", "objects", objects, "successes", success, - "errors", numErr) + "numErrors", numErr, + "errors", err.Error()) } return &status diff --git a/src/internal/kopia/wrapper.go b/src/internal/kopia/wrapper.go index 76fcb46cf..7bfec71fd 100644 --- a/src/internal/kopia/wrapper.go +++ b/src/internal/kopia/wrapper.go @@ -535,6 +535,7 @@ func getItemStream( return &kopiaDataStream{ uuid: decodedName, reader: r, + size: f.Size(), }, nil } diff --git a/src/internal/kopia/wrapper_test.go b/src/internal/kopia/wrapper_test.go index 42fdc0b99..89e3dd4a5 100644 --- a/src/internal/kopia/wrapper_test.go +++ b/src/internal/kopia/wrapper_test.go @@ -72,6 +72,10 @@ func testForFiles( require.NoError(t, err, "reading collection item: %s", fullPath) assert.Equal(t, expected, buf, "comparing collection item: %s", fullPath) + + require.Implements(t, (*data.StreamSize)(nil), s) + ss := s.(data.StreamSize) + assert.Equal(t, len(buf), int(ss.Size())) } }