"rsync for cloud storage" - Google Drive, S3, Dropbox, Backblaze B2, One Drive, Swift, Hubic, Wasabi, Google Cloud Storage, Azure Blob, Azure Files, Yandex Files
Go azure-blobazure-blob-storageazure-filesbackblaze-b2cloud-storagedropboxencryptionftpfuse-filesystemgogolanggoogle-cloud-storagegoogle-driveonedriveopenstack-swiftrclones3sftpsyncwebdav
sftp: follow symlinks correctly - fixes #2145
Nick Craig-Woodd1bb8efb88ee
diff --git a/backend/sftp/sftp.go b/backend/sftp/sftp.goindex 6453a9783..4b481a206 100644--- a/backend/sftp/sftp.go+++ b/backend/sftp/sftp.go@@ -481,6 +481,14 @@ func (f *Fs) List(dir string) (entries fs.DirEntries, err error) {}for _, info := range infos {remote := path.Join(dir, info.Name())+ // If file is a symlink (not a regular file is the best cross platform test we can do), do a stat to+ // pick up the size and type of the destination, instead of the size and type of the symlink.+ if !info.Mode().IsRegular() {+ info, err = f.stat(remote)+ if err != nil {+ return nil, errors.Wrap(err, "stat of non-regular file/dir failed")+ }+ }if info.IsDir() {d := fs.NewDir(remote, info.ModTime())entries = append(entries, d)@@ -805,14 +813,21 @@ func (o *Object) setMetadata(info os.FileInfo) {o.mode = info.Mode()}-// stat updates the info in the Object-func (o *Object) stat() error {- c, err := o.fs.getSftpConnection()+// statRemote stats the file or directory at the remote given+func (f *Fs) stat(remote string) (info os.FileInfo, err error) {+ c, err := f.getSftpConnection()if err != nil {- return errors.Wrap(err, "stat")+ return nil, errors.Wrap(err, "stat")}- info, err := c.sftpClient.Stat(o.path())- o.fs.putSftpConnection(&c, err)+ absPath := path.Join(f.root, remote)+ info, err = c.sftpClient.Stat(absPath)+ f.putSftpConnection(&c, err)+ return info, err+}++// stat updates the info in the Object+func (o *Object) stat() error {+ info, err := o.fs.stat(o.remote)if err != nil {if os.IsNotExist(err) {return fs.ErrorObjectNotFound