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]]
name = "pop-launcher"
version = "1.0.1"
version = "1.0.2"
dependencies = [
"blocking",
"const_format",
@ -1404,7 +1404,7 @@ dependencies = [
[[package]]
name = "pop-launcher-plugins"
version = "1.0.1"
version = "1.0.2"
dependencies = [
"async-pidfd",
"fork",
@ -1435,7 +1435,7 @@ dependencies = [
[[package]]
name = "pop-launcher-service"
version = "1.0.1"
version = "1.0.2"
dependencies = [
"anyhow",
"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)> {
let mut child = Command::new("fdfind")
.arg("-i")
.arg(arg)
.stdin(Stdio::null())
.stdout(Stdio::piped())
.stderr(Stdio::null())
.spawn()?;
// Closure to spawn the process
let spawn = |cmd: &str| -> io::Result<Child> {
Command::new(cmd)
.arg("-i")
.arg(arg)
.stdin(Stdio::null())
.stdout(Stdio::piped())
.stderr(Stdio::null())
.spawn()
};
match child.stdout.take() {
Some(stdout) => Ok((child, stdout)),
None => Err(io::Error::new(
io::ErrorKind::BrokenPipe,
"stdout pipe is missing",
)),
}
// Try fdfind first, then fall back to fd
let mut child = match spawn("fdfind") {
Err(why) if why.kind() == io::ErrorKind::NotFound => spawn("fd"),
result => result,
}?;
child
.stdout
.take()
.map(move |stdout| (child, stdout))
.ok_or_else(|| io::Error::new(io::ErrorKind::BrokenPipe, "stdout pipe is missing"))
}