scanoss 0.2.20 → 0.2.23
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.cspell.json +3 -1
- package/build/main/bin/cli-bin.js +3 -3
- package/build/main/commands/scan.js +4 -5
- package/build/main/index.d.ts +2 -0
- package/build/main/index.js +3 -1
- package/build/main/lib/dependencies/DependencyScanner.js +5 -3
- package/build/main/lib/dependencies/LocalDependency/DependencyTypes.d.ts +1 -1
- package/build/main/lib/dependencies/LocalDependency/parsers/npmParser.js +3 -3
- package/build/main/lib/dependencies/LocalDependency/parsers/pyParser.js +7 -3
- package/build/main/lib/grpc/GrpcDependencyService.d.ts +4 -3
- package/build/main/lib/grpc/GrpcDependencyService.js +6 -2
- package/build/main/lib/scanner/Dispatcher/DispatchableItem.d.ts +4 -4
- package/build/main/lib/scanner/Dispatcher/DispatchableItem.js +5 -5
- package/build/main/lib/scanner/Scanner.d.ts +17 -19
- package/build/main/lib/scanner/Scanner.js +44 -33
- package/build/main/lib/scanner/ScannerCfg.js +2 -2
- package/build/main/lib/scanner/ScannerTypes.d.ts +1 -0
- package/build/main/lib/scanner/ScannerTypes.js +1 -1
- package/build/main/lib/scanner/WfpProvider/FingerprintPacket.d.ts +11 -0
- package/build/main/lib/scanner/WfpProvider/FingerprintPacket.js +32 -0
- package/build/main/lib/scanner/WfpProvider/WfpCalculator/WfpCalculator.d.ts +20 -0
- package/build/main/lib/scanner/WfpProvider/WfpCalculator/WfpCalculator.js +334 -0
- package/build/main/lib/scanner/WfpProvider/WfpProvider.d.ts +32 -0
- package/build/main/lib/scanner/WfpProvider/WfpProvider.js +62 -0
- package/build/main/lib/scanner/WfpProvider/WfpSplitter/WfpSplitter.d.ts +20 -0
- package/build/main/lib/scanner/WfpProvider/WfpSplitter/WfpSplitter.js +96 -0
- package/build/main/lib/scanner/Winnower/WinnowerExtractor.js +1 -1
- package/build/module/bin/cli-bin.js +3 -3
- package/build/module/commands/scan.js +4 -5
- package/build/module/index.d.ts +2 -0
- package/build/module/index.js +3 -1
- package/build/module/lib/dependencies/DependencyScanner.js +5 -3
- package/build/module/lib/dependencies/LocalDependency/DependencyTypes.d.ts +1 -1
- package/build/module/lib/dependencies/LocalDependency/parsers/npmParser.js +3 -3
- package/build/module/lib/dependencies/LocalDependency/parsers/pyParser.js +7 -3
- package/build/module/lib/grpc/GrpcDependencyService.d.ts +4 -3
- package/build/module/lib/grpc/GrpcDependencyService.js +7 -2
- package/build/module/lib/scanner/Dispatcher/DispatchableItem.d.ts +4 -4
- package/build/module/lib/scanner/Dispatcher/DispatchableItem.js +6 -6
- package/build/module/lib/scanner/Scanner.d.ts +17 -19
- package/build/module/lib/scanner/Scanner.js +50 -39
- package/build/module/lib/scanner/ScannerCfg.js +2 -2
- package/build/module/lib/scanner/ScannerTypes.d.ts +1 -0
- package/build/module/lib/scanner/ScannerTypes.js +1 -1
- package/build/module/lib/scanner/WfpProvider/FingerprintPacket.d.ts +11 -0
- package/build/module/lib/scanner/WfpProvider/FingerprintPacket.js +31 -0
- package/build/module/lib/scanner/WfpProvider/WfpCalculator/WfpCalculator.d.ts +20 -0
- package/build/module/lib/scanner/WfpProvider/WfpCalculator/WfpCalculator.js +330 -0
- package/build/module/lib/scanner/WfpProvider/WfpProvider.d.ts +32 -0
- package/build/module/lib/scanner/WfpProvider/WfpProvider.js +64 -0
- package/build/module/lib/scanner/WfpProvider/WfpSplitter/WfpSplitter.d.ts +20 -0
- package/build/module/lib/scanner/WfpProvider/WfpSplitter/WfpSplitter.js +95 -0
- package/build/module/lib/scanner/Winnower/WinnowerExtractor.js +1 -1
- package/build/tsconfig.module.tsbuildinfo +1 -1
- package/build/tsconfig.tsbuildinfo +1 -1
- package/package-lock.json +19948 -0
- package/package.json +1 -1
- package/src/bin/cli-bin.ts +3 -3
- package/src/commands/scan.ts +3 -3
- package/src/index.js +1 -0
- package/src/index.ts +4 -0
- package/src/lib/dependencies/DependencyScanner.ts +4 -2
- package/src/lib/dependencies/LocalDependency/DependencyTypes.ts +1 -1
- package/src/lib/dependencies/LocalDependency/parsers/npmParser.ts +2 -2
- package/src/lib/dependencies/LocalDependency/parsers/pyParser.ts +5 -2
- package/src/lib/grpc/GrpcDependencyService.ts +9 -3
- package/src/lib/scanner/Dispatcher/DispatchableItem.ts +7 -8
- package/src/lib/scanner/Scanner.ts +64 -53
- package/src/lib/scanner/ScannerCfg.ts +2 -2
- package/src/lib/scanner/ScannerTypes.ts +1 -0
- package/src/lib/scanner/{Winnower/WinnowerResponse.ts → WfpProvider/FingerprintPacket.ts} +5 -5
- package/src/lib/scanner/{Winnower/Winnower.ts → WfpProvider/WfpCalculator/WfpCalculator.ts} +33 -119
- package/src/lib/scanner/WfpProvider/WfpProvider.ts +90 -0
- package/src/lib/scanner/WfpProvider/WfpSplitter/WfpSplitter.ts +122 -0
- package/src/lib/scanner/Winnower/WinnowerExtractor.ts +0 -1
package/package.json
CHANGED
package/src/bin/cli-bin.ts
CHANGED
|
@@ -15,13 +15,13 @@ function CLIErrorHandler(e: Error) {
|
|
|
15
15
|
|
|
16
16
|
async function main() {
|
|
17
17
|
program
|
|
18
|
-
.version("0.2.
|
|
18
|
+
.version("0.2.23")
|
|
19
19
|
.description('The SCANOSS JS package provides a simple, easy to consume module for interacting with SCANOSS APIs/Engine.')
|
|
20
20
|
|
|
21
21
|
program
|
|
22
22
|
.command('scan <source>')
|
|
23
23
|
.description('Scan a folder/file')
|
|
24
|
-
|
|
24
|
+
.option('-w, --wfp', 'Scan a .wfp file instead of a folder')
|
|
25
25
|
.option('-c, --concurrency <number>', 'Number of concurrent connections to use while scanning (optional -default 10)')
|
|
26
26
|
.option('--filter <path>', 'Loads an user defined filter (optional)')
|
|
27
27
|
.option('-o, --output <filename>', 'Output result file name (optional - default stdout)')
|
|
@@ -40,7 +40,7 @@ async function main() {
|
|
|
40
40
|
|
|
41
41
|
program
|
|
42
42
|
.command('dep <source>')
|
|
43
|
-
.description('Scan for dependencies
|
|
43
|
+
.description('Scan for dependencies')
|
|
44
44
|
.option('-o, --output <filename>', 'Output result file name (optional - default stdout)')
|
|
45
45
|
.option('-a, --grpc-host <host>', 'SCANOSS GRPC HOST (optional - default: scanoss.com)')
|
|
46
46
|
.option('-p, --grpc-port <port>', 'SCANOSS GRPC PORT (optional - default: 443)')
|
package/src/commands/scan.ts
CHANGED
|
@@ -56,7 +56,7 @@ export async function scanHandler(rootPath: string, options: any): Promise<void>
|
|
|
56
56
|
}
|
|
57
57
|
} else {
|
|
58
58
|
const winnowing = fs.readFileSync(rootPath, {encoding: 'utf-8'});
|
|
59
|
-
|
|
59
|
+
scannerInput.fileList.length = [...winnowing.matchAll(/file=/g)].length;
|
|
60
60
|
}
|
|
61
61
|
|
|
62
62
|
if (!options.verbose) {
|
|
@@ -80,8 +80,8 @@ export async function scanHandler(rootPath: string, options: any): Promise<void>
|
|
|
80
80
|
console.log(await fs.promises.readFile(resultPath, 'utf8'));
|
|
81
81
|
});
|
|
82
82
|
|
|
83
|
-
if (options.wfp)
|
|
84
|
-
|
|
83
|
+
if (options.wfp) scannerInput.wfpPath = rootPath;
|
|
84
|
+
await scanner.scan([scannerInput]);
|
|
85
85
|
|
|
86
86
|
}
|
|
87
87
|
|
package/src/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
alert("Hello world")
|
package/src/index.ts
CHANGED
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
export * from './lib/scanner/ScannerTypes';
|
|
2
2
|
export * from './lib/scanner/ScannerCfg'
|
|
3
3
|
export * from './lib/scanner/Scanner'
|
|
4
|
+
export * from './lib/dependencies/DependencyTypes';
|
|
5
|
+
export * from './lib/dependencies/DependencyScannerCfg';
|
|
4
6
|
export * from './lib/dependencies/DependencyScanner';
|
|
5
7
|
|
|
8
|
+
|
|
9
|
+
|
|
@@ -19,11 +19,12 @@ export class DependencyScanner {
|
|
|
19
19
|
|
|
20
20
|
public async scan(files: Array<string>): Promise<IDependencyResponse> {
|
|
21
21
|
const localDependencies = await this.localDependency.search(files);
|
|
22
|
-
if (localDependencies.files.length === 0) return
|
|
22
|
+
if (localDependencies.files.length === 0) return {filesList: []};
|
|
23
23
|
const request = this.buildRequest(localDependencies);
|
|
24
24
|
const grpcResponse = await this.grpcDependencyService.get(request);
|
|
25
25
|
const response = grpcResponse.toObject();
|
|
26
26
|
|
|
27
|
+
|
|
27
28
|
// Extract scope from localDependencies and add it to response
|
|
28
29
|
this.mergeScopeField(localDependencies, response);
|
|
29
30
|
return response;
|
|
@@ -33,13 +34,14 @@ export class DependencyScanner {
|
|
|
33
34
|
private buildRequest(localDependencies: ILocalDependencies): DependencyRequest {
|
|
34
35
|
try {
|
|
35
36
|
const depRequest = new DependencyRequest();
|
|
37
|
+
depRequest.setDepth(1);
|
|
36
38
|
for (const file of localDependencies.files) {
|
|
37
39
|
const fileMsg = new DependencyRequest.Files();
|
|
38
40
|
fileMsg.setFile(file.file);
|
|
39
41
|
for (const purl of file.purls) {
|
|
40
42
|
const purlMsg = new DependencyRequest.Purls();
|
|
41
43
|
purlMsg.setPurl(purl.purl);
|
|
42
|
-
purlMsg.setRequirement(purl
|
|
44
|
+
if(purl?.requirement) purlMsg.setRequirement(purl.requirement);
|
|
43
45
|
fileMsg.addPurls(purlMsg);
|
|
44
46
|
}
|
|
45
47
|
depRequest.addFiles(fileMsg);
|
|
@@ -20,12 +20,12 @@ export function packageParser(fileContent: string, filePath: string): ILocalDepe
|
|
|
20
20
|
|
|
21
21
|
for(const name of deps){
|
|
22
22
|
const purlString = new PackageURL(PURL_TYPE, undefined, name, undefined, undefined, undefined).toString();
|
|
23
|
-
results.purls.push({purl: purlString, scope: "dependencies",
|
|
23
|
+
results.purls.push({purl: purlString, scope: "dependencies", requirement: o.dependencies[name]});
|
|
24
24
|
}
|
|
25
25
|
|
|
26
26
|
for(const name of devDeps){
|
|
27
27
|
const purlString = new PackageURL(PURL_TYPE, undefined, name, undefined, undefined, undefined).toString();
|
|
28
|
-
results.purls.push({purl: purlString, scope: "devDependencies",
|
|
28
|
+
results.purls.push({purl: purlString, scope: "devDependencies", requirement: o.devDependencies[name]});
|
|
29
29
|
}
|
|
30
30
|
|
|
31
31
|
return results;
|
|
@@ -41,12 +41,15 @@ export function requirementsParser(fileContent: string, filePath: string): ILoca
|
|
|
41
41
|
else {
|
|
42
42
|
|
|
43
43
|
const dep = parseDep(line);
|
|
44
|
-
if (dep.sym
|
|
44
|
+
if (!dep.sym) {
|
|
45
|
+
const purlString = new PackageURL(PURL_TYPE, undefined, dep.name, undefined, undefined, undefined).toString();
|
|
46
|
+
results.purls.push({purl: purlString});
|
|
47
|
+
} else if (dep.sym === '==') {
|
|
45
48
|
const purlString = new PackageURL(PURL_TYPE, undefined, dep.name, dep.version, undefined, undefined).toString();
|
|
46
49
|
results.purls.push({purl: purlString});
|
|
47
50
|
} else {
|
|
48
51
|
const purlString = new PackageURL(PURL_TYPE, undefined, dep.name, undefined, undefined, undefined).toString();
|
|
49
|
-
results.purls.push({purl: purlString,
|
|
52
|
+
results.purls.push({purl: purlString, requirement: dep.sym+dep.version});
|
|
50
53
|
}
|
|
51
54
|
}
|
|
52
55
|
}
|
|
@@ -7,8 +7,14 @@ export class GrpcDependencyService {
|
|
|
7
7
|
|
|
8
8
|
private client: DependenciesClient;
|
|
9
9
|
|
|
10
|
-
|
|
10
|
+
private metadata;
|
|
11
|
+
|
|
12
|
+
constructor(endpoint: string, port: string, apiKey='') {
|
|
11
13
|
this.client = new DependenciesClient(endpoint + ':' + port, grpc.credentials.createSsl());
|
|
14
|
+
if(apiKey) {
|
|
15
|
+
this.metadata = new grpc.Metadata();
|
|
16
|
+
this.metadata.add('x-api-key', apiKey);
|
|
17
|
+
}
|
|
12
18
|
}
|
|
13
19
|
|
|
14
20
|
public async get(req: DependenciesMessages.DependencyRequest): Promise<DependenciesMessages.DependencyResponse> {
|
|
@@ -20,7 +26,7 @@ export class GrpcDependencyService {
|
|
|
20
26
|
});
|
|
21
27
|
}
|
|
22
28
|
|
|
23
|
-
public buildDependencyRequestMsg(plainObj:
|
|
29
|
+
public buildDependencyRequestMsg(plainObj: DependenciesMessages.DependencyRequest.AsObject): DependenciesMessages.DependencyRequest {
|
|
24
30
|
try {
|
|
25
31
|
const depMessage = new DependenciesMessages.DependencyRequest();
|
|
26
32
|
for (const dependency of plainObj.filesList) {
|
|
@@ -52,7 +58,7 @@ export class GrpcDependencyService {
|
|
|
52
58
|
}
|
|
53
59
|
|
|
54
60
|
|
|
55
|
-
public buildEchoRequestMsg(plainObj:
|
|
61
|
+
public buildEchoRequestMsg(plainObj: CommonMessages.EchoRequest.AsObject): CommonMessages.EchoRequest {
|
|
56
62
|
try {
|
|
57
63
|
const echoMessage = new CommonMessages.EchoRequest();
|
|
58
64
|
echoMessage.setMessage(plainObj.message);
|
|
@@ -1,12 +1,11 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
1
|
+
import { FingerprintPacket } from "../WfpProvider/FingerprintPacket";
|
|
3
2
|
export class DispatchableItem {
|
|
4
|
-
private
|
|
3
|
+
private fingerprintPacket: FingerprintPacket;
|
|
5
4
|
|
|
6
5
|
private errorCounter: number;
|
|
7
6
|
|
|
8
|
-
constructor(
|
|
9
|
-
this.
|
|
7
|
+
constructor(fingerprintPacket: FingerprintPacket) {
|
|
8
|
+
this.fingerprintPacket = fingerprintPacket;
|
|
10
9
|
this.errorCounter = 0;
|
|
11
10
|
}
|
|
12
11
|
|
|
@@ -14,12 +13,12 @@ export class DispatchableItem {
|
|
|
14
13
|
this.errorCounter += 1;
|
|
15
14
|
}
|
|
16
15
|
|
|
17
|
-
public getWinnowerResponse():
|
|
18
|
-
return this.
|
|
16
|
+
public getWinnowerResponse(): FingerprintPacket {
|
|
17
|
+
return this.fingerprintPacket;
|
|
19
18
|
}
|
|
20
19
|
|
|
21
20
|
getContent() {
|
|
22
|
-
return this.
|
|
21
|
+
return this.fingerprintPacket.getContent();
|
|
23
22
|
}
|
|
24
23
|
|
|
25
24
|
getErrorCounter() {
|
|
@@ -4,7 +4,7 @@ import EventEmitter from 'eventemitter3';
|
|
|
4
4
|
import os from 'os';
|
|
5
5
|
import fs from 'fs';
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
|
|
8
8
|
import { Dispatcher } from './Dispatcher/Dispatcher';
|
|
9
9
|
|
|
10
10
|
import { DispatchableItem } from './Dispatcher/DispatchableItem';
|
|
@@ -13,8 +13,11 @@ import { ScannerCfg } from './ScannerCfg';
|
|
|
13
13
|
import { ScannerEvents, ScannerInput } from './ScannerTypes';
|
|
14
14
|
|
|
15
15
|
import sortPaths from 'sort-paths';
|
|
16
|
-
import { WinnowerResponse } from './Winnower/WinnowerResponse';
|
|
17
16
|
|
|
17
|
+
import { WfpProvider } from './WfpProvider/WfpProvider';
|
|
18
|
+
import { FingerprintPacket } from './WfpProvider/FingerprintPacket';
|
|
19
|
+
import { WfpCalculator } from './WfpProvider/WfpCalculator/WfpCalculator';
|
|
20
|
+
import { WfpSplitter } from './WfpProvider/WfpSplitter/WfpSplitter';
|
|
18
21
|
|
|
19
22
|
let finishPromiseResolve;
|
|
20
23
|
let finishPromiseReject;
|
|
@@ -22,44 +25,44 @@ let finishPromiseReject;
|
|
|
22
25
|
|
|
23
26
|
|
|
24
27
|
export class Scanner extends EventEmitter {
|
|
25
|
-
scannerCfg;
|
|
28
|
+
private scannerCfg: ScannerCfg;
|
|
26
29
|
|
|
27
|
-
workDirectory;
|
|
30
|
+
private workDirectory: string;
|
|
28
31
|
|
|
29
|
-
|
|
32
|
+
private resultFilePath: string;
|
|
30
33
|
|
|
31
|
-
|
|
34
|
+
private wfpFilePath: string;
|
|
32
35
|
|
|
33
|
-
private
|
|
36
|
+
private scanRoot: string;
|
|
34
37
|
|
|
35
|
-
private
|
|
38
|
+
private scannerId: string;
|
|
36
39
|
|
|
37
|
-
|
|
40
|
+
private wfpProvider: WfpProvider;
|
|
38
41
|
|
|
39
|
-
|
|
42
|
+
private dispatcher: Dispatcher;
|
|
40
43
|
|
|
41
|
-
|
|
44
|
+
private finishPromise: Promise<void>;
|
|
42
45
|
|
|
43
|
-
|
|
46
|
+
private scannerInput: Array<ScannerInput>;
|
|
44
47
|
|
|
45
|
-
|
|
48
|
+
private scanFinished: boolean; // Both flags are used to prevent a race condition between DISPATCHER.NEW_DATA and DISPATCHER_FINISHED
|
|
46
49
|
|
|
47
|
-
|
|
50
|
+
private processingNewData: boolean; // Both flags are used to prevent a race condition between DISPATCHER.NEW_DATA and DISPATCHER_FINISHED
|
|
48
51
|
|
|
49
|
-
|
|
52
|
+
private processedFiles: number;
|
|
50
53
|
|
|
51
|
-
|
|
54
|
+
private running: boolean;
|
|
52
55
|
|
|
53
|
-
|
|
56
|
+
private filesToScan;
|
|
54
57
|
|
|
55
|
-
|
|
58
|
+
private responseBuffer;
|
|
56
59
|
|
|
57
|
-
private
|
|
60
|
+
private filesNotScanned;
|
|
58
61
|
|
|
59
62
|
constructor(scannerCfg = new ScannerCfg()) {
|
|
60
63
|
super();
|
|
61
64
|
this.scannerCfg = scannerCfg;
|
|
62
|
-
this.scannerId = new Date().getTime();
|
|
65
|
+
this.scannerId = new Date().getTime().toString();
|
|
63
66
|
}
|
|
64
67
|
|
|
65
68
|
init() {
|
|
@@ -70,7 +73,7 @@ export class Scanner extends EventEmitter {
|
|
|
70
73
|
this.responseBuffer = [];
|
|
71
74
|
this.filesToScan = {};
|
|
72
75
|
this.filesNotScanned = {};
|
|
73
|
-
this.
|
|
76
|
+
this.wfpProvider = new WfpCalculator(this.scannerCfg);
|
|
74
77
|
this.dispatcher = new Dispatcher(this.scannerCfg);
|
|
75
78
|
|
|
76
79
|
this.finishPromise = new Promise((resolve, reject) =>{
|
|
@@ -85,19 +88,19 @@ export class Scanner extends EventEmitter {
|
|
|
85
88
|
}
|
|
86
89
|
|
|
87
90
|
setWinnowerListeners() {
|
|
88
|
-
this.
|
|
89
|
-
this.emit(ScannerEvents.WINNOWING_NEW_CONTENT,
|
|
91
|
+
this.wfpProvider.on(ScannerEvents.WINNOWING_NEW_CONTENT, (fingerprintPacket: FingerprintPacket) => {
|
|
92
|
+
this.emit(ScannerEvents.WINNOWING_NEW_CONTENT, fingerprintPacket);
|
|
90
93
|
this.reportLog(`[ SCANNER ]: New WFP content`);
|
|
91
|
-
|
|
92
|
-
const disptItem = new DispatchableItem(
|
|
94
|
+
fingerprintPacket.setEngineFlags(this.scannerInput[0].engineFlags);
|
|
95
|
+
const disptItem = new DispatchableItem(fingerprintPacket);
|
|
93
96
|
this.dispatcher.dispatchItem(disptItem);
|
|
94
97
|
});
|
|
95
98
|
|
|
96
|
-
this.
|
|
99
|
+
this.wfpProvider.on(ScannerEvents.WINNOWER_LOG, (msg) => {
|
|
97
100
|
this.reportLog(msg);
|
|
98
101
|
});
|
|
99
102
|
|
|
100
|
-
this.
|
|
103
|
+
this.wfpProvider.on(ScannerEvents.ERROR, (error) => {
|
|
101
104
|
this.errorHandler(error, ScannerEvents.MODULE_WINNOWER);
|
|
102
105
|
});
|
|
103
106
|
}
|
|
@@ -105,12 +108,12 @@ export class Scanner extends EventEmitter {
|
|
|
105
108
|
setDispatcherListeners() {
|
|
106
109
|
this.dispatcher.on(ScannerEvents.DISPATCHER_QUEUE_SIZE_MAX_LIMIT, () => {
|
|
107
110
|
this.reportLog(`[ SCANNER ]: Maximum queue size reached. Winnower will be paused`);
|
|
108
|
-
this.
|
|
111
|
+
this.wfpProvider.pause();
|
|
109
112
|
});
|
|
110
113
|
|
|
111
114
|
this.dispatcher.on(ScannerEvents.DISPATCHER_QUEUE_SIZE_MIN_LIMIT, () => {
|
|
112
115
|
this.reportLog(`[ SCANNER ]: Minimum queue size reached. Winnower will be resumed`);
|
|
113
|
-
this.
|
|
116
|
+
this.wfpProvider.resume();
|
|
114
117
|
});
|
|
115
118
|
|
|
116
119
|
this.dispatcher.on(ScannerEvents.DISPATCHER_NEW_DATA, async (response) => {
|
|
@@ -125,7 +128,7 @@ export class Scanner extends EventEmitter {
|
|
|
125
128
|
});
|
|
126
129
|
|
|
127
130
|
this.dispatcher.on(ScannerEvents.DISPATCHER_FINISHED, async () => {
|
|
128
|
-
if (!this.
|
|
131
|
+
if (!this.wfpProvider.hasPendingFiles()) {
|
|
129
132
|
if (this.processingNewData) this.scanFinished = true;
|
|
130
133
|
else await this.finishJob();
|
|
131
134
|
}
|
|
@@ -136,7 +139,7 @@ export class Scanner extends EventEmitter {
|
|
|
136
139
|
this.appendFilesToNotScanned(filesNotScanned);
|
|
137
140
|
});
|
|
138
141
|
|
|
139
|
-
this.
|
|
142
|
+
this.wfpProvider.on(ScannerEvents.DISPATCHER_LOG, (msg) => {
|
|
140
143
|
this.reportLog(msg);
|
|
141
144
|
});
|
|
142
145
|
|
|
@@ -206,8 +209,18 @@ export class Scanner extends EventEmitter {
|
|
|
206
209
|
this.scannerInput.shift();
|
|
207
210
|
this.reportLog(`[ SCANNER ]: Job finished. ${this.scannerInput.length} pendings`);
|
|
208
211
|
|
|
209
|
-
if(this.scannerInput.length)
|
|
210
|
-
|
|
212
|
+
if(this.scannerInput.length) {
|
|
213
|
+
if (this.scannerInput[0].wfpPath) {
|
|
214
|
+
this.wfpProvider = new WfpSplitter();
|
|
215
|
+
this.setWinnowerListeners();
|
|
216
|
+
this.wfpProvider.start({wfpPath: this.scannerInput[0].wfpPath});
|
|
217
|
+
} else {
|
|
218
|
+
const folderRoot = this.scannerInput[0].folderRoot;
|
|
219
|
+
const winnowingMode = this.scannerInput[0].winnowingMode;
|
|
220
|
+
const fileList = this.scannerInput[0].fileList;
|
|
221
|
+
this.wfpProvider.start({folderRoot, winnowingMode, fileList});
|
|
222
|
+
}
|
|
223
|
+
} else await this.finishScan();
|
|
211
224
|
}
|
|
212
225
|
|
|
213
226
|
private async finishScan() {
|
|
@@ -264,7 +277,6 @@ export class Scanner extends EventEmitter {
|
|
|
264
277
|
public scanFromWinnowingFile(wfpFilePath: string): Promise<void> {
|
|
265
278
|
this.init();
|
|
266
279
|
this.createOutputFiles();
|
|
267
|
-
this.winnower.startWinnowingFromFile(wfpFilePath);
|
|
268
280
|
return this.finishPromise;
|
|
269
281
|
}
|
|
270
282
|
|
|
@@ -274,16 +286,27 @@ export class Scanner extends EventEmitter {
|
|
|
274
286
|
this.createOutputFiles();
|
|
275
287
|
this.scannerInput = scannerInput;
|
|
276
288
|
|
|
277
|
-
if (!this.isValidInput(scannerInput)) {
|
|
278
|
-
|
|
279
|
-
|
|
289
|
+
// if (!this.isValidInput(scannerInput)) {
|
|
290
|
+
// this.finishScan();
|
|
291
|
+
// return this.finishPromise;
|
|
292
|
+
// }
|
|
293
|
+
|
|
294
|
+
if (scannerInput[0].wfpPath) {
|
|
295
|
+
this.wfpProvider = new WfpSplitter();
|
|
296
|
+
this.setWinnowerListeners();
|
|
297
|
+
this.wfpProvider.start({wfpPath: scannerInput[0].wfpPath});
|
|
298
|
+
} else {
|
|
299
|
+
const folderRoot = this.scannerInput[0].folderRoot;
|
|
300
|
+
const winnowingMode = this.scannerInput[0].winnowingMode;
|
|
301
|
+
const fileList = this.scannerInput[0].fileList;
|
|
302
|
+
this.wfpProvider.start({folderRoot, winnowingMode, fileList});
|
|
280
303
|
}
|
|
281
|
-
|
|
282
|
-
this.winnower.startWinnowing(this.scannerInput[0]);
|
|
283
304
|
return this.finishPromise;
|
|
284
305
|
}
|
|
285
306
|
|
|
286
307
|
|
|
308
|
+
|
|
309
|
+
|
|
287
310
|
private isValidInput(scannerInput: Array<ScannerInput>): boolean {
|
|
288
311
|
if (!scannerInput) {
|
|
289
312
|
this.reportLog('[ SCANNER ]: No input provided', 'warning');
|
|
@@ -313,25 +336,13 @@ export class Scanner extends EventEmitter {
|
|
|
313
336
|
return this.scannerId;
|
|
314
337
|
}
|
|
315
338
|
|
|
316
|
-
pause() {
|
|
317
|
-
this.running = false;
|
|
318
|
-
this.winnower.pause();
|
|
319
|
-
// this.dispatcher.pause();
|
|
320
|
-
}
|
|
321
|
-
|
|
322
|
-
resume() {
|
|
323
|
-
this.running = true;
|
|
324
|
-
this.winnower.resume();
|
|
325
|
-
// this.dispatcher.resume();
|
|
326
|
-
}
|
|
327
|
-
|
|
328
339
|
stop() {
|
|
329
340
|
this.reportLog(`[ SCANNER ]: Stopping scanner`);
|
|
330
341
|
this.running = false;
|
|
331
|
-
this.
|
|
342
|
+
this.wfpProvider.removeAllListeners();
|
|
332
343
|
this.dispatcher.removeAllListeners();
|
|
333
344
|
this.dispatcher.stop();
|
|
334
|
-
this.
|
|
345
|
+
this.wfpProvider.stop();
|
|
335
346
|
}
|
|
336
347
|
|
|
337
348
|
isRunning() {
|
|
@@ -23,7 +23,7 @@ export class ScannerCfg {
|
|
|
23
23
|
// Persist results after [ X ] number of server responses.
|
|
24
24
|
MAX_RESPONSES_IN_BUFFER = 300;
|
|
25
25
|
|
|
26
|
-
DISPATCHER_QUEUE_SIZE_MAX_LIMIT =
|
|
26
|
+
DISPATCHER_QUEUE_SIZE_MAX_LIMIT = 300;
|
|
27
27
|
|
|
28
|
-
DISPATCHER_QUEUE_SIZE_MIN_LIMIT =
|
|
28
|
+
DISPATCHER_QUEUE_SIZE_MIN_LIMIT = 200;
|
|
29
29
|
};
|
|
@@ -1,17 +1,17 @@
|
|
|
1
|
-
export class
|
|
1
|
+
export class FingerprintPacket {
|
|
2
2
|
private wfpContent: string;
|
|
3
3
|
|
|
4
4
|
private engineFlags: number;
|
|
5
5
|
|
|
6
6
|
private scanRoot: string;
|
|
7
7
|
|
|
8
|
-
constructor(wfpContent, scanRoot = '') {
|
|
8
|
+
constructor(wfpContent: string, scanRoot = '') {
|
|
9
9
|
this.wfpContent = wfpContent;
|
|
10
10
|
this.scanRoot = scanRoot;
|
|
11
11
|
}
|
|
12
12
|
|
|
13
|
-
public isEqual(
|
|
14
|
-
return this.getContent() ===
|
|
13
|
+
public isEqual(fingerprintPacket: FingerprintPacket): boolean {
|
|
14
|
+
return this.getContent() === fingerprintPacket.getContent();
|
|
15
15
|
}
|
|
16
16
|
|
|
17
17
|
public getContent() {
|
|
@@ -26,7 +26,7 @@ export class WinnowerResponse {
|
|
|
26
26
|
return this.engineFlags;
|
|
27
27
|
}
|
|
28
28
|
|
|
29
|
-
public
|
|
29
|
+
public getFilesFingerprinted() {
|
|
30
30
|
const files = [];
|
|
31
31
|
const regExp = new RegExp(/,(\/.*)/g);
|
|
32
32
|
let result;
|