mirror of https://github.com/rclone/rclone.git
serve sftp: fix hash calculations with --vfs-cache-mode full
Before this change uploading files with rclone to: rclone serve sftp --vfs-cache-mode full Would return the error: command "md5sum XXX" failed with error: unexpected non file This patch detects that the file is still in the VFS cache and reads the MD5SUM from there rather from the remote. Fixes #7241
This commit is contained in:
parent
af95616122
commit
7fc573db27
|
@ -123,11 +123,28 @@ func (c *conn) execCommand(ctx context.Context, out io.Writer, command string) (
|
||||||
}
|
}
|
||||||
o, ok := node.DirEntry().(fs.ObjectInfo)
|
o, ok := node.DirEntry().(fs.ObjectInfo)
|
||||||
if !ok {
|
if !ok {
|
||||||
return errors.New("unexpected non file")
|
fs.Debugf(args, "File uploading - reading hash from VFS cache")
|
||||||
}
|
in, err := node.Open(os.O_RDONLY)
|
||||||
hashSum, err = o.Hash(ctx, ht)
|
if err != nil {
|
||||||
if err != nil {
|
return fmt.Errorf("hash vfs open failed: %w", err)
|
||||||
return fmt.Errorf("hash 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)
|
_, err = fmt.Fprintf(out, "%s %s\n", hashSum, args)
|
||||||
|
|
Loading…
Reference in New Issue