sftp: performance: don't consult config file outside of Fs setup

This commit is contained in:
Jon Fautley 2018-01-20 19:56:54 +00:00 committed by Nick Craig-Wood
parent e57a388851
commit 71bc108ce6

View File

@ -99,6 +99,8 @@ type Fs struct {
url string
mkdirLock *stringLock
cachedHashes *hash.Set
hashcheckDisabled bool
setModtime bool
poolMu sync.Mutex
pool []*conn
connLimit *rate.Limiter // for limiting number of connections per second
@ -273,6 +275,8 @@ func NewFs(name, root string) (fs.Fs, error) {
pass := config.FileGet(name, "pass")
keyFile := config.FileGet(name, "key_file")
insecureCipher := config.FileGetBool(name, "use_insecure_cipher")
hashcheckDisabled := config.FileGetBool(name, "disable_hashcheck")
setModtime := config.FileGetBool(name, "set_modtime", true)
if user == "" {
user = currentUser
}
@ -333,6 +337,8 @@ func NewFs(name, root string) (fs.Fs, error) {
host: host,
port: port,
url: "sftp://" + user + "@" + host + ":" + port + "/" + root,
hashcheckDisabled: hashcheckDisabled,
setModtime: setModtime,
mkdirLock: newStringLock(),
connLimit: rate.NewLimiter(rate.Limit(connectionsPerSecond), 1),
}
@ -640,8 +646,7 @@ func (f *Fs) Hashes() hash.Set {
return *f.cachedHashes
}
hashcheckDisabled := config.FileGetBool(f.name, "disable_hashcheck")
if hashcheckDisabled {
if f.hashcheckDisabled {
return hash.Set(hash.None)
}
@ -816,7 +821,7 @@ func (o *Object) SetModTime(modTime time.Time) error {
if err != nil {
return errors.Wrap(err, "SetModTime")
}
if config.FileGetBool(o.fs.name, "set_modtime", true) {
if o.fs.setModtime {
err = c.sftpClient.Chtimes(o.path(), modTime, modTime)
o.fs.putSftpConnection(&c, err)
if err != nil {