more things broken for now

- shell now uses the path env variable
- commands run based on permission of the bin file
This commit is contained in:
2026-09-03 12:27:32 +02:00
parent 2715e5e28e
commit 6cc9727091
4 changed files with 35 additions and 14 deletions
+3 -4
View File
@@ -18,7 +18,6 @@ export interface UserInfo {
export interface SessionState {
readonly user: UserInfo;
readonly envVars: ReadonlyMap<string, string>;
readonly history: HistoryState;
readonly cwd: number;
readonly pwd: number;
@@ -28,7 +27,7 @@ export interface SessionState {
export function createInitialSessionState(user: UserInfo): SessionState {
return Object.freeze({
user,
envVars: Object.freeze(new Map()),
//envVars: Object.freeze(new Map()),
history: Object.freeze([]),
cwd: user.home,
pwd: user.home,
@@ -65,7 +64,7 @@ export function login(
const stack = [...state.sessionStack];
stack.push(createInitialSessionState(user));
return createShellState(state.filesystem, state.users, state.groups, stack);
return createShellState(state.filesystem, state.users, state.groups, stack, state.env);
}
export function logout(state: ShellState): ShellState {
@@ -73,7 +72,7 @@ export function logout(state: ShellState): ShellState {
const stack = [...state.sessionStack];
stack.pop();
return createShellState(state.filesystem, state.users, state.groups, stack);
return createShellState(state.filesystem, state.users, state.groups, stack, state.env);
}
return state;
}
+14 -6
View File
@@ -8,6 +8,7 @@ export interface ShellState {
readonly users: ReadonlyMap<number, UserInfo>;
readonly groups: ReadonlyMap<number, GroupInfo>;
readonly sessionStack: ReadonlyArray<SessionState>;
readonly env: ReadonlyMap<string, string>;
}
export function createInitialShellState(
@@ -15,12 +16,14 @@ export function createInitialShellState(
users: ReadonlyMap<number, UserInfo>,
groups: ReadonlyMap<number, GroupInfo>,
user: UserInfo,
env: ReadonlyMap<string, string>,
): ShellState {
return Object.freeze({
filesystem,
users,
groups,
sessionStack: Object.freeze([createInitialSessionState(user)]),
env,
});
}
@@ -29,12 +32,14 @@ export function createShellState(
users: ReadonlyMap<number, UserInfo>,
groups: ReadonlyMap<number, GroupInfo>,
sessionStack: ReadonlyArray<SessionState>,
env: ReadonlyMap<string, string>,
): ShellState {
return Object.freeze({
filesystem,
users,
groups,
sessionStack: Object.freeze(sessionStack),
env,
});
}
@@ -43,7 +48,7 @@ export function withCwd(state: ShellState, inode: number): ShellState {
const newSession = Object.freeze({
user: session.user,
envVars: Object.freeze(session.envVars),
//envVars: Object.freeze(session.envVars),
history: Object.freeze(session.history),
cwd: inode,
pwd: session.cwd,
@@ -59,6 +64,7 @@ export function withCwd(state: ShellState, inode: number): ShellState {
users: state.users,
groups: state.groups,
sessionStack: Object.freeze(sessionStack),
env: state.env,
} satisfies ShellState);
}
@@ -67,7 +73,7 @@ export function withHistory(state: ShellState, input: string): ShellState {
const newSession = Object.freeze({
user: session.user,
envVars: Object.freeze(session.envVars),
//envVars: Object.freeze(session.envVars),
history: Object.freeze(addHistoryEntry(session.history, input)),
cwd: session.cwd,
pwd: session.pwd,
@@ -83,10 +89,11 @@ export function withHistory(state: ShellState, input: string): ShellState {
users: state.users,
groups: state.groups,
sessionStack: Object.freeze(sessionStack),
env: state.env,
} satisfies ShellState);
}
export function withEnv(state: ShellState, key: string, value: string): ShellState {
/* export function withEnv(state: ShellState, key: string, value: string): ShellState {
const session = getCurrentSession(state);
const envVars = new Map(session.envVars);
@@ -94,7 +101,7 @@ export function withEnv(state: ShellState, key: string, value: string): ShellSta
const newSession = Object.freeze({
user: session.user,
envVars: Object.freeze(envVars),
//envVars: Object.freeze(envVars),
history: Object.freeze(session.history),
cwd: session.cwd,
pwd: session.pwd,
@@ -111,14 +118,14 @@ export function withEnv(state: ShellState, key: string, value: string): ShellSta
groups: state.groups,
sessionStack: Object.freeze(sessionStack),
} satisfies ShellState);
}
} */
export function withExitCode(state: ShellState, exitCode: number): ShellState {
const session = getCurrentSession(state);
const newSession = Object.freeze({
user: session.user,
envVars: Object.freeze(session.envVars),
//envVars: Object.freeze(session.envVars),
history: Object.freeze(session.history),
cwd: session.cwd,
pwd: session.pwd,
@@ -134,5 +141,6 @@ export function withExitCode(state: ShellState, exitCode: number): ShellState {
users: state.users,
groups: state.groups,
sessionStack: Object.freeze(sessionStack),
env: state.env,
} satisfies ShellState);
}