mirror of
https://gitee.com/zhangsken/opencode.git
synced 2026-10-16 10:30:01 +08:00
fix(tui): handle storage watcher errors after startup (#51243)
Co-authored-by: rekram1-node <rekram1-node@users.noreply.github.com>
This commit is contained in:
committed by
GitHub
parent
8061220b08
commit
85b98e7da4
@@ -110,14 +110,20 @@ export function createStorage(root: string, channel: string) {
|
||||
},
|
||||
}
|
||||
|
||||
let reload: ReturnType<typeof setTimeout> | undefined
|
||||
let reloadTimer: ReturnType<typeof setTimeout> | undefined
|
||||
let watcher: ReturnType<typeof watch> | undefined
|
||||
try {
|
||||
watcher = watch(directory, () => {
|
||||
clearTimeout(reload)
|
||||
clearTimeout(reloadTimer)
|
||||
// Atomic writes notify for the temporary file before its final rename, and some
|
||||
// platforms coalesce the rename event. Reload after the event burst has settled.
|
||||
reload = setTimeout(() => entries.forEach((entry) => entry.reload()), 50)
|
||||
reloadTimer = setTimeout(() => entries.forEach((entry) => entry.reload()), 50)
|
||||
})
|
||||
watcher.on("error", (error) => {
|
||||
clearTimeout(reloadTimer)
|
||||
watcher?.close()
|
||||
watcher = undefined
|
||||
console.error("Storage directory watcher failed, live-reload disabled", { directory, error })
|
||||
})
|
||||
} catch (error) {
|
||||
// fs.watch throws synchronously (e.g. ENOSPC when the inotify watch limit is
|
||||
@@ -128,7 +134,7 @@ export function createStorage(root: string, channel: string) {
|
||||
return {
|
||||
storage,
|
||||
close: () => {
|
||||
clearTimeout(reload)
|
||||
clearTimeout(reloadTimer)
|
||||
watcher?.close()
|
||||
},
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user