mirror of
https://github.com/gitui-org/gitui
synced 2026-05-24 01:18:21 +00:00
fix: avoid panic when filesystem watcher hits permission errors
Log and disable notify-based updates instead of panicking when the watcher cannot be created or cannot recurse into permission-denied directories (e.g. podman-owned folders with --watcher). Fixes #2900 Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
parent
8619c07f3f
commit
d22616dff0
1 changed files with 32 additions and 12 deletions
|
|
@ -49,15 +49,20 @@ impl RepoWatcher {
|
||||||
loop {
|
loop {
|
||||||
let ev = receiver.recv()?;
|
let ev = receiver.recv()?;
|
||||||
|
|
||||||
if let Ok(ev) = ev {
|
match ev {
|
||||||
log::debug!("notify events: {}", ev.len());
|
Ok(events) => {
|
||||||
|
log::debug!("notify events: {}", events.len());
|
||||||
|
|
||||||
for (idx, ev) in ev.iter().enumerate() {
|
for (idx, event) in events.iter().enumerate() {
|
||||||
log::debug!("notify [{idx}]: {ev:?}");
|
log::debug!("notify [{idx}]: {event:?}");
|
||||||
|
}
|
||||||
|
|
||||||
|
if !events.is_empty() {
|
||||||
|
sender.send(())?;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Err(e) => {
|
||||||
if !ev.is_empty() {
|
log::warn!("notify debouncer error: {e}");
|
||||||
sender.send(())?;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -71,12 +76,27 @@ fn create_watcher(
|
||||||
) {
|
) {
|
||||||
scope_time!("create_watcher");
|
scope_time!("create_watcher");
|
||||||
|
|
||||||
let mut bouncer =
|
let mut bouncer = match new_debouncer(timeout, tx) {
|
||||||
new_debouncer(timeout, tx).expect("Watch create error");
|
Ok(bouncer) => bouncer,
|
||||||
bouncer
|
Err(e) => {
|
||||||
|
log::warn!(
|
||||||
|
"failed to create filesystem watcher: {e}; \
|
||||||
|
file change notifications disabled"
|
||||||
|
);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
if let Err(e) = bouncer
|
||||||
.watcher()
|
.watcher()
|
||||||
.watch(Path::new(&workdir), RecursiveMode::Recursive)
|
.watch(Path::new(workdir), RecursiveMode::Recursive)
|
||||||
.expect("Watch error");
|
{
|
||||||
|
log::warn!(
|
||||||
|
"failed to watch repository for changes ({e}); \
|
||||||
|
file change notifications disabled"
|
||||||
|
);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
std::mem::forget(bouncer);
|
std::mem::forget(bouncer);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue