onedrive: fix incorrectly decoded SHA-1

This commit is contained in:
Nick Craig-Wood 2016-01-17 10:45:17 +00:00
parent d0678bc3e5
commit a63dd6020c

View File

@ -4,7 +4,6 @@ package onedrive
import ( import (
"bytes" "bytes"
"encoding/base64"
"fmt" "fmt"
"io" "io"
"log" "log"
@ -14,8 +13,6 @@ import (
"sync" "sync"
"time" "time"
"encoding/hex"
"github.com/ncw/rclone/dircache" "github.com/ncw/rclone/dircache"
"github.com/ncw/rclone/fs" "github.com/ncw/rclone/fs"
"github.com/ncw/rclone/oauthutil" "github.com/ncw/rclone/oauthutil"
@ -727,14 +724,15 @@ func (o *Object) setMetaData(info *api.Item) {
o.hasMetaData = true o.hasMetaData = true
o.size = info.Size o.size = info.Size
// Docs: https://dev.onedrive.com/facets/hashes_facet.htm
//
// The docs state both that the hashes are returned as hex
// strings, and as base64 strings. Testing reveals they are in
// fact uppercase hex strings.
//
// In OneDrive for Business, SHA1 and CRC32 hash values are not returned for files. // In OneDrive for Business, SHA1 and CRC32 hash values are not returned for files.
if info.File != nil && info.File.Hashes.Sha1Hash != "" { if info.File != nil && info.File.Hashes.Sha1Hash != "" {
sha1sumData, err := base64.StdEncoding.DecodeString(info.File.Hashes.Sha1Hash) o.sha1 = strings.ToLower(info.File.Hashes.Sha1Hash)
if err != nil {
fs.Log(o, "Bad SHA1 decode: %v", err)
} else {
o.sha1 = hex.EncodeToString(sha1sumData)
}
} }
if info.FileSystemInfo != nil { if info.FileSystemInfo != nil {
o.modTime = time.Time(info.FileSystemInfo.LastModifiedDateTime) o.modTime = time.Time(info.FileSystemInfo.LastModifiedDateTime)