diff --git a/.zed/settings.json b/.zed/settings.json new file mode 100644 index 0000000..31a49c4 --- /dev/null +++ b/.zed/settings.json @@ -0,0 +1,8 @@ +// Folder-specific settings +// +// For a full list of overridable settings, and general information on folder-specific settings, +// see the documentation: https://zed.dev/docs/configuring-zed#settings-files +{ + "hard_tabs": true, + "tab_size": 4 +} diff --git a/src/rt/rfwfs/fs/library.ts b/src/rt/rfwfs/fs/library.ts index 6257ee6..1c73023 100644 --- a/src/rt/rfwfs/fs/library.ts +++ b/src/rt/rfwfs/fs/library.ts @@ -1,23 +1,59 @@ import { ReadStatus } from "../enum" -import rfwfs, { type EntryCollection, type Entry } from "../main" +import rfwfs, { type EntryCollection, type Entry, RfwfsDirectory } from "../main" +import wrap, { wrap_none, WrapResult, WrapResultEntry, WrapResultNone } from "../wrap" import fs from "./root" +const enum TraverseStatus { + Ok, + Denied, + TargetMissing, + NotFound, +} + let username: string = "user" + const libhome = {} as LibHome interface WorkingDir { entry?: EntryCollection, - path: string[] + } interface LibHome { path: () => string[], get: () => EntryCollection, } -function traverse_to_goal(path: string[]) { - if (working_dir.entry) { +function working_path_result(find: WrapResultEntry, ReadStatus>): WrapResult { + // switch(find.some) { + // case ReadStatus.Ok: { + // return wrap(TraverseStatus.Ok, find.result) + // } + // case ReadStatus.NotFound: { + // } + // case ReadStatus.Denied: { + // } + // } + if (find.some === ReadStatus.Ok) { + if (find.result) { + return wrap(TraverseStatus.Ok) + } else { + } + } else if (find.some === ReadStatus.Denied) { + + } else if (find.some === ReadStatus.NotFound) { + + } + return wrap_none(TraverseStatus.NotFound) +} + +function traverse_to_goal(working_path: string[]) { + let working_dir = fs.inner + + for (const dir_name of working_path) { + const find = working_dir.find(dir_name) + const h = working_path_result(find) } } diff --git a/src/rt/rfwfs/fs/root.ts b/src/rt/rfwfs/fs/root.ts index 524147b..6079ab7 100644 --- a/src/rt/rfwfs/fs/root.ts +++ b/src/rt/rfwfs/fs/root.ts @@ -5,13 +5,14 @@ import rfwfs from "../main" const time_now = (Date.now()/1000)|0 // ------------ Home ------------ -const config = rfwfs.directory(".config", Permissions.rw, time_now) -const local = rfwfs.directory(".local", Permissions.rw, time_now) -const downloads = rfwfs.directory("Downloads", Permissions.rw, time_now) -const pictures = rfwfs.directory("Pictures", Permissions.rw, time_now) -const desktop = rfwfs.directory("Desktop", Permissions.rw, time_now) -const videos = rfwfs.directory("Videos", Permissions.rw, time_now) -const music = rfwfs.directory("Music", Permissions.rw, time_now) +const + config = rfwfs.directory(".config", Permissions.rw, time_now), + local = rfwfs.directory(".local", Permissions.rw, time_now), + downloads = rfwfs.directory("Downloads", Permissions.rw, time_now), + pictures = rfwfs.directory("Pictures", Permissions.rw, time_now), + desktop = rfwfs.directory("Desktop", Permissions.rw, time_now), + videos = rfwfs.directory("Videos", Permissions.rw, time_now), + music = rfwfs.directory("Music", Permissions.rw, time_now); const user = rfwfs.directory("user", Permissions.r, time_now, [ config, diff --git a/src/rt/rfwfs/result.ts b/src/rt/rfwfs/result.ts new file mode 100644 index 0000000..94fcbce --- /dev/null +++ b/src/rt/rfwfs/result.ts @@ -0,0 +1,24 @@ +const enum Status { + Ok, + Err +} + +type OkResult = [Status.Ok, T]; +type ErrResult = [Status.Err, T] + +type Result = OkResult | ErrResult; + +const Ok = (value: T) => [Status.Ok, value] satisfies OkResult; +const Err = (value: T) => [Status.Err, value] satisfies ErrResult; + +const execute = (value: T): Result => { + return Math.random() > 0.5 ? Ok(value) : Err(new Error("boom")); +} + +const result = execute("whatever"); + +if (result[0] === Status.Ok) { + const value = result[1]; // it have to be string +} else { + const value = result[1]; // it have to be error +} \ No newline at end of file