phase 3
This commit is contained in:
@@ -497,7 +497,7 @@ export class FileSystem {
|
|||||||
return FileSystem.init(this._BaseFS, newOverlay, this._INodeIndex);
|
return FileSystem.init(this._BaseFS, newOverlay, this._INodeIndex);
|
||||||
}
|
}
|
||||||
|
|
||||||
public canRead(inode: number, user: { uid: number; gid: number }): boolean {
|
public canRead(inode: number, user: UserInfo): boolean {
|
||||||
const node = this.resolveNode(inode);
|
const node = this.resolveNode(inode);
|
||||||
if (node === undefined) {
|
if (node === undefined) {
|
||||||
throw {
|
throw {
|
||||||
@@ -519,7 +519,7 @@ export class FileSystem {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public canWrite(inode: number, user: { uid: number; gid: number }): boolean {
|
public canWrite(inode: number, user: UserInfo): boolean {
|
||||||
const node = this.resolveNode(inode);
|
const node = this.resolveNode(inode);
|
||||||
if (node === undefined) {
|
if (node === undefined) {
|
||||||
throw {
|
throw {
|
||||||
@@ -541,7 +541,7 @@ export class FileSystem {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public canExecute(inode: number, user: { uid: number; gid: number }): boolean {
|
public canExecute(inode: number, user: UserInfo): boolean {
|
||||||
const node = this.resolveNode(inode);
|
const node = this.resolveNode(inode);
|
||||||
if (node === undefined) {
|
if (node === undefined) {
|
||||||
throw {
|
throw {
|
||||||
|
|||||||
@@ -0,0 +1,10 @@
|
|||||||
|
import type { FileSystem } from "./filesystem/filesystem";
|
||||||
|
|
||||||
|
interface ShellState {
|
||||||
|
readonly filesystem: FileSystem;
|
||||||
|
readonly users: ReadonlyMap<number, UserInfo>;
|
||||||
|
readonly currentUid: number;
|
||||||
|
readonly envVars: ReadonlyMap<string, string>;
|
||||||
|
readonly cwd: number;
|
||||||
|
readonly pwd: number;
|
||||||
|
}
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
interface UserInfo {
|
||||||
|
readonly uid: number;
|
||||||
|
readonly gid: number;
|
||||||
|
readonly group: readonly number[];
|
||||||
|
readonly home: number;
|
||||||
|
}
|
||||||
@@ -1,2 +1,42 @@
|
|||||||
const message: string = "Hello, World!";
|
const message: string = "Hello, World!";
|
||||||
console.log(message);
|
console.log(message);
|
||||||
|
|
||||||
|
function parse(input: string) {
|
||||||
|
let buffer: string[] = [];
|
||||||
|
const tokens: string[] = [];
|
||||||
|
let state: string = "";
|
||||||
|
let escape = false;
|
||||||
|
|
||||||
|
for (const char of input) {
|
||||||
|
if (state.length === 0) {
|
||||||
|
if (char === " ") {
|
||||||
|
tokens.push(buffer.join(""));
|
||||||
|
buffer = [];
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (char === "'" || char === '"') {
|
||||||
|
state = char;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
buffer.push(char);
|
||||||
|
continue;
|
||||||
|
} else {
|
||||||
|
if (char === state) {
|
||||||
|
state = "";
|
||||||
|
tokens.push(buffer.join(""));
|
||||||
|
buffer = [];
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (char === "\\") {
|
||||||
|
escape = true;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
buffer.push(char);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
tokens.push(buffer.join(""));
|
||||||
|
return tokens;
|
||||||
|
}
|
||||||
|
|
||||||
|
console.log(parse('"Hello World"'));
|
||||||
|
|||||||
Reference in New Issue
Block a user