sftp: fix under Windows #1432

This was caused by erroneous use of filepath to parse unix standard paths
This commit is contained in:
Nick Craig-Wood 2017-05-24 15:39:17 +01:00
parent 51d2174c0b
commit a243ea6353

View file

@ -9,16 +9,14 @@ import (
"net" "net"
"os" "os"
"path" "path"
"path/filepath"
"sync" "sync"
"time" "time"
"golang.org/x/crypto/ssh"
"golang.org/x/crypto/ssh/agent"
"github.com/ncw/rclone/fs" "github.com/ncw/rclone/fs"
"github.com/pkg/errors" "github.com/pkg/errors"
"github.com/pkg/sftp" "github.com/pkg/sftp"
"golang.org/x/crypto/ssh"
"golang.org/x/crypto/ssh/agent"
) )
func init() { func init() {
@ -323,27 +321,27 @@ func (f *Fs) mkParentDir(remote string) error {
} }
// mkdir makes the directory and parents using native paths // mkdir makes the directory and parents using native paths
func (f *Fs) mkdir(path string) error { func (f *Fs) mkdir(dirPath string) error {
f.mkdirLock.Lock(path) f.mkdirLock.Lock(dirPath)
defer f.mkdirLock.Unlock(path) defer f.mkdirLock.Unlock(dirPath)
if path == "." || path == "/" { if dirPath == "." || dirPath == "/" {
return nil return nil
} }
ok, err := f.dirExists(path) ok, err := f.dirExists(dirPath)
if err != nil { if err != nil {
return errors.Wrap(err, "mkdir dirExists failed") return errors.Wrap(err, "mkdir dirExists failed")
} }
if ok { if ok {
return nil return nil
} }
parent := filepath.Dir(path) parent := path.Dir(dirPath)
err = f.mkdir(parent) err = f.mkdir(parent)
if err != nil { if err != nil {
return err return err
} }
err = f.sftpClient.Mkdir(path) err = f.sftpClient.Mkdir(dirPath)
if err != nil { if err != nil {
return errors.Wrapf(err, "mkdir %q failed", path) return errors.Wrapf(err, "mkdir %q failed", dirPath)
} }
return nil return nil
} }