Skip to content

Commit

Permalink
Merge pull request #2142 from SanjulaGanepola/fix/count-files-when-empty
Browse files Browse the repository at this point in the history
Fix `countFiles` when directory does not exist
  • Loading branch information
worksofliam authored Jul 1, 2024
2 parents e789fc3 + 4ebced1 commit fea4a69
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/api/IBMiContent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -947,6 +947,6 @@ export default class IBMiContent {
}

async countFiles(directory: string) {
return Number((await this.ibmi.sendCommand({ command: `ls | wc -l`, directory })).stdout.trim());
return Number((await this.ibmi.sendCommand({ command: `cd ${directory} && (ls | wc -l)` })).stdout.trim());
}
}
6 changes: 5 additions & 1 deletion src/testing/connection.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import assert from "assert";
import { TestSuite } from ".";
import { instance } from "../instantiate";
import { Tools } from "../api/Tools";

export const ConnectionSuite: TestSuite = {
name: `Connection tests`,
Expand Down Expand Up @@ -275,7 +276,7 @@ export const ConnectionSuite: TestSuite = {
name: `Test withTempDirectory and countFiles`, test: async () => {
const connection = instance.getConnection()!;
const content = instance.getContent()!;
let temp;
let temp;

await connection.withTempDirectory(async tempDir => {
temp = tempDir;
Expand All @@ -291,6 +292,9 @@ export const ConnectionSuite: TestSuite = {
}

assert.strictEqual(await content.countFiles(tempDir), toCreate);

//Directory does not exist
assert.strictEqual(await content.countFiles(`${tempDir}/${Tools.makeid(20)}`), 0);
});

if (temp) {
Expand Down

0 comments on commit fea4a69

Please sign in to comment.