Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
8f93f3e43f |
@@ -25,7 +25,8 @@ It doesnt implement a website friendly interface on its own. Thats one of the de
|
|||||||
[ref2]: https://pnpm.io/installation
|
[ref2]: https://pnpm.io/installation
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
git clone https://git.gornodox.dev/ChaosMaker/termos.git
|
wget https://git.gornodox.dev/ChaosMaker/termos/archive/unstable-async.zip
|
||||||
|
unzip -d termos unstable-async.zip
|
||||||
cd termos
|
cd termos
|
||||||
npm install
|
npm install
|
||||||
```
|
```
|
||||||
|
|||||||
@@ -6,12 +6,14 @@ import { descriptor as echo } from "./commands/echo";
|
|||||||
import { descriptor as ls } from "./commands/ls";
|
import { descriptor as ls } from "./commands/ls";
|
||||||
import { descriptor as pwd } from "./commands/pwd";
|
import { descriptor as pwd } from "./commands/pwd";
|
||||||
import { descriptor as testasync } from "./commands/testasync";
|
import { descriptor as testasync } from "./commands/testasync";
|
||||||
|
import { descriptor as touch } from "./commands/touch";
|
||||||
|
|
||||||
const reg = new Map<string, CommandDescriptor>();
|
const reg = new Map<string, CommandDescriptor>();
|
||||||
//reg.set(descriptor.name, descriptor <- imported const from command implementation file);
|
//reg.set(descriptor.name, descriptor <- imported const from command implementation file);
|
||||||
reg.set(echo.name, echo);
|
reg.set(echo.name, echo);
|
||||||
reg.set(cd.name, cd);
|
reg.set(cd.name, cd);
|
||||||
reg.set(testasync.name, testasync);
|
reg.set(testasync.name, testasync);
|
||||||
|
reg.set(touch.name, touch);
|
||||||
reg.set(ls.name, ls);
|
reg.set(ls.name, ls);
|
||||||
reg.set(cat.name, cat);
|
reg.set(cat.name, cat);
|
||||||
reg.set(pwd.name, pwd);
|
reg.set(pwd.name, pwd);
|
||||||
|
|||||||
@@ -219,8 +219,10 @@ async function main(io: CommandIO, state: ShellState, args: string[]): Promise<C
|
|||||||
entries.push({ ptr: session.cwd, path: "." });
|
entries.push({ ptr: session.cwd, path: "." });
|
||||||
} else {
|
} else {
|
||||||
for (const path of paths) {
|
for (const path of paths) {
|
||||||
const ptr = resolvePath(state, path);
|
let ptr;
|
||||||
if (!state.filesystem.exists(ptr)) {
|
try {
|
||||||
|
ptr = resolvePath(state, path);
|
||||||
|
} catch {
|
||||||
return {
|
return {
|
||||||
state,
|
state,
|
||||||
result: createErrorResult(
|
result: createErrorResult(
|
||||||
|
|||||||
+24
-24
@@ -1,44 +1,44 @@
|
|||||||
import type { CommandDescriptor, CommandOutput } from "@core/command";
|
import type { CommandDescriptor, CommandOutput } from "@core/command";
|
||||||
import type { CommandIO } from "@core/command_io";
|
import type { CommandIO } from "@core/command_io";
|
||||||
import { createSuccessResult, type ResultSuccess } from "@core/result";
|
import { NodeType } from "@core/filesystem/node";
|
||||||
|
import { createErrorResult, createSuccessResult, type ResultSuccess } from "@core/result";
|
||||||
import { getCurrentSession } from "@core/session_manager";
|
import { getCurrentSession } from "@core/session_manager";
|
||||||
import type { ShellState } from "@core/shell_state";
|
import type { ShellState } from "@core/shell_state";
|
||||||
import type { ShellError } from "@core/util/errors";
|
import type { ShellError } from "@core/util/errors";
|
||||||
import { resolvePath } from "@core/util/path_resolver";
|
import { resolvePath } from "@core/util/path_resolver";
|
||||||
|
import { Blob } from "node:buffer";
|
||||||
|
|
||||||
export const COMMAND_NAME = "touch";
|
export const COMMAND_NAME = "touch";
|
||||||
|
|
||||||
//Need to implement escape sequences
|
//Need to implement escape sequences
|
||||||
async function main(io: CommandIO, state: ShellState, args: string[]): Promise<CommandOutput<ShellError>> {
|
async function main(io: CommandIO, state: ShellState, args: string[]): Promise<CommandOutput<ShellError>> {
|
||||||
|
const session = getCurrentSession(state);
|
||||||
|
|
||||||
for (const arg of args) {
|
for (const arg of args) {
|
||||||
const inode = resolvePath(state, arg);
|
try {
|
||||||
const session = getCurrentSession(state);
|
resolvePath(state, arg);
|
||||||
|
} catch {
|
||||||
let newState;
|
|
||||||
|
|
||||||
if (inode === -1) {
|
|
||||||
const index = arg.lastIndexOf("/");
|
const index = arg.lastIndexOf("/");
|
||||||
let parentPath;
|
|
||||||
if (index === -1) {
|
|
||||||
parentPath = "./";
|
|
||||||
} else {
|
|
||||||
parentPath = arg.slice(0, index);
|
|
||||||
}
|
|
||||||
const fileName = arg.slice(index + 1);
|
const fileName = arg.slice(index + 1);
|
||||||
const parent = resolvePath(state, parentPath);
|
const parentPath = index === -1 ? "./" : arg.slice(0, index + 1);
|
||||||
|
const pptr = resolvePath(state, parentPath);
|
||||||
|
|
||||||
newState = state.filesystem.createNode(
|
state.filesystem.createNode(pptr, fileName, {
|
||||||
parent,
|
type: NodeType.File,
|
||||||
fileName,
|
mode: 0o644,
|
||||||
TreeNodeType.File,
|
owner: session.user.uid,
|
||||||
0o644,
|
group: session.user.gid,
|
||||||
session.user.uid,
|
content: new Blob(),
|
||||||
session.user.gid,
|
size: 0,
|
||||||
);
|
});
|
||||||
} else {
|
|
||||||
|
continue;
|
||||||
}
|
}
|
||||||
|
return {
|
||||||
|
state,
|
||||||
|
result: createErrorResult("AlreadyExists", "The file already exists", {}),
|
||||||
|
} satisfies CommandOutput<ShellError>;
|
||||||
}
|
}
|
||||||
|
|
||||||
const result: ResultSuccess = createSuccessResult(COMMAND_NAME);
|
const result: ResultSuccess = createSuccessResult(COMMAND_NAME);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ import { NodeType, type DirectoryNode, type FileNode, type Node, type SymlinkNod
|
|||||||
|
|
||||||
export function deserializeFileSystem(json: string): { dstore: IDataStore; mstore: IMetaStore; config: VDiskConfig }[] {
|
export function deserializeFileSystem(json: string): { dstore: IDataStore; mstore: IMetaStore; config: VDiskConfig }[] {
|
||||||
const raw = JSON.parse(json);
|
const raw = JSON.parse(json);
|
||||||
|
let index = 0;
|
||||||
|
|
||||||
// prettier-ignore
|
// prettier-ignore
|
||||||
function parseNode(tree: any, parent: number, store: MemDataStore, map: Map<number, Node>): void { // eslint-disable-line @typescript-eslint/no-explicit-any
|
function parseNode(tree: any, parent: number, store: MemDataStore, map: Map<number, Node>): void { // eslint-disable-line @typescript-eslint/no-explicit-any
|
||||||
@@ -31,6 +32,8 @@ export function deserializeFileSystem(json: string): { dstore: IDataStore; mstor
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(tree.inode > index) index = tree.inode;
|
||||||
|
|
||||||
switch(tree.type) {
|
switch(tree.type) {
|
||||||
case "directory": {
|
case "directory": {
|
||||||
const children: Map<string, number> = new Map();
|
const children: Map<string, number> = new Map();
|
||||||
@@ -121,7 +124,7 @@ export function deserializeFileSystem(json: string): { dstore: IDataStore; mstor
|
|||||||
const config: VDiskConfig = {
|
const config: VDiskConfig = {
|
||||||
id: dev.id,
|
id: dev.id,
|
||||||
label: `disk-${dev.id}`,
|
label: `disk-${dev.id}`,
|
||||||
index: 0,
|
index,
|
||||||
readonly: false,
|
readonly: false,
|
||||||
size: 1024 * 1024 * 1024 * 8, //8 GiB
|
size: 1024 * 1024 * 1024 * 8, //8 GiB
|
||||||
base: map,
|
base: map,
|
||||||
|
|||||||
Reference in New Issue
Block a user