Skip to content

Commit

Permalink
fix: solve the lock due to promise returned in a promise
Browse files Browse the repository at this point in the history
when scanDir was called, it was returning a promise thant calls scanFiles. But scanFiles returns a promise also. Solved by awaiting the return of scanFiles call and resolving correctly the promise of scanDir.
  • Loading branch information
Annubis45 authored and kylefarris committed Mar 8, 2022
1 parent 42236a9 commit dfbafbf
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -1981,7 +1981,10 @@ class NodeClam {
.trim()
.split(os.EOL)
.map((p) => p.replace(/ /g, '\\ ').trim());
return this.scanFiles(files, endCb, fileCb);
const { goodFiles, badFiles, viruses, errors } = await this.scanFiles(files, null, null);
return hasCb
? endCb(null, goodFiles, badFiles, viruses)
: resolve({ goodFiles, badFiles, viruses, errors });
} catch (e) {
const err = new NodeClamError({ path, err: e }, 'There was an issue scanning the path specified!');
return hasCb ? endCb(err, [], []) : reject(err);
Expand All @@ -1991,7 +1994,10 @@ class NodeClam {
else if (this.settings.scanRecursively === false && this.scanner === 'clamdscan') {
try {
const allFiles = (await fsReaddir(path)).filter(async (file) => (await fsStat(file)).isFile());
return this.scanFiles(allFiles, endCb, fileCb);
const { goodFiles, badFiles, viruses, errors } = await this.scanFiles(allFiles, null, null);
return hasCb
? endCb(null, goodFiles, badFiles, viruses)
: resolve({ goodFiles, badFiles, viruses, errors });
} catch (e) {
const err = new NodeClamError(
{ path, err: e },
Expand Down

0 comments on commit dfbafbf

Please sign in to comment.