mirror of
https://github.com/curioustorvald/tsvm.git
synced 2026-03-07 19:51:51 +09:00
command.js: . and .. on path resolving
This commit is contained in:
@@ -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");
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user