fix(find): Hang due to not resetting active status on finished

This commit is contained in:
Michael Aaron Murphy 2021-08-18 14:14:18 +02:00
parent 878e31f30c
commit 106804ec27
2 changed files with 9 additions and 6 deletions

View file

@ -180,7 +180,7 @@ impl App {
.await; .await;
if id == 19 { if id == 19 {
break break;
} }
} }

View file

@ -2,7 +2,7 @@ use futures_lite::*;
use pop_launcher::*; use pop_launcher::*;
use postage::mpsc; use postage::mpsc;
use postage::prelude::{Sink, Stream}; use postage::prelude::{Sink, Stream};
use smol::process::{ChildStdout, Command, Stdio}; use smol::process::{Child, ChildStdout, Command, Stdio};
use std::borrow::Cow; use std::borrow::Cow;
use std::cell::Cell; use std::cell::Cell;
use std::io; use std::io;
@ -148,8 +148,8 @@ impl SearchContext {
async fn search(&mut self, search: String) { async fn search(&mut self, search: String) {
tracing::debug!("searching for {}", search); tracing::debug!("searching for {}", search);
let mut stdout = match query(&search).await { let (mut child, mut stdout) = match query(&search).await {
Ok(stdout) => futures_lite::io::BufReader::new(stdout).lines(), Ok((child, stdout)) => (child, futures_lite::io::BufReader::new(stdout).lines()),
Err(why) => { Err(why) => {
tracing::error!("failed to spawn fdfind process: {}", why); tracing::error!("failed to spawn fdfind process: {}", why);
self.active.set(false); self.active.set(false);
@ -189,11 +189,14 @@ impl SearchContext {
} }
crate::send(&mut self.out, PluginResponse::Finished).await; crate::send(&mut self.out, PluginResponse::Finished).await;
self.active.set(false);
let _ = child.kill();
let _ = child.status().await;
} }
} }
/// Submits the search query to `fdfind`, and returns its stdout pipe. /// Submits the search query to `fdfind`, and returns its stdout pipe.
async fn query(arg: &str) -> io::Result<ChildStdout> { async fn query(arg: &str) -> io::Result<(Child, ChildStdout)> {
let mut child = Command::new("fdfind") let mut child = Command::new("fdfind")
.arg(arg) .arg(arg)
.stdin(Stdio::null()) .stdin(Stdio::null())
@ -202,7 +205,7 @@ async fn query(arg: &str) -> io::Result<ChildStdout> {
.spawn()?; .spawn()?;
match child.stdout.take() { match child.stdout.take() {
Some(stdout) => Ok(stdout), Some(stdout) => Ok((child, stdout)),
None => Err(io::Error::new( None => Err(io::Error::new(
io::ErrorKind::BrokenPipe, io::ErrorKind::BrokenPipe,
"stdout pipe is missing", "stdout pipe is missing",