Skip to content

Commit 064efe2

Browse files
committed
fix: tray menu run watcher reports garbage timestamps and garbage entries
- re: garbage timestamps, we are not setting `alwaysStat=true`. by default, chokidar only reports file stats for the initial scan - re: garbage entries, sigh. i can't figure out how to configure chokidar to show only top-level directory entries, of the specified watch directory; this PR has some fixes for that, but not ideal ones.
1 parent 6687a6c commit 064efe2

File tree

1 file changed

+14
-6
lines changed
  • plugins/plugin-codeflare/src/tray/watchers/profile

1 file changed

+14
-6
lines changed

plugins/plugin-codeflare/src/tray/watchers/profile/run.ts

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ export default class ProfileRunWatcher {
3838
public constructor(
3939
private readonly updateFn: UpdateFunction,
4040
private readonly profile: string,
41-
private readonly watcher = chokidar.watch(ProfileRunWatcher.path(profile) + "/*", { depth: 1 })
41+
private readonly watcher = chokidar.watch(ProfileRunWatcher.path(profile) + "/*", { depth: 1, alwaysStat: true })
4242
) {
4343
// we need to close the chokidar watcher before exit, otherwise
4444
// electron-main dies with SIGABRT
@@ -65,12 +65,20 @@ export default class ProfileRunWatcher {
6565
/** Initialize the filesystem watcher to notify us of new or removed profiles */
6666
private initWatcher() {
6767
this.watcher.on("addDir", async (path, stats) => {
68-
const runId = basename(path)
69-
const idx = this.runs.findIndex((_) => _.runId === runId)
70-
if (idx < 0) {
71-
this._runs.push({ runId, timestamp: stats?.mtimeMs || stats?.ctimeMs || 0 })
72-
this.updateFn()
68+
if (!stats) {
69+
// hmm, not sure why this would ever happen, since we specified `alwaysStat: true`, but to make typescript happy
70+
return
71+
} else if (path.replace(ProfileRunWatcher.path(this.profile) + "/", "").indexOf("/") >= 0) {
72+
// sigh. @starpit can't figure out how to get chokidar to
73+
// ignore subdirectories; i've tried `depth` and it doesn't
74+
// seem to do anything; maybe we could use an `ignored` option
75+
// instead of doing it here...
76+
return
7377
}
78+
79+
const runId = basename(path)
80+
this._runs.push({ runId, timestamp: stats.mtimeMs })
81+
this.updateFn()
7482
})
7583

7684
this.watcher.on("unlink", (path) => {

0 commit comments

Comments
 (0)