From 8f69a6c0eeb64a82ceda69ac2e358b65a8a454c7 Mon Sep 17 00:00:00 2001 From: Chris Farfan de los Godos <83005088+UncleCeiling@users.noreply.github.com> Date: Thu, 24 Jul 2025 02:27:01 +0300 Subject: [PATCH] COMMAND: Improving error message for mv when a script is Running * Adjusted error message to include information about making sure scripts are not running when trying to use mv on them. * nom run format * Added behaviour info to NetscriptDefinitions.d.ts * `npm run doc` * un-nested/inversed the check * `npm run format` --- markdown/bitburner.ns.mv.md | 2 ++ src/NetscriptFunctions.ts | 16 ++++++++++------ src/ScriptEditor/NetscriptDefinitions.d.ts | 2 ++ src/Terminal/commands/mv.ts | 4 +++- 4 files changed, 17 insertions(+), 7 deletions(-) diff --git a/markdown/bitburner.ns.mv.md b/markdown/bitburner.ns.mv.md index c3a389eb7..862a03610 100644 --- a/markdown/bitburner.ns.mv.md +++ b/markdown/bitburner.ns.mv.md @@ -34,3 +34,5 @@ This command only works for scripts and text files (.txt). It cannot, however, b This function can also be used to rename files. +This function is not able to remove running scripts from their original locations. Make sure to stop any scripts before using this function on them. + diff --git a/src/NetscriptFunctions.ts b/src/NetscriptFunctions.ts index 3cc275e7f..ad23c9921 100644 --- a/src/NetscriptFunctions.ts +++ b/src/NetscriptFunctions.ts @@ -1613,13 +1613,17 @@ export const ns: InternalAPI = { throw helpers.errorMessage(ctx, `Source text file ${sourcePath} does not exist on ${host}`); } const success = sourceContentFile.deleteFromServer(server); - if (success) { - const { overwritten } = server.writeToContentFile(destinationPath, sourceContentFile.content); - if (overwritten) helpers.log(ctx, () => `WARNING: Overwriting file ${destinationPath} on ${host}`); - helpers.log(ctx, () => `Moved ${sourcePath} to ${destinationPath} on ${host}`); - return; + if (!success) { + helpers.log( + ctx, + () => + `ERROR: Failed. Was unable to remove file ${sourcePath} from its original location. If ${sourcePath} is a script, make sure that it is NOT running before trying to use 'mv' on it.`, + ); } - helpers.log(ctx, () => `ERROR: Failed. Was unable to remove file ${sourcePath} from its original location.`); + const { overwritten } = server.writeToContentFile(destinationPath, sourceContentFile.content); + if (overwritten) helpers.log(ctx, () => `WARNING: Overwriting file ${destinationPath} on ${host}`); + helpers.log(ctx, () => `Moved ${sourcePath} to ${destinationPath} on ${host}`); + return; }, getResetInfo: () => () => ({ lastAugReset: Player.lastAugReset, diff --git a/src/ScriptEditor/NetscriptDefinitions.d.ts b/src/ScriptEditor/NetscriptDefinitions.d.ts index b168a1d35..0ed94e46d 100644 --- a/src/ScriptEditor/NetscriptDefinitions.d.ts +++ b/src/ScriptEditor/NetscriptDefinitions.d.ts @@ -8215,6 +8215,8 @@ export interface NS { * * This function can also be used to rename files. * + * This function is not able to remove running scripts from their original locations. Make sure to stop any scripts before using this function on them. + * * @param host - Hostname/IP of target server. * @param source - Filename of the source file. * @param destination - Filename of the destination file. diff --git a/src/Terminal/commands/mv.ts b/src/Terminal/commands/mv.ts index c6e26d720..9f612042c 100644 --- a/src/Terminal/commands/mv.ts +++ b/src/Terminal/commands/mv.ts @@ -27,7 +27,9 @@ export function mv(args: (string | number | boolean)[], server: BaseServer): voi if (!sourceContentFile) return Terminal.error(`Source file ${sourcePath} does not exist`); if (!sourceContentFile.deleteFromServer(server)) { - return Terminal.error(`Could not remove source file ${sourcePath} from existing location.`); + return Terminal.error( + `Could not remove source file ${sourcePath} from existing location. If ${sourcePath} is a script, make sure that it is NOT running before trying to use 'mv' on it.`, + ); } Terminal.print(`Moved ${sourcePath} to ${destinationPath}`); const { overwritten } = server.writeToContentFile(destinationPath, sourceContentFile.content);