Skip to content

Commit 3cecc8e

Browse files
committed
Merge branch 'ssh-known-hosts-markers' of github.com:hds/cargo into ssh-known-hosts-markers
2 parents 26e08ab + a871a90 commit 3cecc8e

File tree

1 file changed

+10
-21
lines changed

1 file changed

+10
-21
lines changed

src/cargo/sources/git/known_hosts.rs

Lines changed: 10 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -434,7 +434,7 @@ fn check_ssh_known_hosts_loaded(
434434
return Ok(());
435435
}
436436

437-
if latent_errors.len() == 0 {
437+
if latent_errors.is_empty() {
438438
// FIXME: Ideally the error message should include the IP address of the
439439
// remote host (to help the user validate that they are connecting to the
440440
// host they were expecting to). However, I don't see a way to obtain that
@@ -450,27 +450,16 @@ fn check_ssh_known_hosts_loaded(
450450
// We're going to take the first HostKeyHasChanged error if
451451
// we find one, otherwise we'll take the first error (which
452452
// we expect to be a CertAuthority error).
453-
for err in &latent_errors {
454-
if let KnownHostError::HostKeyHasChanged {
455-
hostname,
456-
key_type,
457-
old_known_host,
458-
remote_host_key,
459-
remote_fingerprint,
460-
} = err
461-
{
462-
return Err(KnownHostError::HostKeyHasChanged {
463-
hostname: hostname.clone(),
464-
key_type: key_type.clone(),
465-
old_known_host: old_known_host.clone(),
466-
remote_host_key: remote_host_key.clone(),
467-
remote_fingerprint: remote_fingerprint.clone(),
468-
});
469-
}
453+
if let Some(index) = latent_errors
454+
.iter()
455+
.position(|e| matches!(e, KnownHostError::HostKeyHasChanged { .. }))
456+
{
457+
return Err(latent_errors.remove(index));
458+
} else {
459+
// Otherwise, we take the first error (which we expect to be
460+
// a CertAuthority error).
461+
Err(latent_errors.pop().unwrap())
470462
}
471-
// Otherwise, we take the first error (which we expect to be
472-
// a CertAuthority error).
473-
Err(latent_errors.pop().unwrap())
474463
}
475464
}
476465

0 commit comments

Comments
 (0)