File tree Expand file tree Collapse file tree 1 file changed +13
-1
lines changed Expand file tree Collapse file tree 1 file changed +13
-1
lines changed Original file line number Diff line number Diff line change @@ -277,18 +277,30 @@ func ParseOpenSSHVersion(version []byte) *semver.Version {
277
277
return & semver.Version {}
278
278
}
279
279
280
+ // sshVersions caches the parsed version of each ssh executable, if it is needed again.
281
+ var sshVersions = map [string ]* semver.Version {}
282
+
280
283
func DetectOpenSSHVersion () semver.Version {
281
284
var (
282
285
v semver.Version
283
286
stderr bytes.Buffer
284
287
)
285
- cmd := exec .Command ("ssh" , "-V" )
288
+ path , err := exec .LookPath ("ssh" )
289
+ if err != nil {
290
+ logrus .Warnf ("failed to find ssh executable: %v" , err )
291
+ } else {
292
+ if ver := sshVersions [path ]; ver != nil {
293
+ return * ver
294
+ }
295
+ }
296
+ cmd := exec .Command (path , "-V" )
286
297
cmd .Stderr = & stderr
287
298
if err := cmd .Run (); err != nil {
288
299
logrus .Warnf ("failed to run %v: stderr=%q" , cmd .Args , stderr .String ())
289
300
} else {
290
301
v = * ParseOpenSSHVersion (stderr .Bytes ())
291
302
logrus .Debugf ("OpenSSH version %s detected" , v )
303
+ sshVersions [path ] = & v
292
304
}
293
305
return v
294
306
}
You can’t perform that action at this time.
0 commit comments