Skip to content

Commit

Permalink
Ignore non-JSON files and search subdirectories (resolves IBM-Blockch…
Browse files Browse the repository at this point in the history
…ain#1523)

Signed-off-by: Simon Stone <sstone1@uk.ibm.com>
  • Loading branch information
Simon Stone committed Oct 15, 2019
1 parent efb2c5c commit 04c796e
Show file tree
Hide file tree
Showing 8 changed files with 41 additions and 20 deletions.
49 changes: 29 additions & 20 deletions extension/fabric/FabricEnvironment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,27 +42,36 @@ export class FabricEnvironment extends EventEmitter {
}

public async getNodes(withoutIdentitiies: boolean = false): Promise<FabricNode[]> {
const nodesPath: string = path.resolve(this.path, 'nodes');
const nodesExist: boolean = await fs.pathExists(nodesPath);
if (!nodesExist) {
return [];
}
let nodePaths: string[] = await fs.readdir(nodesPath);
nodePaths = nodePaths
.sort()
.filter((nodePath: string) => !nodePath.startsWith('.'))
.map((nodePath: string) => path.resolve(this.path, 'nodes', nodePath));
const nodes: FabricNode[] = [];
for (const nodePath of nodePaths) {
const node: FabricNode = await fs.readJson(nodePath);
nodes.push(node);
}

if (withoutIdentitiies) {
return nodes.filter((node: FabricNode) => (!node.wallet || !node.identity));
} else {
return nodes;
const rootNodesPath: string = path.resolve(this.path, 'nodes');
async function loadNodes(nodesPath: string): Promise<FabricNode[]> {
const nodesExist: boolean = await fs.pathExists(nodesPath);
if (!nodesExist) {
return [];
}
let nodePaths: string[] = await fs.readdir(nodesPath);
nodePaths = nodePaths
.sort()
.filter((nodePath: string) => !nodePath.startsWith('.'))
.map((nodePath: string) => path.resolve(nodesPath, nodePath));
const nodes: FabricNode[] = [];
for (const nodePath of nodePaths) {
const stats: fs.Stats = await fs.lstat(nodePath);
if (stats.isDirectory()) {
const subNodes: FabricNode[] = await loadNodes(nodePath);
nodes.push(...subNodes);
} else if (stats.isFile() && nodePath.endsWith('.json')) {
const node: FabricNode = await fs.readJson(nodePath);
nodes.push(node);
}
}

if (withoutIdentitiies) {
return nodes.filter((node: FabricNode) => (!node.wallet || !node.identity));
} else {
return nodes;
}
}
return loadNodes(rootNodesPath);
}

public async updateNode(node: FabricNode): Promise<void> {
Expand Down
4 changes: 4 additions & 0 deletions test/data/yofn/nodes/junkfile.bin
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
i am an orderer
and i'm hashing a block
hashy hashy block
hashy hashy block
4 changes: 4 additions & 0 deletions test/data/yofn/nodes/orderer/junkfile.bin
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
i am an orderer
and i'm hashing a block
hashy hashy block
hashy hashy block
File renamed without changes.
4 changes: 4 additions & 0 deletions test/data/yofn/nodes/org1/junkfile.bin
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
i am an orderer
and i'm hashing a block
hashy hashy block
hashy hashy block

0 comments on commit 04c796e

Please sign in to comment.