From ae92ea0f94b3c6893c8e6274e519985dac754c13 Mon Sep 17 00:00:00 2001 From: lucebac Date: Tue, 28 Feb 2023 12:53:42 +0100 Subject: [PATCH] ns.scp: strip leading slashes from filenames if file is in root (#263) --- src/NetscriptFunctions.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/NetscriptFunctions.ts b/src/NetscriptFunctions.ts index 875016bd8..06f0bbb68 100644 --- a/src/NetscriptFunctions.ts +++ b/src/NetscriptFunctions.ts @@ -828,7 +828,10 @@ export const ns: InternalAPI = { let noFailures = true; //ts detects files as any[] here even though we would have thrown in the above loop if it wasn't string[] - for (const file of files as string[]) { + for (let file of files as string[]) { + // cut off the leading / for files in the root of the server; this assumes that the filename is somewhat normalized and doesn't look like `//file.js` + if (file.startsWith("/") && file.indexOf("/", 1) === -1) file = file.slice(1); + // Scp for lit files if (file.endsWith(".lit")) { const sourceMessage = sourceServ.messages.find((message) => message === file);