mirror of
https://github.com/rclone/rclone.git
synced 2025-08-14 07:49:00 +02:00
serve s3: fixes before merge
- add context to log and fallthrough to error log level - test: use rclone random lib to generate random strings - calculate hash from vfs cache if file is uploading - add server started log with server url - remove md5 hasher
This commit is contained in:
@ -4,11 +4,14 @@ import (
|
||||
"context"
|
||||
"encoding/hex"
|
||||
"fmt"
|
||||
"io"
|
||||
"os"
|
||||
"path"
|
||||
"strings"
|
||||
|
||||
"github.com/Mikubill/gofakes3"
|
||||
"github.com/rclone/rclone/fs"
|
||||
"github.com/rclone/rclone/fs/hash"
|
||||
"github.com/rclone/rclone/vfs"
|
||||
)
|
||||
|
||||
@ -47,9 +50,29 @@ func getFileHash(node interface{}) string {
|
||||
|
||||
switch b := node.(type) {
|
||||
case vfs.Node:
|
||||
o = b.DirEntry().(fs.Object)
|
||||
case fs.DirEntry:
|
||||
o = b.(fs.Object)
|
||||
fsObj, ok := b.DirEntry().(fs.Object)
|
||||
if !ok {
|
||||
fs.Debugf("serve s3", "File uploading - reading hash from VFS cache")
|
||||
in, err := b.Open(os.O_RDONLY)
|
||||
if err != nil {
|
||||
return ""
|
||||
}
|
||||
defer func() {
|
||||
_ = in.Close()
|
||||
}()
|
||||
h, err := hash.NewMultiHasherTypes(hash.NewHashSet(Opt.hashType))
|
||||
if err != nil {
|
||||
return ""
|
||||
}
|
||||
_, err = io.Copy(h, in)
|
||||
if err != nil {
|
||||
return ""
|
||||
}
|
||||
return h.Sums()[Opt.hashType]
|
||||
}
|
||||
o = fsObj
|
||||
case fs.Object:
|
||||
o = b
|
||||
}
|
||||
|
||||
hash, err := o.Hash(context.Background(), Opt.hashType)
|
||||
|
Reference in New Issue
Block a user