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

<!--- Please check the type of change your PR introduces: --->
- [ ] 🌻 Feature
- [x] 🐛 Bugfix
- [ ] 🗺️ Documentation
- [ ] 🤖 Test
- [ ] 💻 CI/Deployment
- [ ] 🐹 Trivial/Minor

## Test Plan

<!-- How will this be tested prior to merging.-->
- [x] 💪 Manual
- [x]  Unit test
- [ ] 💚 E2E
This commit is contained in:
Vaibhav Kamra 2022-09-26 15:20:54 -07:00 committed by GitHub
parent 7b5c8d43f1
commit ea73873ffb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 13 additions and 7 deletions

View File

@ -96,10 +96,10 @@ type itemWriter struct {
}
const (
contentRangeHeaderKey = "Content-Range"
contentLengthHeaderKey = "Content-Length"
// Format for Content-Length is "bytes <start>-<end>/<total>"
contentLengthHeaderValueFmt = "bytes %d-%d/%d"
contentRangeHeaderKey = "Content-Range"
// Format for Content-Range is "bytes <start>-<end>/<total>"
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),

View File

@ -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)
}

View File

@ -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

View File

@ -535,6 +535,7 @@ func getItemStream(
return &kopiaDataStream{
uuid: decodedName,
reader: r,
size: f.Size(),
}, nil
}

View File

@ -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()))
}
}