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
This commit is contained in:
Nick Craig-Wood 2022-12-14 14:37:07 +00:00
parent 5db4493557
commit 7edb4c0162

View File

@ -1775,11 +1775,14 @@ func (o *Object) setMetadata(info os.FileInfo) {
// statRemote stats the file or directory at the remote given // statRemote stats the file or directory at the remote given
func (f *Fs) stat(ctx context.Context, remote string) (info os.FileInfo, err error) { 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) c, err := f.getSftpConnection(ctx)
if err != nil { if err != nil {
return nil, fmt.Errorf("stat: %w", err) return nil, fmt.Errorf("stat: %w", err)
} }
absPath := path.Join(f.absRoot, remote)
info, err = c.sftpClient.Stat(absPath) info, err = c.sftpClient.Stat(absPath)
f.putSftpConnection(&c, err) f.putSftpConnection(&c, err)
return info, err return info, err