Skip to content

Commit 2102ef0

Browse files
authored
Merge pull request #150 from ChrisPark89/fix/overwrite
Added a check if directory is empty before 'rm -r *'
2 parents 738cb76 + ff6e641 commit 2102ef0

File tree

2 files changed

+6
-6
lines changed

2 files changed

+6
-6
lines changed

__tests__/api/BundlePush/BundlePusher.test.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -380,7 +380,7 @@ describe("BundlePusher01", () => {
380380
shellSpy.mockImplementationOnce(() => { throw new Error( "Injected Shell error" ); });
381381

382382
await runPushTestWithError("__tests__/__resources__/ExampleBundle01", true,
383-
"A problem occurred attempting to run 'rm -r *' in remote directory '/u/ThisDoesNotExist/12345678'. Problem is: Injected Shell error");
383+
"A problem occurred attempting to run 'if [ \"$(ls)\" ]; then rm -r *; fi' in remote directory '/u/ThisDoesNotExist/12345678'. Problem is: Injected Shell error");
384384

385385
expect(zosMFSpy).toHaveBeenCalledTimes(1);
386386
expect(sshSpy).toHaveBeenCalledTimes(1);
@@ -414,7 +414,7 @@ describe("BundlePusher01", () => {
414414
});
415415

416416
await runPushTestWithError("__tests__/__resources__/ExampleBundle01", true,
417-
"A problem occurred attempting to run 'rm -r *' in remote directory '/u/ThisDoesNotExist/12345678'. " +
417+
"A problem occurred attempting to run 'if [ \"$(ls)\" ]; then rm -r *; fi' in remote directory '/u/ThisDoesNotExist/12345678'. " +
418418
"Problem is: The output from the remote command implied that an error occurred.");
419419

420420
expect(consoleText).toContain("Ssh command exit with non zero status");
@@ -433,7 +433,7 @@ describe("BundlePusher01", () => {
433433
});
434434

435435
await runPushTestWithError("__tests__/__resources__/ExampleBundle01", true,
436-
"A problem occurred attempting to run 'rm -r *' in remote directory '/u/ThisDoesNotExist/12345678'. " +
436+
"A problem occurred attempting to run 'if [ \"$(ls)\" ]; then rm -r *; fi' in remote directory '/u/ThisDoesNotExist/12345678'. " +
437437
"Problem is: The output from the remote command implied that an error occurred.");
438438

439439
expect(consoleText).toContain("Injected FSUM9195 error message");
@@ -452,7 +452,7 @@ describe("BundlePusher01", () => {
452452
});
453453

454454
await runPushTestWithError("__tests__/__resources__/ExampleBundle01", true,
455-
"A problem occurred attempting to run 'rm -r *' in remote directory '/u/ThisDoesNotExist/12345678'. " +
455+
"A problem occurred attempting to run 'if [ \"$(ls)\" ]; then rm -r *; fi' in remote directory '/u/ThisDoesNotExist/12345678'. " +
456456
"Problem is: The output from the remote command implied that an error occurred.");
457457

458458
expect(consoleText).toContain("Injected FSUM9195 and FSUM9196 error message");
@@ -892,7 +892,7 @@ describe("BundlePusher01", () => {
892892
expect(consoleText).toContain("Undeploy complete");
893893
expect(consoleText).toContain("Running 'npm uninstall *' in '/u/ThisDoesNotExist/12345678'");
894894
expect(consoleText).toContain("Removing contents of remote bundle directory");
895-
expect(consoleText).toContain("Issuing SSH command 'rm -r *' in remote directory '/u/ThisDoesNotExist/12345678'");
895+
expect(consoleText).toContain("Issuing SSH command 'if [ \"$(ls)\" ]; then rm -r *; fi' in remote directory '/u/ThisDoesNotExist/12345678'");
896896
expect(consoleText).toContain("Uploading bundle contents to remote directory");
897897
expect(consoleText).toContain("WARNING: No .zosAttributes file found in the bundle directory, default values will be applied");
898898
expect(consoleText).toContain("Running 'npm install' in '/u/ThisDoesNotExist/12345678'");

src/api/BundlePush/BundlePusher.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -338,7 +338,7 @@ export class BundlePusher {
338338

339339
private async deleteBundleDirContents(sshSession: SshSession) {
340340
this.updateStatus("Removing contents of remote bundle directory");
341-
await this.runSshCommandInRemoteDirectory(sshSession, this.params.arguments.bundledir, "rm -r *");
341+
await this.runSshCommandInRemoteDirectory(sshSession, this.params.arguments.bundledir, "if [ \"$(ls)\" ]; then rm -r *; fi");
342342
}
343343

344344
private async runSingleNpmInstall(sshSession: SshSession, remoteDirectory: string) {

0 commit comments

Comments
 (0)