From 2f63a9f81cd5fae993be6f5fa57c705ddd1da465 Mon Sep 17 00:00:00 2001 From: Victor Date: Fri, 16 Feb 2018 14:21:26 +0100 Subject: [PATCH] onedrive: Overwrite object size value with real size when reading file. Because of a bug in the Onedrive API it will sometime report the wrong size. If the size is wrong other remotes that depend on the size might fail. To fix this we overwrite the objects size with the real size from ContentLength header. --- backend/onedrive/onedrive.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/backend/onedrive/onedrive.go b/backend/onedrive/onedrive.go index 068928010..874a6128f 100644 --- a/backend/onedrive/onedrive.go +++ b/backend/onedrive/onedrive.go @@ -1079,6 +1079,11 @@ func (o *Object) Open(options ...fs.OpenOption) (in io.ReadCloser, err error) { if err != nil { return nil, err } + + if resp.StatusCode == http.StatusOK && resp.ContentLength > 0 && resp.Header.Get("Content-Range") == "" { + //Overwrite size with actual size since size readings from Onedrive is unreliable. + o.size = resp.ContentLength + } return resp.Body, err }