Handle ctrl-c in RawStream iterator (#7314)

Fixes #7246 and #1898.

Darren noticed that `open /dev/random` could not be interrupted by
`ctrl+c`. Thankfully the solution was very simple; it looks like we just
forgot to check `ctrlc` in the `impl Iterator for RawStream`!

To reproduce this, just run `open /dev/random` and then cancel it with
`ctrl+c`.
This commit is contained in:
Reilly Wood 2022-12-02 08:00:56 -08:00 committed by GitHub
parent bc0c9ab698
commit 3ac36879e0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -77,6 +77,12 @@ impl Iterator for RawStream {
type Item = Result<Value, ShellError>;
fn next(&mut self) -> Option<Self::Item> {
if let Some(ctrlc) = &self.ctrlc {
if ctrlc.load(Ordering::SeqCst) {
return None;
}
}
// If we know we're already binary, just output that
if self.is_binary {
match self.stream.next() {