Merge pull request #1993 from Nick-Colclasure/file-read-patch

Fix problems finding root files in cat and ns.read
This commit is contained in:
hydroflame 2021-12-20 01:56:20 -05:00 committed by GitHub
commit 3255768259
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 3 deletions

@ -16,7 +16,8 @@ export function cat(
terminal.error("Incorrect usage of cat command. Usage: cat [file]"); terminal.error("Incorrect usage of cat command. Usage: cat [file]");
return; return;
} }
const filename = terminal.getFilepath(args[0] + ""); const relative_filename = args[0] + "";
const filename = terminal.getFilepath(relative_filename);
if (!filename.endsWith(".msg") && !filename.endsWith(".lit") && !filename.endsWith(".txt")) { if (!filename.endsWith(".msg") && !filename.endsWith(".lit") && !filename.endsWith(".txt")) {
terminal.error( terminal.error(
"Only .msg, .txt, and .lit files are viewable with cat (filename must end with .msg, .txt, or .lit)", "Only .msg, .txt, and .lit files are viewable with cat (filename must end with .msg, .txt, or .lit)",
@ -39,7 +40,7 @@ export function cat(
} }
} }
} else if (filename.endsWith(".txt")) { } else if (filename.endsWith(".txt")) {
const txt = terminal.getTextFile(player, filename); const txt = terminal.getTextFile(player, relative_filename);
if (txt != null) { if (txt != null) {
txt.show(); txt.show();
return; return;

@ -1,6 +1,7 @@
import { dialogBoxCreate } from "./ui/React/DialogBox"; import { dialogBoxCreate } from "./ui/React/DialogBox";
import { BaseServer } from "./Server/BaseServer"; import { BaseServer } from "./Server/BaseServer";
import { Generic_fromJSON, Generic_toJSON, Reviver } from "./utils/JSONReviver"; 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. * 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 // eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
export function getTextFile(fn: string, server: BaseServer): TextFile | null { 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[]) { for (const file of server.textFiles as TextFile[]) {
if (file.fn === filename) { if (file.fn === filename) {