Skip to content

Commit d3d50a9

Browse files
committed
Add the size and the mtime to the cache key
Signed-off-by: Anders F Björklund <[email protected]>
1 parent 0a50cd7 commit d3d50a9

File tree

1 file changed

+14
-3
lines changed

1 file changed

+14
-3
lines changed

pkg/sshutil/sshutil.go

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import (
1414
"runtime"
1515
"strings"
1616
"sync"
17+
"time"
1718

1819
"github.com/coreos/go-semver/semver"
1920
"github.com/lima-vm/lima/pkg/ioutilx"
@@ -277,19 +278,29 @@ func ParseOpenSSHVersion(version []byte) *semver.Version {
277278
return &semver.Version{}
278279
}
279280

281+
// sshExecutable beyond path also records size and mtime, in the case of ssh upgrades.
282+
type sshExecutable struct {
283+
Path string
284+
Size int64
285+
ModTime time.Time
286+
}
287+
280288
// sshVersions caches the parsed version of each ssh executable, if it is needed again.
281-
var sshVersions = map[string]*semver.Version{}
289+
var sshVersions = map[sshExecutable]*semver.Version{}
282290

283291
func DetectOpenSSHVersion() semver.Version {
284292
var (
285293
v semver.Version
294+
exe sshExecutable
286295
stderr bytes.Buffer
287296
)
288297
path, err := exec.LookPath("ssh")
289298
if err != nil {
290299
logrus.Warnf("failed to find ssh executable: %v", err)
291300
} else {
292-
if ver := sshVersions[path]; ver != nil {
301+
st, _ := os.Stat(path)
302+
exe = sshExecutable{Path: path, Size: st.Size(), ModTime: st.ModTime()}
303+
if ver := sshVersions[exe]; ver != nil {
293304
return *ver
294305
}
295306
}
@@ -300,7 +311,7 @@ func DetectOpenSSHVersion() semver.Version {
300311
} else {
301312
v = *ParseOpenSSHVersion(stderr.Bytes())
302313
logrus.Debugf("OpenSSH version %s detected", v)
303-
sshVersions[path] = &v
314+
sshVersions[exe] = &v
304315
}
305316
return v
306317
}

0 commit comments

Comments
 (0)