Skip to content

Commit

Permalink
refactor for readability
Browse files Browse the repository at this point in the history
  • Loading branch information
csmig committed Jun 11, 2024
1 parent b6a4535 commit 43beb6f
Showing 1 changed file with 26 additions and 28 deletions.
54 changes: 26 additions & 28 deletions lib/scan.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,37 +32,35 @@ async function startScanner() {
const discoveredFiles = new Set() // in memory set of files discovered in the current scan

try {
//if the parseQueue and cargoQueue are empty, start a scan
if (parseQueue.length == 0 && cargoQueue.length == 0) {
logger.info({ component, message: `queue empty, starting scan` })
//if the parseQueue and cargoQueue are not empty, skip the scan
if (parseQueue.length || cargoQueue.length) {
logger.info({ component, message: `scan skipped, queues not empty`, parseQueueSize: parseQueue.length, cargoQueueSize: cargoQueue.length })
return
}
// scan the path for files
const stream = fg.stream([`${options.path}/**/*.ckl`, `${options.path}/**/*.xml`, `${options.path}/**/*.cklb`], {
dot: !options.ignoreDot,
suppressErrors: true,
ignore: options.ignoreGlob ?? []
})
logger.info({ component, message: `scan started`, path: options.path })
// for each file discovered
for await (const entry of stream) {
discoveredFiles.add(entry)
logger.verbose({ component, message: `discovered file`, file: entry })
// check if the file is in the history
if (historySet.has(entry)) {
logger.verbose({component, message: `history match`, file: entry})
}
// if the file is not in the history, add it to the in memory history set.
else {
parseQueue.push(entry)
logger.info({component, message: `queued for parsing`, file: entry})
}
const stream = fg.stream([`${options.path}/**/*.ckl`, `${options.path}/**/*.xml`, `${options.path}/**/*.cklb`], {
dot: !options.ignoreDot,
suppressErrors: true,
ignore: options.ignoreGlob ?? []
})
logger.info({ component, message: `scan started`, path: options.path })
// for each file discovered
for await (const entry of stream) {
discoveredFiles.add(entry)
logger.verbose({ component, message: `discovered file`, file: entry })
// check if the file is in the history
if (historySet.has(entry)) {
logger.verbose({component, message: `history match`, file: entry})
}
// if the file is not in the history, add it to the in memory history set.
else {
parseQueue.push(entry)
logger.info({component, message: `queued for parsing`, file: entry})
}
//Remove stale files: those in historySet but not found in the current scan
removeStaleFiles(discoveredFiles)
logger.info({ component, message: `scan ended`, path: options.path })
}
else {
logger.info({ component, message: `scan skipped, queue not empty. parseQueue: ${parseQueue.length} cargoQueue: ${cargoQueue.length}` })
}
//Remove stale files: those in historySet but not found in the current scan
removeStaleFiles(discoveredFiles)
logger.info({ component, message: `scan ended`, path: options.path })
}
catch (e) {
logger.error({ component, error: serializeError(e) })
Expand Down

0 comments on commit 43beb6f

Please sign in to comment.