Skip to content

"rsync for cloud storage" - Google Drive, S3, Dropbox, Backblaze B2, One Drive, Swift, Hubic, Wasabi, Google Cloud Storage, Azure Blob, Azure Files, Yandex Files

serve sftp: fix hash calculations with --vfs-cache-mode full

Nick Craig-Wood7fc573db27f8
diff --git a/cmd/serve/sftp/connection.go b/cmd/serve/sftp/connection.go
index 42564c151..91c83002c 100644
--- a/cmd/serve/sftp/connection.go
+++ b/cmd/serve/sftp/connection.go
@@ -123,11 +123,28 @@ func (c *conn) execCommand(ctx context.Context, out io.Writer, command string) (
}
o, ok := node.DirEntry().(fs.ObjectInfo)
if !ok {
- return errors.New("unexpected non file")
- }
- hashSum, err = o.Hash(ctx, ht)
- if err != nil {
- return fmt.Errorf("hash failed: %w", err)
+ fs.Debugf(args, "File uploading - reading hash from VFS cache")
+ in, err := node.Open(os.O_RDONLY)
+ if err != nil {
+ return fmt.Errorf("hash vfs open failed: %w", err)
+ }
+ defer func() {
+ _ = in.Close()
+ }()
+ h, err := hash.NewMultiHasherTypes(hash.NewHashSet(ht))
+ if err != nil {
+ return fmt.Errorf("hash vfs create multi-hasher failed: %w", err)
+ }
+ _, err = io.Copy(h, in)
+ if err != nil {
+ return fmt.Errorf("hash vfs copy failed: %w", err)
+ }
+ hashSum = h.Sums()[ht]
+ } else {
+ hashSum, err = o.Hash(ctx, ht)
+ if err != nil {
+ return fmt.Errorf("hash failed: %w", err)
+ }
}
}
_, err = fmt.Fprintf(out, "%s %s\n", hashSum, args)