mirror of
https://github.com/bitburner-official/bitburner-src.git
synced 2024-11-09 17:23:53 +01:00
Fix problems finding root files in cat and ns.read
Cat ends up translating the path it receives from relative to absolute twice, which I fix by changing the filename to an absolute path before it's passed to getTextFile with a leading "/" so that it doesn't interpret the filename as being relative. Read I fixed by causing getTextFile to remove the leading "/" from files that are in the root directory, since that is required to translate their name into the native "filesystem"s format.
This commit is contained in:
parent
eb002d655a
commit
8ba5199e54
@ -39,7 +39,7 @@ export function cat(
|
||||
}
|
||||
}
|
||||
} else if (filename.endsWith(".txt")) {
|
||||
const txt = terminal.getTextFile(player, filename);
|
||||
const txt = terminal.getTextFile(player, "/" + filename);
|
||||
if (txt != null) {
|
||||
txt.show();
|
||||
return;
|
||||
|
@ -1,6 +1,7 @@
|
||||
import { dialogBoxCreate } from "./ui/React/DialogBox";
|
||||
import { BaseServer } from "./Server/BaseServer";
|
||||
import { Generic_fromJSON, Generic_toJSON, Reviver } from "./utils/JSONReviver";
|
||||
import { removeLeadingSlash, isInRootDirectory } from "./Terminal/DirectoryHelpers"
|
||||
|
||||
/**
|
||||
* Represents a plain text file that is typically stored on a server.
|
||||
@ -101,7 +102,11 @@ Reviver.constructors.TextFile = TextFile;
|
||||
*/
|
||||
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
|
||||
export function getTextFile(fn: string, server: BaseServer): TextFile | null {
|
||||
const filename: string = !fn.endsWith(".txt") ? `${fn}.txt` : fn;
|
||||
let filename: string = !fn.endsWith(".txt") ? `${fn}.txt` : fn;
|
||||
|
||||
if (isInRootDirectory(filename)) {
|
||||
filename = removeLeadingSlash(filename);
|
||||
}
|
||||
|
||||
for (const file of server.textFiles as TextFile[]) {
|
||||
if (file.fn === filename) {
|
||||
|
Loading…
Reference in New Issue
Block a user