diff --git a/src/rt/rfwfs/fs/root.ts b/src/rt/fs.ts similarity index 93% rename from src/rt/rfwfs/fs/root.ts rename to src/rt/fs.ts index 524147b..74f3199 100644 --- a/src/rt/rfwfs/fs/root.ts +++ b/src/rt/fs.ts @@ -1,6 +1,6 @@ -import { Permissions } from "../enum" +import { Permissions } from "./rfwfs/enum" -import rfwfs from "../main" +import rfwfs from "./rfwfs/main" const time_now = (Date.now()/1000)|0 diff --git a/src/rt/rfwfs/fs/library.ts b/src/rt/rfwfs/fs/library.ts deleted file mode 100644 index 6257ee6..0000000 --- a/src/rt/rfwfs/fs/library.ts +++ /dev/null @@ -1,30 +0,0 @@ -import { ReadStatus } from "../enum" -import rfwfs, { type EntryCollection, type Entry } from "../main" - -import fs from "./root" - -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) { - - } -} - -libhome.path = function() { - return ["home", username] -} - -libhome.get = function() { - -} \ No newline at end of file diff --git a/src/rt/rfwfs/library.ts b/src/rt/rfwfs/library.ts new file mode 100644 index 0000000..43d7d69 --- /dev/null +++ b/src/rt/rfwfs/library.ts @@ -0,0 +1,47 @@ +import { ReadStatus } from "./enum" +import { wrap_entry, type WrapResultEntry } from "./wrap" + +import rfwfs, { type DirectoryDepth, type Directory } from "./main" +import fs from "../fs" + +type Path = string[] + +interface LibHome { + goal: (path: Path) => WrapResultEntry + path: () => Path, + get: () => Directory | undefined, +} + +let username: string = "user" + +const libhome = {} as LibHome + +libhome.goal = function(path) { + let traverse = fs + + for (const path_name of path) { + const find = traverse.inner.find(path_name) + + if (find.status === ReadStatus.Ok) { + if (find.result && rfwfs.is_dir(find.result)) { + traverse = find.result as DirectoryDepth + } else { + return wrap_entry(ReadStatus.Denied) + } + } else { + return wrap_entry(find.status) + } + } + return wrap_entry(ReadStatus.Ok, traverse) +} + +libhome.path = function() { + return ["home", username] +} + +libhome.get = function() { + const traverse = this.goal(this.path()) + return traverse.status === ReadStatus.Ok ? traverse.result : undefined +} + +export default libhome \ No newline at end of file