(directoryPath, maxFileSize, enableZipArchives = false, scanExtensions = null)
| 215 | try { |
| 216 | const fileHash = hash.digest('hex'); |
| 217 | resolve(fileHash); |
| 218 | } catch (err) { |
| 219 | console.error(`Error generating final hash for file: ${filePath}`, err); |
| 220 | reject(err); |
| 221 | } |
| 222 | }); |
| 223 | }); |
| 224 | } |
| 225 | |
| 226 | async function scanDirectory(directoryPath, maxFileSize, enableZipArchives = false, scanExtensions = null) { |
| 227 | const files = []; |
| 228 | /** Every file-type dirent seen while walking the tree (matches legacy totalFiles meaning). */ |
| 229 | let traversedFileEntries = 0; |
| 230 | const extSet = buildScanExtensionSet(scanExtensions); |
| 231 | |
| 232 | const shouldQueueFile = (fileName) => { |
| 233 | // Skip Printventory zip-extract temps if they somehow land under a scanned tree |
| 234 | if (typeof fileName === 'string' && fileName.startsWith('printventory_')) return false; |
| 235 | const ext = path.extname(fileName).toLowerCase(); |
| 236 | if (extSet.has(ext)) return true; |
| 237 | if (enableZipArchives && ext === '.zip') return true; |
| 238 | return false; |
| 239 | }; |
| 240 | |
| 241 | // Throttle progress IPC: walking huge folders is sync; avoid flooding the main process. |
| 242 | const TRAVERSE_PROGRESS_INTERVAL = isDockerContainer() ? 2000 : 1000; |
| 243 | |
| 244 | const reportTraversedFile = () => { |
| 245 | traversedFileEntries++; |
| 246 | if (traversedFileEntries % TRAVERSE_PROGRESS_INTERVAL === 0) { |
| 247 | parentPort.postMessage({ |
| 248 | type: 'progress', |
| 249 | processed: traversedFileEntries |
| 250 | }); |
| 251 | } |
| 252 | }; |
| 253 | |
| 254 | // Use a simple queue system |
| 255 | const queue = [{ type: 'dir', path: directoryPath }]; |
| 256 | const seenDirs = new Set(); |
| 257 | let activeOps = 0; |
| 258 | |
| 259 | // Promise to signal completion |
| 260 | let resolveDone; |
| 261 | const donePromise = new Promise(resolve => { resolveDone = resolve; }); |
| 262 | |
| 263 | const processNext = () => { |
| 264 | // If no active ops and queue is empty, we are done |
| 265 | if (activeOps === 0 && queue.length === 0) { |
| 266 | if (traversedFileEntries > 0) { |
| 267 | parentPort.postMessage({ |
| 268 | type: 'progress', |
| 269 | processed: traversedFileEntries |
| 270 | }); |
| 271 | } |
| 272 | resolveDone({ files, totalFiles: traversedFileEntries }); |
| 273 | return; |
| 274 | } |
no test coverage detected