Skip to content

Commit 5de67be

Browse files
committed
SP-711 Skips binary files on local cryptography scanning
1 parent c6452cb commit 5de67be

File tree

7 files changed

+28
-4
lines changed

7 files changed

+28
-4
lines changed

Diff for: CHANGELOG.md

+2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
44

5+
### [0.13.2](https://github.com/scanoss/scanoss.js/compare/v0.13.0...v0.13.1) (2024-05-20)
6+
57
### [0.13.1](https://github.com/scanoss/scanoss.js/compare/v0.13.0...v0.13.1) (2024-05-15)
68

79
### [0.13.0](https://github.com/scanoss/scanoss.js/compare/v0.12.2...v0.13.0) (2024-05-13)

Diff for: package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "scanoss",
3-
"version": "0.13.1",
3+
"version": "0.13.2",
44
"description": "The SCANOSS JS package provides a simple, easy to consume module for interacting with SCANOSS APIs/Engine.",
55
"main": "build/main/index.js",
66
"typings": "build/main/index.d.ts",

Diff for: src/cli/commands/crypto.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import { Tree } from '../../sdk/tree/Tree';
1010
import { DependencyFilter } from '../../sdk/tree/Filters/DependencyFilter';
1111
import { CryptoCfg } from '../../sdk/Cryptography/CryptoCfg';
1212
import fs from 'fs';
13+
import { BinaryFilter } from '../../sdk/tree/Filters/BinaryFilter';
1314

1415
export async function cryptoHandler(rootPath: string, options: any): Promise<void> {
1516
rootPath = rootPath.replace(/\/$/, ''); // Remove trailing slash if exists
@@ -30,7 +31,7 @@ export async function cryptoHandler(rootPath: string, options: any): Promise<voi
3031
if (pathIsFolder) {
3132
const tree = new Tree(rootPath);
3233
tree.build();
33-
fileList = tree.getFileList(null);
34+
fileList = tree.getFileList(new BinaryFilter());
3435
}
3536

3637
console.log("Searching for local cryptography...")

Diff for: src/sdk/tree/File.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,10 @@ import { Filter } from './Filters/Filter';
44

55

66
export default class File extends Node {
7-
constructor(name: string, path: string) {
7+
constructor(name: string, path: string, isBinaryFile: boolean) {
88
super(name, path);
99
this.type = NodeType.FILE;
10+
this.isBinaryFile = isBinaryFile;
1011
}
1112

1213
public getNode(path: string): Node {

Diff for: src/sdk/tree/Filters/BinaryFilter.ts

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import Node from '../Node';
2+
import { Filter } from './Filter';
3+
4+
export class BinaryFilter extends Filter {
5+
public evaluate(node: Node): boolean {
6+
return !node.isBinary();
7+
}
8+
9+
}

Diff for: src/sdk/tree/Node.ts

+7
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,12 @@ export default abstract class Node {
1010

1111
protected action: string;
1212

13+
protected isBinaryFile: boolean;
14+
1315
constructor(path: string, label: string) {
1416
this.path = path;
1517
this.label = label;
18+
this.isBinaryFile = false;
1619
}
1720

1821
public abstract getNode(path: string): Node;
@@ -31,6 +34,10 @@ export default abstract class Node {
3134
return this.type;
3235
}
3336

37+
public isBinary(): boolean {
38+
return this.isBinaryFile;
39+
}
40+
3441
}
3542

3643
export enum NodeType {

Diff for: src/sdk/tree/Tree.ts

+5-1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import File from './File';
88
import Folder from './Folder';
99
import { FilterList } from '../Filtering/Filtering';
1010
import { Filter } from './Filters/Filter';
11+
import { isBinaryFileSync } from 'isbinaryfile';
1112

1213
export class Tree {
1314
private rootFolder: Folder;
@@ -44,7 +45,10 @@ export class Tree {
4445
const f: Folder = new Folder(fullPath, dirEntry.name);
4546
const subTree = this.buildRec(`${path}/${dirEntry.name}`, f);
4647
root.addChild(subTree);
47-
} else root.addChild(new File(fullPath, dirEntry.name));
48+
} else {
49+
const file = new File(fullPath, dirEntry.name, isBinaryFileSync(fullPath));
50+
root.addChild(file);
51+
}
4852
}
4953
return root;
5054
}

0 commit comments

Comments
 (0)