"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: fail soft with a debug on hash failure #1474
Nick Craig-Wood870c58f7f855
diff --git a/backend/sftp/sftp.go b/backend/sftp/sftp.goindex 8e1537455..51a7e7c98 100644--- a/backend/sftp/sftp.go+++ b/backend/sftp/sftp.go@@ -5,6 +5,7 @@package sftpimport (+ "bytes""context""fmt""io"@@ -733,40 +734,44 @@ func (o *Object) Remote() string {// Hash returns the selected checksum of the file// If no checksum is available it returns ""func (o *Object) Hash(r hash.Type) (string, error) {- if r == hash.MD5 && o.md5sum != nil {- return *o.md5sum, nil- } else if r == hash.SHA1 && o.sha1sum != nil {- return *o.sha1sum, nil+ var hashCmd string+ if r == hash.MD5 {+ if o.md5sum != nil {+ return *o.md5sum, nil+ }+ hashCmd = "md5sum"+ } else if r == hash.SHA1 {+ if o.sha1sum != nil {+ return *o.sha1sum, nil+ }+ hashCmd = "sha1sum"+ } else {+ return "", hash.ErrUnsupported}c, err := o.fs.getSftpConnection()if err != nil {- return "", errors.Wrap(err, "Hash")+ return "", errors.Wrap(err, "Hash get SFTP connection")}session, err := c.sshClient.NewSession()o.fs.putSftpConnection(&c, err)if err != nil {- o.fs.cachedHashes = nil // Something has changed on the remote system- return "", hash.ErrUnsupported+ return "", errors.Wrap(err, "Hash put SFTP connection")}- err = hash.ErrUnsupported- var outputBytes []byte+ var stdout, stderr bytes.Buffer+ session.Stdout = &stdout+ session.Stderr = &stderrescapedPath := shellEscape(o.path())- if r == hash.MD5 {- outputBytes, err = session.Output("md5sum " + escapedPath)- } else if r == hash.SHA1 {- outputBytes, err = session.Output("sha1sum " + escapedPath)- }-+ err = session.Run(hashCmd + " " + escapedPath)if err != nil {- o.fs.cachedHashes = nil // Something has changed on the remote system_ = session.Close()- return "", hash.ErrUnsupported+ fs.Debugf(o, "Failed to calculate %v hash: %v (%s)", r, err, bytes.TrimSpace(stderr.Bytes()))+ return "", nil}_ = session.Close()- str := parseHash(outputBytes)+ str := parseHash(stdout.Bytes())if r == hash.MD5 {o.md5sum = &str} else if r == hash.SHA1 {