* Get mtimeMs from an added file every 3 seconds until it is no longer changing * Times out after 600s * * @param {string} path * @param {number} [lastMTimeMs=0] * @param {number} [loop=0]
(path, lastMTimeMs = 0, loop = 0)
| 237 | * @param {number} [loop=0] |
| 238 | */ |
| 239 | async waitForFileToAdd(path, lastMTimeMs = 0, loop = 0) { |
| 240 | // Safety to catch infinite loop (600s) |
| 241 | if (loop >= 200) { |
| 242 | Logger.warn(`[Watcher] Waiting to add file at "${path}" timeout (loop ${loop}) - bailing`) |
| 243 | this.pendingFileUpdates = this.pendingFileUpdates.filter((pfu) => pfu.path !== path) |
| 244 | return this.filesBeingAdded.delete(path) |
| 245 | } |
| 246 | |
| 247 | const mtimeMs = await getFileMTimeMs(path) |
| 248 | if (mtimeMs === lastMTimeMs) { |
| 249 | if (lastMTimeMs) Logger.debug(`[Watcher] File finished adding at "${path}"`) |
| 250 | return this.filesBeingAdded.delete(path) |
| 251 | } |
| 252 | if (loop % 5 === 0) { |
| 253 | Logger.debug(`[Watcher] Waiting to add file at "${path}". mtimeMs=${mtimeMs} lastMTimeMs=${lastMTimeMs} (loop ${loop})`) |
| 254 | } |
| 255 | // Wait 3 seconds |
| 256 | await new Promise((resolve) => setTimeout(resolve, 3000)) |
| 257 | this.waitForFileToAdd(path, mtimeMs, ++loop) |
| 258 | } |
| 259 | |
| 260 | /** |
| 261 | * Queue file update |
no test coverage detected