4
4
*/
5
5
6
6
/*
7
- Watch A DIRECTORY for changes. Use ./watcher.ts for a single file.
8
-
7
+ Watch A DIRECTORY for changes of the files in *that* directory only (not recursive).
8
+ Use ./watcher.ts for a single file.
9
9
10
10
Slightly generalized fs.watch that works even when the directory doesn't exist,
11
11
but also doesn't provide any information about what changed.
@@ -54,7 +54,7 @@ const logger = getLogger("backend:path-watcher");
54
54
const POLLING = true ;
55
55
56
56
const DEFAULT_POLL_MS = parseInt (
57
- process . env . COCALC_FS_WATCHER_POLL_INTERVAL_MS ?? "1500 " ,
57
+ process . env . COCALC_FS_WATCHER_POLL_INTERVAL_MS ?? "3000 " ,
58
58
) ;
59
59
60
60
const ChokidarOpts : WatchOptions = {
@@ -79,17 +79,13 @@ export class Watcher extends EventEmitter {
79
79
private exists : boolean ;
80
80
private watchContents ?: FSWatcher ;
81
81
private watchExistence ?: FSWatcher ;
82
- private interval_ms : number ;
83
82
private debounce_ms : number ;
84
83
private debouncedChange : any ;
85
84
private log : Function ;
86
85
87
86
constructor (
88
87
path : string ,
89
- {
90
- debounce : debounce_ms = 0 ,
91
- interval : interval_ms ,
92
- } : { debounce ?: number ; interval ?: number } = { } ,
88
+ { debounce : debounce_ms = DEFAULT_POLL_MS } : { debounce ?: number } = { } ,
93
89
) {
94
90
super ( ) ;
95
91
this . log = logger . extend ( path ) . debug ;
@@ -99,7 +95,6 @@ export class Watcher extends EventEmitter {
99
95
}
100
96
this . path = path . startsWith ( "/" ) ? path : join ( process . env . HOME , path ) ;
101
97
this . debounce_ms = debounce_ms ;
102
- this . interval_ms = interval_ms ?? DEFAULT_POLL_MS ;
103
98
this . debouncedChange = this . debounce_ms
104
99
? debounce ( this . change , this . debounce_ms , {
105
100
leading : true ,
@@ -122,16 +117,8 @@ export class Watcher extends EventEmitter {
122
117
}
123
118
}
124
119
125
- private chokidarOptions = ( ) => {
126
- return {
127
- ...ChokidarOpts ,
128
- interval : this . interval_ms ,
129
- binaryInterval : this . interval_ms ,
130
- } ;
131
- } ;
132
-
133
120
private initWatchContents ( ) : void {
134
- this . watchContents = watch ( this . path , this . chokidarOptions ( ) ) ;
121
+ this . watchContents = watch ( this . path , ChokidarOpts ) ;
135
122
this . watchContents . on ( "all" , this . debouncedChange ) ;
136
123
this . watchContents . on ( "error" , ( err ) => {
137
124
this . log ( `error watching listings -- ${ err } ` ) ;
@@ -140,7 +127,7 @@ export class Watcher extends EventEmitter {
140
127
141
128
private async initWatchExistence ( ) : Promise < void > {
142
129
const containing_path = path_split ( this . path ) . head ;
143
- this . watchExistence = watch ( containing_path , this . chokidarOptions ( ) ) ;
130
+ this . watchExistence = watch ( containing_path , ChokidarOpts ) ;
144
131
this . watchExistence . on ( "all" , this . watchExistenceChange ( containing_path ) ) ;
145
132
this . watchExistence . on ( "error" , ( err ) => {
146
133
this . log ( `error watching for existence of ${ this . path } -- ${ err } ` ) ;
0 commit comments