From 88ef2e05ab7083b4390af60595d57ac6bc1e629c Mon Sep 17 00:00:00 2001 From: minjaesong Date: Thu, 12 Nov 2020 11:11:35 +0900 Subject: [PATCH] command.js: . and .. on path resolving --- assets/tvdos/TVDOS.SYS | 7 +------ assets/tvdos/bin/command.js | 19 ++++++++++++++++++- 2 files changed, 19 insertions(+), 7 deletions(-) diff --git a/assets/tvdos/TVDOS.SYS b/assets/tvdos/TVDOS.SYS index 8a39bb0..a551f3b 100644 --- a/assets/tvdos/TVDOS.SYS +++ b/assets/tvdos/TVDOS.SYS @@ -77,18 +77,13 @@ filesystem.isDirectory = function(driveLetter) { com.sendMessage(port[0], "LISTFILES"); let response = com.getStatusCode(port[0]); - if (135 == response) { - throw Error("File not opened"); - } return (response === 0); } filesystem.mkDir = function(driveLetter) { let port = filesystem._toPorts(driveLetter); com.sendMessage(port[0], "MKDIR"); let response = com.getStatusCode(port[0]); - if (135 == response) { - throw Error("File not opened"); - } + if (response < 0 || response >= 128) { let status = com.getDeviceStatus(port[0]); throw Error("Creating a directory failed with ("+response+"): "+status.message+"\n"); diff --git a/assets/tvdos/bin/command.js b/assets/tvdos/bin/command.js index f286cc4..0c5b604 100644 --- a/assets/tvdos/bin/command.js +++ b/assets/tvdos/bin/command.js @@ -127,9 +127,26 @@ function resolvePathInput(input) { // replace slashes into revslashes let pathstr = input.replaceAll('/','\\\\'); let startsWithSlash = input.startsWith('\\'); + let newPwd = []; // split them into an array while filtering empty elements except for the root 'head' - let newPwd = (startsWithSlash ? [""] : shell_pwd).concat(pathstr.split("\\").filter(function(it) { return (it.length > 0); })); + let ipwd = (startsWithSlash ? [""] : shell_pwd).concat(pathstr.split("\\").filter(function(it) { return (it.length > 0); })); + + serial.println("command.js > resolvePathInput > ipwd = "+ipwd); + serial.println("command.js > resolvePathInput > newPwd = "+newPwd); + + // process dots + ipwd.forEach(function(it) { + serial.println("command.js > resolvePathInput > ipwd.forEach > it = "+it); + if (it === ".." && newPwd[1] !== undefined) { + newPwd.pop(); + } + else if (it !== ".." && it !== ".") { + newPwd.push(it); + } + serial.println("command.js > resolvePathInput > newPwd = "+newPwd); + }); + // construct new pathstr from pwd arr so it will be sanitised pathstr = newPwd.join('\\').substring(1);