use std::io;
use vcs_runner::{Cmd, RunError};
pub(crate) fn retry_busy_executable(cmd: Cmd) -> Cmd {
cmd.retry_when(|err| matches!(err, RunError::Spawn { source, .. } if busy_executable(source)))
}
fn busy_executable(source: &io::Error) -> bool {
source.kind() == io::ErrorKind::ExecutableFileBusy || source.raw_os_error() == Some(26)
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn a_busy_kind_without_an_errno_is_still_busy() {
assert!(busy_executable(&io::Error::from(io::ErrorKind::ExecutableFileBusy)));
assert!(!busy_executable(&io::Error::from(io::ErrorKind::NotFound)));
}
proptest::proptest! {
#[test]
fn only_etxtbusy_reads_as_a_busy_executable(errno in 0i32..133) {
proptest::prop_assert_eq!(busy_executable(&io::Error::from_raw_os_error(errno)), errno == 26);
}
}
}