mirror of
https://github.com/curioustorvald/tsvm.git
synced 2026-06-09 22:54:03 +09:00
more chdir wip
This commit is contained in:
@@ -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;
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user