fix(find): Fallback to fd if fdfind is not found

This commit is contained in:
nedia 2021-10-29 15:35:20 +13:00 • committed by Michael Aaron Murphy
parent f26f67f347
commit 857acd1ed8
2 changed files with 26 additions and 18 deletions

6
Cargo.lock generated
View file

@ -1381,7 +1381,7 @@ checksum = "bb20dcc30536a1508e75d47dd0e399bb2fe7354dcf35cda9127f2bf1ed92e30e"
[[package]] [[package]]
name = "pop-launcher" name = "pop-launcher"
version = "1.0.1" version = "1.0.2"
dependencies = [ dependencies = [
"blocking", "blocking",
"const_format", "const_format",
@ -1404,7 +1404,7 @@ dependencies = [
[[package]] [[package]]
name = "pop-launcher-plugins" name = "pop-launcher-plugins"
version = "1.0.1" version = "1.0.2"
dependencies = [ dependencies = [
"async-pidfd", "async-pidfd",
"fork", "fork",
@ -1435,7 +1435,7 @@ dependencies = [
[[package]] [[package]]
name = "pop-launcher-service" name = "pop-launcher-service"
version = "1.0.1" version = "1.0.2"
dependencies = [ dependencies = [
"anyhow", "anyhow",
"async-io", "async-io",

View file

@ -207,21 +207,29 @@ impl SearchContext {
} }
} }
/// Submits the search query to `fdfind`, and returns its stdout pipe. /// Submits the search query to `fdfind`, and returns its stdout pipe. Falls
/// back to fdfind if it cannot be spawned.
async fn query(arg: &str) -> io::Result<(Child, ChildStdout)> { async fn query(arg: &str) -> io::Result<(Child, ChildStdout)> {
let mut child = Command::new("fdfind") // Closure to spawn the process
.arg("-i") let spawn = |cmd: &str| -> io::Result<Child> {
.arg(arg) Command::new(cmd)
.stdin(Stdio::null()) .arg("-i")
.stdout(Stdio::piped()) .arg(arg)
.stderr(Stdio::null()) .stdin(Stdio::null())
.spawn()?; .stdout(Stdio::piped())
.stderr(Stdio::null())
.spawn()
};
match child.stdout.take() { // Try fdfind first, then fall back to fd
Some(stdout) => Ok((child, stdout)), let mut child = match spawn("fdfind") {
None => Err(io::Error::new( Err(why) if why.kind() == io::ErrorKind::NotFound => spawn("fd"),
io::ErrorKind::BrokenPipe, result => result,
"stdout pipe is missing", }?;
)),
} child
.stdout
.take()
.map(move |stdout| (child, stdout))
.ok_or_else(|| io::Error::new(io::ErrorKind::BrokenPipe, "stdout pipe is missing"))
} }