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`
This commit is contained in:
Chris Farfan de los Godos
2025-07-24 02:27:01 +03:00
committed by GitHub
parent ff106bb764
commit 8f69a6c0ee
4 changed files with 17 additions and 7 deletions

View File

@@ -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.

View File

@@ -1613,13 +1613,17 @@ export const ns: InternalAPI<NSFull> = {
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,

View File

@@ -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.

View File

@@ -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);