|  | 
| 7 | 7 | use cap_std_ext::prelude::CapStdExtCommandExt; | 
| 8 | 8 | use cap_std_ext::{cap_std, cap_tempfile}; | 
| 9 | 9 | use futures_util::{Future, FutureExt}; | 
|  | 10 | +use itertools::Itertools; | 
| 10 | 11 | use oci_spec::image::{Descriptor, Digest}; | 
| 11 | 12 | use serde::{Deserialize, Serialize}; | 
| 12 | 13 | use std::fs::File; | 
| @@ -382,39 +383,27 @@ impl FromReplyFds for () { | 
| 382 | 383 | /// A FinishPipe instance | 
| 383 | 384 | impl FromReplyFds for FinishPipe { | 
| 384 | 385 |     fn from_reply(fds: impl IntoIterator<Item = OwnedFd>, pipeid: u32) -> Result<Self> { | 
| 385 |  | -        let mut fds = fds.into_iter(); | 
| 386 |  | -        let Some(first_fd) = fds.next() else { | 
| 387 |  | -            return Err(Error::Other("Expected fd for FinishPipe".into())); | 
| 388 |  | -        }; | 
| 389 |  | -        if fds.next().is_some() { | 
| 390 |  | -            return Err(Error::Other("More than one fd for FinishPipe".into())); | 
| 391 |  | -        } | 
| 392 | 386 |         let Some(pipeid) = PipeId::try_new(pipeid) else { | 
| 393 | 387 |             return Err(Error::Other("Expected pipeid for FinishPipe".into())); | 
| 394 | 388 |         }; | 
| 395 |  | -        Ok(Self { | 
| 396 |  | -            pipeid, | 
| 397 |  | -            datafd: first_fd, | 
| 398 |  | -        }) | 
|  | 389 | +        let datafd = fds | 
|  | 390 | +            .into_iter() | 
|  | 391 | +            .exactly_one() | 
|  | 392 | +            .map_err(|_| Error::Other("Expected exactly one fd for FinishPipe".into()))?; | 
|  | 393 | +        Ok(Self { pipeid, datafd }) | 
| 399 | 394 |     } | 
| 400 | 395 | } | 
| 401 | 396 | 
 | 
| 402 | 397 | /// A DualFds instance | 
| 403 | 398 | impl FromReplyFds for DualFds { | 
| 404 | 399 |     fn from_reply(fds: impl IntoIterator<Item = OwnedFd>, pipeid: u32) -> Result<Self> { | 
| 405 |  | -        let mut fds = fds.into_iter(); | 
| 406 |  | -        let Some(datafd) = fds.next() else { | 
| 407 |  | -            return Err(Error::Other("Expected data fd for DualFds".into())); | 
| 408 |  | -        }; | 
| 409 |  | -        let Some(errfd) = fds.next() else { | 
| 410 |  | -            return Err(Error::Other("Expected err fd for DualFds".into())); | 
| 411 |  | -        }; | 
| 412 |  | -        if fds.next().is_some() { | 
| 413 |  | -            return Err(Error::Other("More than two fds for DualFds".into())); | 
| 414 |  | -        } | 
| 415 | 400 |         if pipeid != 0 { | 
| 416 | 401 |             return Err(Error::Other("Unexpected pipeid with DualFds".into())); | 
| 417 | 402 |         } | 
|  | 403 | +        let [datafd, errfd] = fds | 
|  | 404 | +            .into_iter() | 
|  | 405 | +            .collect_array() | 
|  | 406 | +            .ok_or_else(|| Error::Other("Expected two fds for DualFds".into()))?; | 
| 418 | 407 |         Ok(Self { datafd, errfd }) | 
| 419 | 408 |     } | 
| 420 | 409 | } | 
| @@ -962,7 +951,7 @@ mod tests { | 
| 962 | 951 |         match DualFds::from_reply(fds, 0) { | 
| 963 | 952 |             Ok(v) => unreachable!("{v:?}"), | 
| 964 | 953 |             Err(Error::Other(msg)) => { | 
| 965 |  | -                assert_eq!(msg.as_ref(), "More than two fds for DualFds") | 
|  | 954 | +                assert_eq!(msg.as_ref(), "Expected two fds for DualFds") | 
| 966 | 955 |             } | 
| 967 | 956 |             Err(other) => unreachable!("{other}"), | 
| 968 | 957 |         } | 
| @@ -998,7 +987,7 @@ mod tests { | 
| 998 | 987 |         match FinishPipe::from_reply(fds, 1) { | 
| 999 | 988 |             Ok(v) => unreachable!("{v:?}"), | 
| 1000 | 989 |             Err(Error::Other(msg)) => { | 
| 1001 |  | -                assert_eq!(msg.as_ref(), "Expected fd for FinishPipe") | 
|  | 990 | +                assert_eq!(msg.as_ref(), "Expected exactly one fd for FinishPipe") | 
| 1002 | 991 |             } | 
| 1003 | 992 |             Err(other) => unreachable!("{other}"), | 
| 1004 | 993 |         } | 
|  | 
0 commit comments