diff --git a/src/core/command.ts b/src/core/command.ts index a88b625..85fa4f5 100644 --- a/src/core/command.ts +++ b/src/core/command.ts @@ -1,6 +1,6 @@ -import type { ShellError } from "./errors"; import type { Result } from "./result"; import type { ShellState } from "./shell_state"; +import type { ShellError } from "./util/errors"; type CommandFn = (state: ShellState, flags: string[], args: string[]) => CommandOutput; diff --git a/src/core/commands/cd.ts b/src/core/commands/cd.ts index 0dd2882..50f2d7b 100644 --- a/src/core/commands/cd.ts +++ b/src/core/commands/cd.ts @@ -1,16 +1,16 @@ import type { CommandDescriptor, CommandOutput } from "@core/command"; +import type { FileSystem } from "@core/filesystem/filesystem"; +import { createErrorResult, createSuccessResult } from "@core/result"; +import { getCurrentSession } from "@core/session_manager"; +import { ShellState, withCwd } from "@core/shell_state"; import { type InvalidArgumentsError, type PathResolutionError, type PermissionDeniedError, type ShellError, -} from "@core/errors"; -import type { FileSystem } from "@core/filesystem/filesystem"; -import { resolveInode, resolvePath } from "@core/path_resolver"; -import { createErrorResult, createSuccessResult } from "@core/result"; -import { getCurrentSession } from "@core/session"; -import { ShellState, withCwd } from "@core/shell_state"; +} from "@core/util/errors"; import { createImmutableBuffer } from "@core/util/immutable_buffer"; +import { resolveInode, resolvePath } from "@core/util/path_resolver"; export const COMMAND_NAME = "cd"; diff --git a/src/core/commands/echo.ts b/src/core/commands/echo.ts index 8b522aa..c38bd08 100644 --- a/src/core/commands/echo.ts +++ b/src/core/commands/echo.ts @@ -1,7 +1,7 @@ import type { CommandDescriptor, CommandOutput } from "@core/command"; -import type { ShellError } from "@core/errors"; import type { ResultSuccess } from "@core/result"; import type { ShellState } from "@core/shell_state"; +import type { ShellError } from "@core/util/errors"; import { createImmutableBuffer } from "@core/util/immutable_buffer"; export const COMMAND_NAME = "echo"; diff --git a/src/core/filesystem/filesystem.ts b/src/core/filesystem/filesystem.ts index 2d53392..d354d34 100644 --- a/src/core/filesystem/filesystem.ts +++ b/src/core/filesystem/filesystem.ts @@ -1,4 +1,4 @@ -import type { UserInfo } from "@core/user_info"; +import type { UserInfo } from "@core/session_manager"; import { createImmutableBuffer, type ImmutableBuffer } from "@core/util/immutable_buffer"; import { dnTraverseTree, upTraverseTree } from "@core/util/tree_traversal"; import type { diff --git a/src/core/result.ts b/src/core/result.ts index c89d0bd..c72a983 100644 --- a/src/core/result.ts +++ b/src/core/result.ts @@ -1,4 +1,4 @@ -import { createShellError, type ShellError } from "./errors"; +import { createShellError, type ShellError } from "./util/errors"; import { createImmutableBuffer, type ImmutableBuffer } from "./util/immutable_buffer"; export interface ResultError { diff --git a/src/core/session.ts b/src/core/session_manager.ts similarity index 81% rename from src/core/session.ts rename to src/core/session_manager.ts index 04f3627..1a657d5 100644 --- a/src/core/session.ts +++ b/src/core/session_manager.ts @@ -1,6 +1,13 @@ import { type HistoryState } from "./history_state"; import type { ShellState } from "./shell_state"; -import type { UserInfo } from "./user_info"; + +export interface UserInfo { + readonly username: string; + readonly uid: number; + readonly gid: number; + readonly group: readonly number[]; + readonly home: number; +} export interface SessionState { readonly user: UserInfo; diff --git a/src/core/shell_state.ts b/src/core/shell_state.ts index b024d9b..9215b6e 100644 --- a/src/core/shell_state.ts +++ b/src/core/shell_state.ts @@ -1,7 +1,7 @@ import type { FileSystem } from "./filesystem/filesystem"; import { addHistoryEntry } from "./history_state"; -import { createInitialSessionState, getCurrentSession, type SessionState } from "./session"; -import type { UserInfo } from "./user_info"; +import type { UserInfo } from "./session_manager"; +import { createInitialSessionState, getCurrentSession, type SessionState } from "./session_manager"; export interface ShellState { readonly filesystem: FileSystem; diff --git a/src/core/user_info.ts b/src/core/user_info.ts deleted file mode 100644 index b5754be..0000000 --- a/src/core/user_info.ts +++ /dev/null @@ -1,7 +0,0 @@ -export interface UserInfo { - readonly name: string; - readonly uid: number; - readonly gid: number; - readonly group: readonly number[]; - readonly home: number; -} diff --git a/src/core/errors.ts b/src/core/util/errors.ts similarity index 95% rename from src/core/errors.ts rename to src/core/util/errors.ts index 95c4eb6..56eecb4 100644 --- a/src/core/errors.ts +++ b/src/core/util/errors.ts @@ -43,8 +43,7 @@ const EXIT_CODE_MAP: Record = { DataFormatError: 65, FileNotFound: 66, UserNotFound: 67, - HostNotFound: 68, - ServiceUnavailable: 69, + LoginError: 68, InternalSoftwareError: 70, OperatingSystemError: 71, SystemFileError: 72, @@ -136,12 +135,9 @@ export interface UserNotFoundError extends ShellError { username: string; } -// ===================== 4. NETWORK / HOST / SERVICE ERRORS (Exit: 68, 69) ===================== - -/** Specified host does not exist or is unreachable (Exit 68 - EX_NOHOST) */ -export interface HostNotFoundError extends ShellError { - errorType: "HostNotFound"; - hostname: string; +export interface LoginError extends ShellError { + errorType: "LoginError"; + user: number; } /** Required service is unavailable (Exit 69 - EX_UNAVAILABLE) */ diff --git a/src/core/path_resolver.ts b/src/core/util/path_resolver.ts similarity index 93% rename from src/core/path_resolver.ts rename to src/core/util/path_resolver.ts index 361d528..ef499c0 100644 --- a/src/core/path_resolver.ts +++ b/src/core/util/path_resolver.ts @@ -1,6 +1,6 @@ -import type { NodeNotFoundError, NotADirectoryError } from "./filesystem/errors"; -import type { FileSystem } from "./filesystem/filesystem"; -import { TreeNodeType, type DirectoryNode, type TreeNode } from "./filesystem/treenode"; +import type { NodeNotFoundError, NotADirectoryError } from "../filesystem/errors"; +import type { FileSystem } from "../filesystem/filesystem"; +import { TreeNodeType, type DirectoryNode, type TreeNode } from "../filesystem/treenode"; export function resolvePath(fs: FileSystem, cwd: number, path: string): number { const isAbsolute = path.startsWith("/"); diff --git a/test/core/commands/cd.test.ts b/test/core/commands/cd.test.ts index 8fb0812..59b9b18 100644 --- a/test/core/commands/cd.test.ts +++ b/test/core/commands/cd.test.ts @@ -1,9 +1,9 @@ import { descriptor as cd } from "@core/commands/cd"; -import type { PathResolutionError } from "@core/errors"; import type { ResultError, ResultSuccess } from "@core/result"; -import { getCurrentSession } from "@core/session"; +import { getCurrentSession } from "@core/session_manager"; import { createInitialShellState, withCwd, type ShellState } from "@core/shell_state"; import type { UserInfo } from "@core/user_info"; +import type { PathResolutionError } from "@core/util/errors"; import { buildTestFS, type FixtureNode } from "@tests/helpers/filesystems_fixture"; import { expect, test } from "vitest"; diff --git a/test/core/path_resolver.test.ts b/test/core/path_resolver.test.ts index 061207c..e3228a4 100644 --- a/test/core/path_resolver.test.ts +++ b/test/core/path_resolver.test.ts @@ -1,4 +1,4 @@ -import { resolveInode, resolvePath } from "@core/path_resolver"; +import { resolveInode, resolvePath } from "@core/util/path_resolver"; import { expectNodeNotFoundError, expectNotADirectoryError } from "@tests/helpers/error_matchers"; import { buildTestFS } from "@tests/helpers/filesystems_fixture"; import { depth7Tree } from "@tests/helpers/tree_fixture"; diff --git a/test/core/session.test.ts b/test/core/session.test.ts index fe4a882..e10dced 100644 --- a/test/core/session.test.ts +++ b/test/core/session.test.ts @@ -1,4 +1,4 @@ -import { createInitialSessionState } from "@core/session"; +import { createInitialSessionState } from "@core/session_manager"; import type { UserInfo } from "@core/user_info"; import { expect, test } from "vitest"; diff --git a/test/core/shell_state.test.ts b/test/core/shell_state.test.ts index b36b232..fd90628 100644 --- a/test/core/shell_state.test.ts +++ b/test/core/shell_state.test.ts @@ -1,6 +1,6 @@ import { FileSystem } from "@core/filesystem/filesystem"; import { TreeNodeType, type DirectoryNode, type TreeNode } from "@core/filesystem/treenode"; -import { getCurrentSession } from "@core/session"; +import { getCurrentSession } from "@core/session_manager"; import { createInitialShellState, withCwd, withEnv, withExitCode, withHistory } from "@core/shell_state"; import type { UserInfo } from "@core/user_info"; import { expect, test } from "vitest";