Skip to content

Commit b2ca851

Browse files
committed
avoid usage of syscalls like pidfd_open which dont work well on iSH
1 parent 582d217 commit b2ca851

2 files changed

Lines changed: 27 additions & 17 deletions

File tree

src/sync.rs

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -29,33 +29,38 @@ async fn pull_loop(workspace: PathBuf, db: Arc<BrainDb>, interval_secs: u64) {
2929
tokio::time::sleep(interval).await;
3030

3131
let ws = workspace.clone();
32-
match tokio::process::Command::new("git")
33-
.args(["pull", "--rebase", "origin", "main"])
34-
.current_dir(&ws)
35-
.output()
36-
.await
37-
{
38-
Ok(out) if out.status.success() => {
32+
let output_res = tokio::task::spawn_blocking(move || {
33+
std::process::Command::new("git")
34+
.args(["pull", "--rebase", "origin", "main"])
35+
.current_dir(&ws)
36+
.output()
37+
})
38+
.await;
39+
40+
match output_res {
41+
Ok(Ok(out)) if out.status.success() => {
3942
let stdout = String::from_utf8_lossy(&out.stdout);
4043
eprintln!("git pull: ok — {}", stdout.trim());
4144

45+
let ws_reindex = workspace.clone();
4246
// Re-index vault so FTS5 reflects any new notes from PC.
4347
let idx = indexer.clone();
44-
match tokio::task::spawn_blocking(move || idx.scan(&ws)).await {
48+
match tokio::task::spawn_blocking(move || idx.scan(&ws_reindex)).await {
4549
Ok(Ok(stats)) => eprintln!("vault re-index: {stats}"),
4650
Ok(Err(e)) => eprintln!("vault re-index warning: {e}"),
4751
Err(e) => eprintln!("vault re-index task error: {e}"),
4852
}
4953
}
50-
Ok(out) => {
54+
Ok(Ok(out)) => {
5155
let stderr = String::from_utf8_lossy(&out.stderr);
5256
eprintln!(
5357
"git pull: non-zero exit ({}): {}",
5458
out.status,
5559
stderr.trim()
5660
);
5761
}
58-
Err(e) => eprintln!("git pull: failed to spawn: {e}"),
62+
Ok(Err(e)) => eprintln!("git pull: failed to spawn: {e}"),
63+
Err(e) => eprintln!("git pull: task panicked: {e}"),
5964
}
6065
}
6166
}

src/tools/git.rs

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
use std::process::Output;
1313

1414
use serde_json::Value;
15-
use tokio::process::Command;
1615

1716
use crate::tools::context::ToolCtx;
1817
use crate::tools::registry::{BoxFuture, Tool};
@@ -89,12 +88,18 @@ impl Tool for GitSyncTool {
8988
}
9089

9190
async fn run_git(workspace: &std::path::Path, args: &[&str]) -> Result<Output, String> {
92-
Command::new("git")
93-
.args(args)
94-
.current_dir(workspace)
95-
.output()
96-
.await
97-
.map_err(|e| e.to_string())
91+
let workspace = workspace.to_path_buf();
92+
let args: Vec<String> = args.iter().map(|s| s.to_string()).collect();
93+
94+
tokio::task::spawn_blocking(move || {
95+
std::process::Command::new("git")
96+
.args(&args)
97+
.current_dir(&workspace)
98+
.output()
99+
})
100+
.await
101+
.map_err(|e| e.to_string())?
102+
.map_err(|e| e.to_string())
98103
}
99104

100105
fn append_output(log: &mut String, label: &str, out: &Output) {

0 commit comments

Comments
 (0)