From e4f1e191277144c1d1fa75e01bf847fcc60d9c00 Mon Sep 17 00:00:00 2001 From: Nick Craig-Wood Date: Wed, 13 May 2020 21:53:04 +0100 Subject: [PATCH] sftp: fix post transfer copies failing with 0 size when using set_modtime=false Before this change we early exited the SetModTime call which means we skipped reading the info about the file. This change reads info about the file in the SetModTime call even if we are skipping setting the modtime. See: https://forum.rclone.org/t/sftp-and-set-modtime-false-error/16362 --- backend/sftp/sftp.go | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/backend/sftp/sftp.go b/backend/sftp/sftp.go index ec98c1719..7e5be399c 100644 --- a/backend/sftp/sftp.go +++ b/backend/sftp/sftp.go @@ -1102,19 +1102,18 @@ func (o *Object) stat() error { // // it also updates the info field func (o *Object) SetModTime(ctx context.Context, modTime time.Time) error { - if !o.fs.opt.SetModTime { - return nil + if o.fs.opt.SetModTime { + c, err := o.fs.getSftpConnection() + if err != nil { + return errors.Wrap(err, "SetModTime") + } + err = c.sftpClient.Chtimes(o.path(), modTime, modTime) + o.fs.putSftpConnection(&c, err) + if err != nil { + return errors.Wrap(err, "SetModTime failed") + } } - c, err := o.fs.getSftpConnection() - if err != nil { - return errors.Wrap(err, "SetModTime") - } - err = c.sftpClient.Chtimes(o.path(), modTime, modTime) - o.fs.putSftpConnection(&c, err) - if err != nil { - return errors.Wrap(err, "SetModTime failed") - } - err = o.stat() + err := o.stat() if err != nil { return errors.Wrap(err, "SetModTime stat failed") }