From afc1347d3adb412e0077808f557deaee530416f9 Mon Sep 17 00:00:00 2001 From: Olivier Gagnon Date: Mon, 17 May 2021 18:09:47 -0400 Subject: [PATCH] Deleting a file without ext print a normal error msg. --- src/Constants.ts | 1 + src/Server/BaseServer.ts | 1 + src/Terminal.jsx | 12 ++++++++++-- 3 files changed, 12 insertions(+), 2 deletions(-) diff --git a/src/Constants.ts b/src/Constants.ts index 3c31a8042..a8f75656d 100644 --- a/src/Constants.ts +++ b/src/Constants.ts @@ -258,5 +258,6 @@ export const CONSTANTS: IMap = { * Fix some ram not displayed as 0.00GB * Fix error message throw undefined variable error * City hall now has some generic text if you can't create a corp yet. + * Deleting a file without extension now returns an appropriate error message. `, } \ No newline at end of file diff --git a/src/Server/BaseServer.ts b/src/Server/BaseServer.ts index b86e1849e..9300b109a 100644 --- a/src/Server/BaseServer.ts +++ b/src/Server/BaseServer.ts @@ -181,6 +181,7 @@ export class BaseServer { * @returns {IReturnStatus} Return status object indicating whether or not file was deleted */ removeFile(fn: string): IReturnStatus { + console.log(`removing ${fn}`); if (fn.endsWith(".exe") || fn.match(/^.+\.exe-\d+(?:\.\d*)?%-INC$/) != null) { for (let i = 0; i < this.programs.length; ++i) { if (this.programs[i] === fn) { diff --git a/src/Terminal.jsx b/src/Terminal.jsx index cbdb84c36..aef1812f3 100644 --- a/src/Terminal.jsx +++ b/src/Terminal.jsx @@ -1313,9 +1313,17 @@ let Terminal = { } // Check programs - let delTarget = Terminal.getFilepath(commandArray[1]); + let delTarget, status; + try { + delTarget = Terminal.getFilepath(commandArray[1]); + status = s.removeFile(delTarget); + } catch(err) { + status = { + res: false, + msg: 'No such file exists' + }; + } - const status = s.removeFile(delTarget); if (!status.res) { postError(status.msg); }