fileExists no longer case sensitive for programs

This commit is contained in:
omuretsu 2023-05-27 08:34:14 -04:00
parent ad3b217b8f
commit 8bf13b6fd3
3 changed files with 17 additions and 24 deletions

@ -17,7 +17,7 @@ fileExists(filename: string, host?: string): boolean;
| Parameter | Type | Description |
| --- | --- | --- |
| filename | string | Filename of file to check. |
| host | string | _(Optional)_ Host of target server. This is optional. If it is not specified then the function will use the current server as the target server. |
| host | string | _(Optional)_ Host of target server. Optional, defaults to the server the script is running on. |
**Returns:**
@ -29,9 +29,7 @@ True if specified file exists, and false otherwise.
RAM cost: 0.1 GB
Returns a boolean indicating whether the specified file exists on the target server. The filename for scripts is case-sensitive, but for other types of files it is not. For example, fileExists(“brutessh.exe”) will work fine, even though the actual program is named 'BruteSSH.exe'.
If the hostname/ip argument is omitted, then the function will search through the current server (the server running the script that calls this function) for the file.
Returns a boolean indicating whether the specified file exists on the target server. The filename for programs is case insensitive, other file types are case sensitive. For example, fileExists(“brutessh.exe”) will work fine, even though the actual program is named 'BruteSSH.exe'.
\*

@ -1125,21 +1125,19 @@ export const ns: InternalAPI<NSFull> = {
const hostname = helpers.string(ctx, "hostname", _hostname);
return GetServer(hostname) !== null;
},
fileExists:
(ctx) =>
(_filename, _hostname = ctx.workerScript.hostname) => {
const filename = helpers.string(ctx, "filename", _filename);
const hostname = helpers.string(ctx, "hostname", _hostname);
const server = helpers.getServer(ctx, hostname);
const path = resolveFilePath(filename, ctx.workerScript.name);
if (!path) return false;
if (hasScriptExtension(path)) return server.scripts.has(path);
if (hasTextExtension(path)) return server.textFiles.has(path);
if (hasProgramExtension(path)) return server.programs.includes(path);
if (path.endsWith(".lit") || path.endsWith(".msg")) return server.messages.includes(path as any);
if (hasContractExtension(path)) return !!server.contracts.find(({ fn }) => fn === path);
return false;
},
fileExists: (ctx) => (_filename, _hostname) => {
const filename = helpers.string(ctx, "filename", _filename);
const hostname = helpers.string(ctx, "hostname", _hostname ?? ctx.workerScript.hostname);
const server = helpers.getServer(ctx, hostname);
const path = resolveFilePath(filename, ctx.workerScript.name);
if (!path) return false;
if (hasScriptExtension(path)) return server.scripts.has(path);
if (hasTextExtension(path)) return server.textFiles.has(path);
if (path.endsWith(".lit") || path.endsWith(".msg")) return server.messages.includes(path as any);
if (hasContractExtension(path)) return !!server.contracts.find(({ fn }) => fn === path);
const lowerPath = path.toLowerCase();
return server.programs.map((programName) => programName.toLowerCase()).includes(lowerPath);
},
isRunning:
(ctx) =>
(fn, hostname, ...scriptArgs) => {

@ -5750,13 +5750,10 @@ export interface NS {
* RAM cost: 0.1 GB
*
* Returns a boolean indicating whether the specified file exists on the target server.
* The filename for scripts is case-sensitive, but for other types of files it is not.
* The filename for programs is case insensitive, other file types are case sensitive.
* For example, fileExists(brutessh.exe) will work fine, even though the actual program
* is named 'BruteSSH.exe'.
*
* If the hostname/ip argument is omitted, then the function will search through the current
* server (the server running the script that calls this function) for the file.
*
* * @example
* ```js
* // The function call will return true if the script named foo.js exists on the foodnstuff server, and false otherwise.
@ -5766,7 +5763,7 @@ export interface NS {
* ns.fileExists("ftpcrack.exe");
* ```
* @param filename - Filename of file to check.
* @param host - Host of target server. This is optional. If it is not specified then the function will use the current server as the target server.
* @param host - Host of target server. Optional, defaults to the server the script is running on.
* @returns True if specified file exists, and false otherwise.
*/
fileExists(filename: string, host?: string): boolean;