fix(find): Fallback to fd if fdfind is not found
This commit is contained in:
parent
f26f67f347
commit
857acd1ed8
2 changed files with 26 additions and 18 deletions
6
Cargo.lock
generated
6
Cargo.lock
generated
|
|
@ -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",
|
||||
|
|
|
|||
|
|
@ -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"))
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue