more chdir wip

This commit is contained in:
minjaesong
2020-11-07 17:33:54 +09:00
parent 954307a7f9
commit f01345fb6f
4 changed files with 26 additions and 1 deletions

View File

@@ -138,9 +138,22 @@ shell.coreutils = {
return
}
// replace slashes into revslashes
let pathstr = args[1].replaceAll('/','\\\\');
// split them into an array while filtering empty elements except for the root 'head'
let newPwd = [""].concat(pathstr.split("\\").filter(function(it) { return (it.length > 0); }));
// construct new pathstr from pwd arr so it will be sanitised
pathstr = newPwd.join('\\').substring(1);
if (DEBUG_PRINT) serial.println("command.js > pathstr = "+pathstr);
// check if path is valid
let dirOpened = filesystem.open(CURRENT_DRIVE, pathstr, 'R');
if (!dirOpened) { printerrln("CHDIR failed for '"+pathstr+"'"); return; }
// check if path is directory
let isDir = filesystem.isDirectory(CURRENT_DRIVE);
if (!isDir) { printerrln("CHDIR failed for '"+pathstr+"'"); return; }
shell_pwd = newPwd;
},