@@ -57,11 +57,11 @@ function loadFingerprint( serverId, knownHostsPath, cb ) {
57
57
}
58
58
59
59
const _lockFingerprintFromAppending = { } ;
60
- function storeFingerprint ( serverId , knownHostsPath , fingerprint ) {
60
+ function storeFingerprint ( serverId , knownHostsPath , fingerprint , cb ) {
61
61
// we check if the serverId has been appended
62
62
if ( ! ! _lockFingerprintFromAppending [ serverId ] ) {
63
63
// if it has, we ignore it
64
- return ;
64
+ return cb ( null ) ;
65
65
}
66
66
67
67
// we make the line as appended
@@ -70,15 +70,11 @@ function storeFingerprint( serverId, knownHostsPath, fingerprint ) {
70
70
71
71
// we append to file
72
72
fs . appendFile ( knownHostsPath , serverId + " " + fingerprint + EOL , "utf8" , ( err ) => {
73
+ delete _lockFingerprintFromAppending [ serverId ] ;
73
74
if ( err ) {
74
75
console . log ( err ) ;
75
76
}
76
- } ) ;
77
-
78
- // since the error occurs in the span of one tick
79
- // after one tick we clean up to not interfere with anything else
80
- setImmediate ( ( ) => {
81
- delete _lockFingerprintFromAppending [ serverId ] ;
77
+ return cb ( err ) ;
82
78
} ) ;
83
79
}
84
80
@@ -145,8 +141,12 @@ const TrustStrategy = {
145
141
if ( knownFingerprint === serverFingerprint ) {
146
142
onSuccess ( ) ;
147
143
} else if ( knownFingerprint == null ) {
148
- storeFingerprint ( serverId , knownHostsPath , serverFingerprint ) ;
149
- onSuccess ( ) ;
144
+ storeFingerprint ( serverId , knownHostsPath , serverFingerprint , ( err ) => {
145
+ if ( err ) {
146
+ return onFailure ( err ) ;
147
+ }
148
+ return onSuccess ( ) ;
149
+ } ) ;
150
150
} else {
151
151
onFailure ( newError ( "Database encryption certificate has changed, and no longer " +
152
152
"matches the certificate stored for " + serverId + " in `" + knownHostsPath +
0 commit comments