* Polls directory children for changes, detecting new and deleted files.
()
| 152 | * Polls directory children for changes, detecting new and deleted files. |
| 153 | */ |
| 154 | #pollDirectory() { |
| 155 | // Rescan for new files |
| 156 | if (this.#recursive) { |
| 157 | this.#rescanRecursive(this.#path, ''); |
| 158 | } else { |
| 159 | this.#rescanChildren(this.#path); |
| 160 | } |
| 161 | |
| 162 | // Check tracked files for changes/deletions |
| 163 | for (const { 0: filePath, 1: info } of this.#trackedFiles) { |
| 164 | const newStats = this.#getStatsFor(filePath); |
| 165 | if (newStats === null && info.stats !== null) { |
| 166 | // File was deleted |
| 167 | this.emit('change', 'rename', this.#encodeFilename(info.relativePath)); |
| 168 | this.#trackedFiles.delete(filePath); |
| 169 | } else if (this.#statsChanged(info.stats, newStats)) { |
| 170 | const eventType = this.#determineEventType(info.stats, newStats); |
| 171 | this.emit('change', eventType, this.#encodeFilename(info.relativePath)); |
| 172 | info.stats = newStats; |
| 173 | } |
| 174 | } |
| 175 | } |
| 176 | |
| 177 | /** |
| 178 | * Rescans direct children for new entries. |
no test coverage detected