switch to using bitflags for rfwfs permissions
This commit is contained in:
parent
56790cbe1d
commit
bb5d24884f
14
src/rt/fs.ts
14
src/rt/fs.ts
@ -7,6 +7,7 @@ const time_now = (Date.now()/1000)|0
|
|||||||
// ------------ Home ------------
|
// ------------ Home ------------
|
||||||
const config = rfwfs.directory(".config", Permissions.rw, time_now)
|
const config = rfwfs.directory(".config", Permissions.rw, time_now)
|
||||||
const local = rfwfs.directory(".local", Permissions.rw, time_now)
|
const local = rfwfs.directory(".local", Permissions.rw, time_now)
|
||||||
|
|
||||||
const downloads = rfwfs.directory("Downloads", Permissions.rw, time_now)
|
const downloads = rfwfs.directory("Downloads", Permissions.rw, time_now)
|
||||||
const pictures = rfwfs.directory("Pictures", Permissions.rw, time_now)
|
const pictures = rfwfs.directory("Pictures", Permissions.rw, time_now)
|
||||||
const desktop = rfwfs.directory("Desktop", Permissions.rw, time_now)
|
const desktop = rfwfs.directory("Desktop", Permissions.rw, time_now)
|
||||||
@ -33,9 +34,10 @@ const vard = rfwfs.directory("var", Permissions.r, time_now)
|
|||||||
const etc = rfwfs.directory("etc", Permissions.r, time_now)
|
const etc = rfwfs.directory("etc", Permissions.r, time_now)
|
||||||
// ------------
|
// ------------
|
||||||
|
|
||||||
export default rfwfs.directory("/", Permissions.r, time_now, [
|
const fs = new rfwfs([
|
||||||
bin,
|
|
||||||
home,
|
])
|
||||||
vard,
|
|
||||||
etc,
|
rfwfs.directory("bin", Permissions.r, fs, time_now)
|
||||||
])
|
|
||||||
|
export default fs
|
@ -1,52 +0,0 @@
|
|||||||
type ConstEnum = number
|
|
||||||
|
|
||||||
const enum EntryType {
|
|
||||||
Root,
|
|
||||||
File,
|
|
||||||
Directory,
|
|
||||||
Binary,
|
|
||||||
}
|
|
||||||
|
|
||||||
const enum Permissions {
|
|
||||||
r,
|
|
||||||
w,
|
|
||||||
x,
|
|
||||||
rw,
|
|
||||||
rwx,
|
|
||||||
rx,
|
|
||||||
wx,
|
|
||||||
none,
|
|
||||||
}
|
|
||||||
|
|
||||||
const enum PushStatus {
|
|
||||||
Ok,
|
|
||||||
Duplicate,
|
|
||||||
Denied,
|
|
||||||
}
|
|
||||||
|
|
||||||
const enum ReadStatus {
|
|
||||||
Ok,
|
|
||||||
NotFound,
|
|
||||||
Denied,
|
|
||||||
}
|
|
||||||
|
|
||||||
const enum ExecuteStatus {
|
|
||||||
Ok,
|
|
||||||
Panic,
|
|
||||||
Denied,
|
|
||||||
}
|
|
||||||
|
|
||||||
const enum Option {
|
|
||||||
Ok,
|
|
||||||
None,
|
|
||||||
}
|
|
||||||
|
|
||||||
export {
|
|
||||||
type ConstEnum,
|
|
||||||
ExecuteStatus,
|
|
||||||
Permissions,
|
|
||||||
PushStatus,
|
|
||||||
ReadStatus,
|
|
||||||
EntryType,
|
|
||||||
Option,
|
|
||||||
}
|
|
@ -1,22 +1,26 @@
|
|||||||
import { ReadStatus } from "./enum"
|
import { ReadStatus } from "./enum"
|
||||||
import { wrap_entry, type WrapResultEntry } from "./wrap"
|
import { wrap_entry, type WrapResultEntry } from "./wrap"
|
||||||
|
|
||||||
import rfwfs, { type DirectoryDepth, type Directory } from "./main"
|
import rfwfs, { type DirectoryAny, type EntryCollection, type DirectoryAnyDepth } from "./main"
|
||||||
import fs from "../fs"
|
import fs from "../fs"
|
||||||
|
|
||||||
type Path = string[]
|
type Path = string[]
|
||||||
|
|
||||||
interface LibHome {
|
interface Home {
|
||||||
goal: (path: Path) => WrapResultEntry<Directory, ReadStatus>
|
|
||||||
path: () => Path,
|
path: () => Path,
|
||||||
get: () => Directory | undefined,
|
dir: () => DirectoryAny | undefined,
|
||||||
|
}
|
||||||
|
interface Librfwfs {
|
||||||
|
home: Home,
|
||||||
|
traverse_to: (path: Path) => WrapResultEntry<DirectoryAny, ReadStatus>
|
||||||
|
pwd_entry: <T extends EntryCollection<T>>(working_dir: T) => Path | undefined
|
||||||
}
|
}
|
||||||
|
|
||||||
let username: string = "user"
|
let username: string = "user"
|
||||||
|
|
||||||
const libhome = {} as LibHome
|
const librfwfs = {} as Librfwfs
|
||||||
|
|
||||||
libhome.goal = function(path) {
|
librfwfs.traverse_to = function(path) {
|
||||||
let traverse = fs
|
let traverse = fs
|
||||||
|
|
||||||
for (const path_name of path) {
|
for (const path_name of path) {
|
||||||
@ -24,7 +28,7 @@ libhome.goal = function(path) {
|
|||||||
|
|
||||||
if (find.status === ReadStatus.Ok) {
|
if (find.status === ReadStatus.Ok) {
|
||||||
if (find.result && rfwfs.is_dir(find.result)) {
|
if (find.result && rfwfs.is_dir(find.result)) {
|
||||||
traverse = find.result as DirectoryDepth
|
traverse = find.result as DirectoryAnyDepth
|
||||||
} else {
|
} else {
|
||||||
return wrap_entry(ReadStatus.Denied)
|
return wrap_entry(ReadStatus.Denied)
|
||||||
}
|
}
|
||||||
@ -35,13 +39,22 @@ libhome.goal = function(path) {
|
|||||||
return wrap_entry(ReadStatus.Ok, traverse)
|
return wrap_entry(ReadStatus.Ok, traverse)
|
||||||
}
|
}
|
||||||
|
|
||||||
libhome.path = function() {
|
librfwfs.pwd_entry = function(working_dir) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
librfwfs.home = {} as Home
|
||||||
|
|
||||||
|
librfwfs.home.path = function() {
|
||||||
return ["home", username]
|
return ["home", username]
|
||||||
}
|
}
|
||||||
|
|
||||||
libhome.get = function() {
|
librfwfs.home.dir = function() {
|
||||||
const traverse = this.goal(this.path())
|
const traverse = librfwfs.traverse_to(this.path())
|
||||||
return traverse.status === ReadStatus.Ok ? traverse.result : undefined
|
return traverse.status === ReadStatus.Ok ? traverse.result : undefined
|
||||||
}
|
}
|
||||||
|
|
||||||
export default libhome
|
export default librfwfs
|
||||||
|
export {
|
||||||
|
username
|
||||||
|
}
|
@ -1,8 +1,36 @@
|
|||||||
import { EntryType, PushStatus, ReadStatus, Permissions, ExecuteStatus } from "./enum"
|
|
||||||
import { wrap_entry, wrap_none, type WrapResultEntry, type WrapResultNone, type WrapBinary, wrap_binary } from "./wrap"
|
import { wrap_entry, wrap_none, type WrapResultEntry, type WrapResultNone, type WrapBinary, wrap_binary } from "./wrap"
|
||||||
|
|
||||||
import directory_search from "./index"
|
import directory_search from "./index"
|
||||||
|
|
||||||
|
const enum EntryType {
|
||||||
|
Root,
|
||||||
|
File,
|
||||||
|
Directory,
|
||||||
|
Binary,
|
||||||
|
}
|
||||||
|
const enum Permissions {
|
||||||
|
r = 1<<0,
|
||||||
|
w = 1<<1,
|
||||||
|
x = 1<<2,
|
||||||
|
none = 1<<3,
|
||||||
|
}
|
||||||
|
|
||||||
|
const enum PushStatus {
|
||||||
|
Ok,
|
||||||
|
Duplicate,
|
||||||
|
Denied,
|
||||||
|
}
|
||||||
|
const enum ReadStatus {
|
||||||
|
Ok,
|
||||||
|
NotFound,
|
||||||
|
Denied,
|
||||||
|
}
|
||||||
|
const enum ExecuteStatus {
|
||||||
|
Ok,
|
||||||
|
Panic,
|
||||||
|
Denied,
|
||||||
|
}
|
||||||
|
|
||||||
type FileInner = string | number
|
type FileInner = string | number
|
||||||
type BinaryError = string
|
type BinaryError = string
|
||||||
|
|
||||||
@ -46,20 +74,17 @@ function strip_entry<T extends Entry>(entry: T): EntryStripped {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function execute_access(permissions: Permissions): boolean {
|
|
||||||
return permissions === Permissions.rwx
|
|
||||||
|| permissions === Permissions.rx
|
|
||||||
|| permissions === Permissions.wx
|
|
||||||
|| permissions === Permissions.x
|
|
||||||
}
|
|
||||||
function read_write_access(permissions: Permissions): boolean {
|
function read_write_access(permissions: Permissions): boolean {
|
||||||
return permissions === Permissions.rw
|
return (permissions & (Permissions.r | Permissions.w)) === (Permissions.r | Permissions.w)
|
||||||
|
}
|
||||||
|
function execute_access(permissions: Permissions): boolean {
|
||||||
|
return (permissions & Permissions.x) !== 0
|
||||||
}
|
}
|
||||||
function read_access(permissions: Permissions): boolean {
|
function read_access(permissions: Permissions): boolean {
|
||||||
return read_write_access(permissions) || permissions === Permissions.r
|
return (permissions & Permissions.r) !== 0
|
||||||
}
|
}
|
||||||
function write_access(permissions: Permissions): boolean {
|
function write_access(permissions: Permissions): boolean {
|
||||||
return read_write_access(permissions) || permissions === Permissions.w
|
return (permissions & Permissions.w) !== 0
|
||||||
}
|
}
|
||||||
|
|
||||||
class EntryValue<T> {
|
class EntryValue<T> {
|
||||||
@ -190,7 +215,7 @@ class rfwfs<T extends Entry> extends rfwfs_static {
|
|||||||
this.root = { type: EntryType.Root, inner: inner }
|
this.root = { type: EntryType.Root, inner: inner }
|
||||||
}
|
}
|
||||||
|
|
||||||
public file(
|
public static file(
|
||||||
default_name: string,
|
default_name: string,
|
||||||
default_permissions: Permissions,
|
default_permissions: Permissions,
|
||||||
default_parent: DirectoryAny,
|
default_parent: DirectoryAny,
|
||||||
@ -207,7 +232,7 @@ class rfwfs<T extends Entry> extends rfwfs_static {
|
|||||||
return file
|
return file
|
||||||
}
|
}
|
||||||
|
|
||||||
public directory<T extends Entry>(
|
public static directory<T extends Entry>(
|
||||||
default_name: string,
|
default_name: string,
|
||||||
default_permissions: Permissions,
|
default_permissions: Permissions,
|
||||||
default_parent: DirectoryAny,
|
default_parent: DirectoryAny,
|
||||||
@ -223,7 +248,7 @@ class rfwfs<T extends Entry> extends rfwfs_static {
|
|||||||
return directory
|
return directory
|
||||||
}
|
}
|
||||||
|
|
||||||
public binary(
|
public static binary(
|
||||||
default_name: string,
|
default_name: string,
|
||||||
default_permissions: Permissions,
|
default_permissions: Permissions,
|
||||||
default_parent: DirectoryAny,
|
default_parent: DirectoryAny,
|
||||||
@ -251,4 +276,9 @@ export {
|
|||||||
type FileInner,
|
type FileInner,
|
||||||
type EntryFile,
|
type EntryFile,
|
||||||
type Entry,
|
type Entry,
|
||||||
|
ExecuteStatus,
|
||||||
|
Permissions,
|
||||||
|
PushStatus,
|
||||||
|
ReadStatus,
|
||||||
|
EntryType,
|
||||||
}
|
}
|
@ -1,5 +1,12 @@
|
|||||||
import { ExecuteStatus, Option, type ConstEnum } from "./enum"
|
|
||||||
import { type BinaryError, type Entry } from "./main"
|
import { type BinaryError, type Entry } from "./main"
|
||||||
|
import { ExecuteStatus } from "./main"
|
||||||
|
|
||||||
|
const enum Option {
|
||||||
|
Ok,
|
||||||
|
None,
|
||||||
|
}
|
||||||
|
|
||||||
|
type ConstEnum = number
|
||||||
|
|
||||||
type WrapResultEntry<T extends Entry, U> = WrapResult<T | undefined, U>
|
type WrapResultEntry<T extends Entry, U> = WrapResult<T | undefined, U>
|
||||||
type WrapBSearch<T extends Entry> = WrapResult<T, number>
|
type WrapBSearch<T extends Entry> = WrapResult<T, number>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user