From 7edb4c0162a67768c47e3dd7bbae3ae9819039e8 Mon Sep 17 00:00:00 2001 From: Nick Craig-Wood Date: Wed, 14 Dec 2022 14:37:07 +0000 Subject: [PATCH] sftp: fix NewObject with leading / This was breaking the use of operations/stat with remote with an initial / See: https://forum.rclone.org/t/rclone-rc-api-operations-stat-is-not-working-for-sftp-remotes/34560 --- backend/sftp/sftp.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/backend/sftp/sftp.go b/backend/sftp/sftp.go index 109745267..c998180c7 100644 --- a/backend/sftp/sftp.go +++ b/backend/sftp/sftp.go @@ -1775,11 +1775,14 @@ func (o *Object) setMetadata(info os.FileInfo) { // statRemote stats the file or directory at the remote given func (f *Fs) stat(ctx context.Context, remote string) (info os.FileInfo, err error) { + absPath := remote + if !strings.HasPrefix(remote, "/") { + absPath = path.Join(f.absRoot, remote) + } c, err := f.getSftpConnection(ctx) if err != nil { return nil, fmt.Errorf("stat: %w", err) } - absPath := path.Join(f.absRoot, remote) info, err = c.sftpClient.Stat(absPath) f.putSftpConnection(&c, err) return info, err