Skip to content

Commit

Permalink
SP-711 Skips binary files on local cryptography scanning
Browse files Browse the repository at this point in the history
  • Loading branch information
agustingroh committed May 20, 2024
1 parent c6452cb commit 5de67be
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 4 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

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.

### [0.13.2](https://github.com/scanoss/scanoss.js/compare/v0.13.0...v0.13.1) (2024-05-20)

### [0.13.1](https://github.com/scanoss/scanoss.js/compare/v0.13.0...v0.13.1) (2024-05-15)

### [0.13.0](https://github.com/scanoss/scanoss.js/compare/v0.12.2...v0.13.0) (2024-05-13)
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "scanoss",
"version": "0.13.1",
"version": "0.13.2",
"description": "The SCANOSS JS package provides a simple, easy to consume module for interacting with SCANOSS APIs/Engine.",
"main": "build/main/index.js",
"typings": "build/main/index.d.ts",
Expand Down
3 changes: 2 additions & 1 deletion src/cli/commands/crypto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { Tree } from '../../sdk/tree/Tree';
import { DependencyFilter } from '../../sdk/tree/Filters/DependencyFilter';
import { CryptoCfg } from '../../sdk/Cryptography/CryptoCfg';
import fs from 'fs';
import { BinaryFilter } from '../../sdk/tree/Filters/BinaryFilter';

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

console.log("Searching for local cryptography...")
Expand Down
3 changes: 2 additions & 1 deletion src/sdk/tree/File.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@ import { Filter } from './Filters/Filter';


export default class File extends Node {
constructor(name: string, path: string) {
constructor(name: string, path: string, isBinaryFile: boolean) {
super(name, path);
this.type = NodeType.FILE;
this.isBinaryFile = isBinaryFile;
}

public getNode(path: string): Node {
Expand Down
9 changes: 9 additions & 0 deletions src/sdk/tree/Filters/BinaryFilter.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import Node from '../Node';
import { Filter } from './Filter';

export class BinaryFilter extends Filter {
public evaluate(node: Node): boolean {
return !node.isBinary();
}

}
7 changes: 7 additions & 0 deletions src/sdk/tree/Node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,12 @@ export default abstract class Node {

protected action: string;

protected isBinaryFile: boolean;

constructor(path: string, label: string) {
this.path = path;
this.label = label;
this.isBinaryFile = false;
}

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

public isBinary(): boolean {
return this.isBinaryFile;
}

}

export enum NodeType {
Expand Down
6 changes: 5 additions & 1 deletion src/sdk/tree/Tree.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import File from './File';
import Folder from './Folder';
import { FilterList } from '../Filtering/Filtering';
import { Filter } from './Filters/Filter';
import { isBinaryFileSync } from 'isbinaryfile';

export class Tree {
private rootFolder: Folder;
Expand Down Expand Up @@ -44,7 +45,10 @@ export class Tree {
const f: Folder = new Folder(fullPath, dirEntry.name);
const subTree = this.buildRec(`${path}/${dirEntry.name}`, f);
root.addChild(subTree);
} else root.addChild(new File(fullPath, dirEntry.name));
} else {
const file = new File(fullPath, dirEntry.name, isBinaryFileSync(fullPath));
root.addChild(file);
}
}
return root;
}
Expand Down

0 comments on commit 5de67be

Please sign in to comment.