|
|
|
@ -1,5 +1,4 @@
|
|
|
|
|
import { ReadStatus, PushStatus, ExecuteStatus } from "./enum/status"
|
|
|
|
|
import { wrap_entry, wrap_none, wrap_binary, type WrapResultEntry, type WrapResultNone, type WrapBinary } from "./wrap"
|
|
|
|
|
import wrap, { type WrapResult, ConstEnum, Option } from "./wrap"
|
|
|
|
|
|
|
|
|
|
import directory_search from "./index"
|
|
|
|
|
|
|
|
|
@ -15,230 +14,192 @@ const enum Permissions {
|
|
|
|
|
x = 1<<2,
|
|
|
|
|
none = 1<<3,
|
|
|
|
|
}
|
|
|
|
|
const enum ROOT_ID { TRUNK = "/" }
|
|
|
|
|
const enum ROOT_ID {
|
|
|
|
|
TRUNK = "/",
|
|
|
|
|
NAME = "root"
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
type FileInner = string | number
|
|
|
|
|
type BinaryError = string
|
|
|
|
|
const enum PushStatus {
|
|
|
|
|
Ok,
|
|
|
|
|
Duplicate,
|
|
|
|
|
Denied,
|
|
|
|
|
}
|
|
|
|
|
const enum ReadStatus {
|
|
|
|
|
Ok,
|
|
|
|
|
NotFound,
|
|
|
|
|
Denied,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
type BinaryEntry = () => EntryStripped
|
|
|
|
|
type BinaryLambda = (binary_entry: BinaryEntry) => void
|
|
|
|
|
interface UserPermissions {
|
|
|
|
|
readonly root: Permissions.r | Permissions.w | Permissions.x, //Flip OR
|
|
|
|
|
[index: string]: Permissions
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
type Directory<T extends Entry> = EntryCollection<T>
|
|
|
|
|
type DirectoryAny = EntryCollection<Entry>
|
|
|
|
|
type DirectoryAnyDepth = EntryCollection<DirectoryAny>
|
|
|
|
|
interface Entry<T extends EntryType = EntryType, N = EntryValue<string>> {
|
|
|
|
|
readonly type: T,
|
|
|
|
|
permissions: UserPermissions,
|
|
|
|
|
timestamp: number,
|
|
|
|
|
name: N
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
interface EntryStripped {
|
|
|
|
|
readonly type: EntryType,
|
|
|
|
|
interface DirectoryContainer<T> extends Entry {
|
|
|
|
|
files: EntryValue<Entry[]>,
|
|
|
|
|
parent: T | null
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
type Directory<T extends Entry> = DirectoryContainer<RfwfsDirectory<T>>
|
|
|
|
|
type DirectoryInRoot = DirectoryContainer<Root>
|
|
|
|
|
|
|
|
|
|
interface Root extends Entry<EntryType.Root, ROOT_ID.TRUNK> {
|
|
|
|
|
timestamp: number,
|
|
|
|
|
parent: null,
|
|
|
|
|
files: EntryValue<Entry[]>,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
interface DirectoryInRootProperties {
|
|
|
|
|
permissions: Permissions,
|
|
|
|
|
timestamp: EntryValue<number>,
|
|
|
|
|
name: EntryValue<string>,
|
|
|
|
|
name: string
|
|
|
|
|
timestamp: number,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
interface Entry<T = DirectoryAny | null> extends EntryStripped {
|
|
|
|
|
parent: T,
|
|
|
|
|
interface DirectoryProperties<T extends Entry> extends DirectoryInRootProperties {
|
|
|
|
|
parent: RfwfsDirectory<T>,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
interface EntryFile extends Entry {
|
|
|
|
|
inner: EntryValue<FileInner>,
|
|
|
|
|
hash: string,
|
|
|
|
|
interface FileProperties extends Entry {
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
interface EntryCollection<T extends Entry> extends Entry {
|
|
|
|
|
inner: RfwfsDirectory<T>,
|
|
|
|
|
/** Other directory types that can be treated as a single arbitrary directory.
|
|
|
|
|
|
|
|
|
|
Do not cast.
|
|
|
|
|
*/
|
|
|
|
|
type DirectoryAssociates<T extends Entry> = Directory<T> | DirectoryInRoot | Root
|
|
|
|
|
/** Other entry types that can be treated as a single arbitrary entry.
|
|
|
|
|
|
|
|
|
|
Do not cast.
|
|
|
|
|
*/
|
|
|
|
|
type EntryAssociates = Entry | Root
|
|
|
|
|
|
|
|
|
|
type WrapResultEntry<T extends Entry, U> = WrapResult<T | undefined, U>
|
|
|
|
|
type WrapResultNone<T> = WrapResult<Option.None, T>
|
|
|
|
|
|
|
|
|
|
function wrap_entry<T extends ConstEnum, U extends Entry>(status: T, result?: U): WrapResultEntry<U, T> {
|
|
|
|
|
return wrap(result, status)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
interface EntryBinary extends Entry {
|
|
|
|
|
inner: RfwfsBinary
|
|
|
|
|
function wrap_none<T extends ConstEnum>(status: T): WrapResultNone<T> {
|
|
|
|
|
return wrap(Option.None, status)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
interface Root<T extends Entry> {
|
|
|
|
|
readonly type: EntryType,
|
|
|
|
|
readonly permissions: Permissions,
|
|
|
|
|
readonly timestamp: EntryValueRoot<number>,
|
|
|
|
|
readonly parent: null,
|
|
|
|
|
readonly inner: RfwfsRootDirectory<T>,
|
|
|
|
|
readonly name: ROOT_ID.TRUNK,
|
|
|
|
|
function fs_dir_sort<T extends Entry>(dir: DirectoryAssociates<T>) {
|
|
|
|
|
dir.files.inner.sort((a,z) => a.name.inner.localeCompare(z.name.inner))
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function strip_entry<T extends Entry>(entry: T): EntryStripped {
|
|
|
|
|
return {
|
|
|
|
|
type: entry.type,
|
|
|
|
|
permissions: entry.permissions,
|
|
|
|
|
timestamp: entry.timestamp,
|
|
|
|
|
name: entry.name,
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function fs_dir_clone<T extends Entry>(directory: T[], file_name: string): WrapResultEntry<T, ReadStatus> {
|
|
|
|
|
const clone_find = directory_search(directory, file_name)
|
|
|
|
|
function fs_dir_clone<T extends Entry>(dir: DirectoryAssociates<T>, file_name: string): WrapResultEntry<T, ReadStatus> {
|
|
|
|
|
const clone_find = directory_search(dir.files.inner, file_name)
|
|
|
|
|
if (clone_find) {
|
|
|
|
|
return wrap_entry(ReadStatus.Ok, { ...clone_find.result })
|
|
|
|
|
return wrap_entry(ReadStatus.Ok, { ...clone_find.result as T })
|
|
|
|
|
}
|
|
|
|
|
return wrap_entry(ReadStatus.NotFound)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function fs_dir_find<T extends Entry>(directory: T[], file_name: string): WrapResultEntry<T, ReadStatus> {
|
|
|
|
|
const file_search = directory_search(directory, file_name)
|
|
|
|
|
function fs_dir_find<T extends Entry>(dir: DirectoryAssociates<T>, file_name: string): WrapResultEntry<T, ReadStatus> {
|
|
|
|
|
const file_search = directory_search(dir.files.inner, file_name)
|
|
|
|
|
if (file_search) {
|
|
|
|
|
return wrap_entry(ReadStatus.Ok, file_search.result)
|
|
|
|
|
return wrap_entry(ReadStatus.Ok, file_search.result as T)
|
|
|
|
|
}
|
|
|
|
|
return wrap_entry(ReadStatus.NotFound)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function fs_dir_push<T extends Entry, E extends T>(directory: T[], entry: E) {
|
|
|
|
|
const no_duplicates = directory_search(directory, entry.name.inner)
|
|
|
|
|
function fs_dir_push<T extends Entry>(dir: DirectoryAssociates<T>, entry: Entry) {
|
|
|
|
|
const no_duplicates = directory_search(dir.files.inner, entry.name.inner)
|
|
|
|
|
if (!no_duplicates) {
|
|
|
|
|
directory.push(entry)
|
|
|
|
|
directory.sort()
|
|
|
|
|
dir.files.inner.push(entry)
|
|
|
|
|
fs_dir_sort(dir)
|
|
|
|
|
return wrap_none(PushStatus.Ok)
|
|
|
|
|
}
|
|
|
|
|
return wrap_none(PushStatus.Duplicate)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function fs_dir_pop<T extends Entry>(directory: T[], file_name: string): WrapResultEntry<T, ReadStatus> {
|
|
|
|
|
const pop_find = directory_search(directory, file_name)
|
|
|
|
|
function fs_dir_pop<T extends Entry>(dir: DirectoryAssociates<T>, file_name: string): WrapResultEntry<T, ReadStatus> {
|
|
|
|
|
const pop_find = directory_search(dir.files.inner, file_name)
|
|
|
|
|
if (pop_find) {
|
|
|
|
|
directory.splice(pop_find.status, 1)
|
|
|
|
|
return wrap_entry(ReadStatus.Ok, pop_find.result)
|
|
|
|
|
dir.files.inner.splice(pop_find.status, 1)
|
|
|
|
|
return wrap_entry(ReadStatus.Ok, pop_find.result as T)
|
|
|
|
|
}
|
|
|
|
|
return wrap_entry(ReadStatus.NotFound)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
class EntryValue<T> {
|
|
|
|
|
public inner: T;
|
|
|
|
|
protected entry: Entry;
|
|
|
|
|
class EntryValue<V> {
|
|
|
|
|
public inner: V;
|
|
|
|
|
protected user_perms: UserPermissions;
|
|
|
|
|
|
|
|
|
|
constructor(entry: Entry, inner_default: T) {
|
|
|
|
|
this.inner = inner_default
|
|
|
|
|
this.entry = entry
|
|
|
|
|
constructor(user: UserPermissions, value: V) {
|
|
|
|
|
this.inner = value
|
|
|
|
|
this.user_perms = user
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
Safe write
|
|
|
|
|
*/
|
|
|
|
|
public write<I extends T>(item: I): boolean {
|
|
|
|
|
if (rfwfs.write_access(this.entry.permissions)) {
|
|
|
|
|
this.inner = item
|
|
|
|
|
public read(): V | undefined {
|
|
|
|
|
return rfwfs_lib.read_access(this.user_perms.permissions) ? this.inner : undefined
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public write<T extends V>(new_value: T): boolean {
|
|
|
|
|
if (rfwfs_lib.write_access(this.user_perms.permissions)) {
|
|
|
|
|
this.inner = new_value
|
|
|
|
|
return true
|
|
|
|
|
}
|
|
|
|
|
return false
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
Convert the inner file value
|
|
|
|
|
|
|
|
|
|
Same as `write` but mutates the inner value `T` into a `FileInner`
|
|
|
|
|
*/
|
|
|
|
|
public write_into(item: FileInner): boolean {
|
|
|
|
|
return this.write(item as T)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public read(): T | undefined {
|
|
|
|
|
return rfwfs.write_access(this.entry.permissions) ? this.inner : undefined
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
class EntryValueRoot<T> {
|
|
|
|
|
protected inner: T;
|
|
|
|
|
|
|
|
|
|
constructor(inner: T) {
|
|
|
|
|
this.inner = inner
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public read(): T {
|
|
|
|
|
return this.inner
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
class RfwfsDirectory<T extends Entry> {
|
|
|
|
|
public directory: T[];
|
|
|
|
|
protected entry: Entry;
|
|
|
|
|
public dir: DirectoryAssociates<T>;
|
|
|
|
|
|
|
|
|
|
constructor(entry: Entry, directory: T[]) {
|
|
|
|
|
this.directory = directory
|
|
|
|
|
this.entry = entry
|
|
|
|
|
constructor(dir: DirectoryAssociates<T>) {
|
|
|
|
|
this.dir = dir
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public sort() {
|
|
|
|
|
this.directory.sort((a,z) => a.name.inner.localeCompare(z.name.inner))
|
|
|
|
|
fs_dir_sort(this.dir)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public clone(file_name: string): WrapResultEntry<T, ReadStatus> {
|
|
|
|
|
if (rfwfs.read_write_access(this.entry.permissions)) {
|
|
|
|
|
return fs_dir_clone(this.directory, file_name)
|
|
|
|
|
public clone(file_name: string): WrapResultEntry<Entry, ReadStatus> {
|
|
|
|
|
if (rfwfs.read_write_access(this.dir.permissions)) {
|
|
|
|
|
return fs_dir_clone(this.dir, file_name)
|
|
|
|
|
}
|
|
|
|
|
return wrap_entry(ReadStatus.Denied)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public find(file_name: string): WrapResultEntry<T, ReadStatus> {
|
|
|
|
|
if (rfwfs.read_write_access(this.entry.permissions)) {
|
|
|
|
|
return fs_dir_find(this.directory, file_name)
|
|
|
|
|
public find(file_name: string): WrapResultEntry<Entry, ReadStatus> {
|
|
|
|
|
if (rfwfs.read_write_access(this.dir.permissions)) {
|
|
|
|
|
return fs_dir_find(this.dir, file_name)
|
|
|
|
|
}
|
|
|
|
|
return wrap_entry(ReadStatus.Denied)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public push<E extends T>(entry: E): WrapResultNone<PushStatus> {
|
|
|
|
|
if (rfwfs.read_write_access(this.entry.permissions)) {
|
|
|
|
|
return fs_dir_push(this.directory, entry)
|
|
|
|
|
public push<E extends Entry>(entry: E): WrapResultNone<PushStatus> {
|
|
|
|
|
if (rfwfs.read_write_access(this.dir.permissions)) {
|
|
|
|
|
return fs_dir_push(this.dir, entry)
|
|
|
|
|
}
|
|
|
|
|
return wrap_none(PushStatus.Denied)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public pop(file_name: string): WrapResultEntry<T, ReadStatus> {
|
|
|
|
|
if (rfwfs.read_write_access(this.entry.permissions)) {
|
|
|
|
|
fs_dir_pop(this.directory, file_name)
|
|
|
|
|
public pop(file_name: string): WrapResultEntry<Entry, ReadStatus> {
|
|
|
|
|
if (rfwfs.read_write_access(this.dir.permissions)) {
|
|
|
|
|
fs_dir_pop(this.dir, file_name)
|
|
|
|
|
}
|
|
|
|
|
return wrap_entry(ReadStatus.Denied)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
class RfwfsRootDirectory<T extends Entry> {
|
|
|
|
|
public directory: T[];
|
|
|
|
|
|
|
|
|
|
constructor() {
|
|
|
|
|
this.directory = []
|
|
|
|
|
public push_bulk_unsafe(dirs: T[]) {
|
|
|
|
|
dirs.forEach(dir => this.dir.files.inner.push(dir))
|
|
|
|
|
this.sort()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public sort() {
|
|
|
|
|
this.directory.sort((a,z) => a.name.inner.localeCompare(z.name.inner))
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public clone(file_name: string): WrapResultEntry<T, ReadStatus> {
|
|
|
|
|
return fs_dir_clone(this.directory, file_name)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public find(file_name: string): WrapResultEntry<T, ReadStatus> {
|
|
|
|
|
return fs_dir_find(this.directory, file_name)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public push<E extends T>(entry: E): WrapResultNone<PushStatus> {
|
|
|
|
|
return fs_dir_push(this.directory, entry)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public pop(file_name: string): WrapResultEntry<T, ReadStatus> {
|
|
|
|
|
return fs_dir_pop(this.directory, file_name)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
class RfwfsBinary {
|
|
|
|
|
public lambda: BinaryLambda;
|
|
|
|
|
protected entry: Entry;
|
|
|
|
|
|
|
|
|
|
constructor(entry: Entry, lambda: BinaryLambda) {
|
|
|
|
|
this.lambda = lambda
|
|
|
|
|
this.entry = entry
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public execute(): WrapBinary {
|
|
|
|
|
if (rfwfs.execute_access(this.entry.permissions)) {
|
|
|
|
|
try {
|
|
|
|
|
this.lambda(() => strip_entry(this.entry))
|
|
|
|
|
} catch(binary_e) {
|
|
|
|
|
return wrap_binary(ExecuteStatus.Panic, (binary_e as object).toString())
|
|
|
|
|
}
|
|
|
|
|
return wrap_binary(ExecuteStatus.Ok)
|
|
|
|
|
}
|
|
|
|
|
return wrap_binary(ExecuteStatus.Denied)
|
|
|
|
|
public push_unsafe(dir: T) {
|
|
|
|
|
this.dir.files.inner.push(dir)
|
|
|
|
|
this.sort()
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -268,88 +229,105 @@ class rfwfs_lib {
|
|
|
|
|
public static read_write_access(permissions: Permissions): boolean {
|
|
|
|
|
return rfwfs.read_access(permissions) && rfwfs.write_access(permissions)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static directory_in_root(properties: DirectoryInRootProperties): RfwfsDirectory<DirectoryInRoot> {
|
|
|
|
|
class dir<P, F extends Entry> {
|
|
|
|
|
public parent: P;
|
|
|
|
|
public permissions: Permissions;
|
|
|
|
|
public timestamp: number;
|
|
|
|
|
public files: EntryValue<F[]>;
|
|
|
|
|
public name: EntryValue<string>;
|
|
|
|
|
|
|
|
|
|
constructor(permissions: Permissions, timestamp: number, name: string, parent: P, files: F[]) {
|
|
|
|
|
this.parent = parent
|
|
|
|
|
this.permissions = permissions
|
|
|
|
|
this.timestamp = timestamp
|
|
|
|
|
this.files = new EntryValue(this.permissions, files)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
// const dir_o = { type: EntryType.Directory } as DirectoryInRoot
|
|
|
|
|
// dir_o.parent = null
|
|
|
|
|
// dir_o.permissions = properties.permissions
|
|
|
|
|
// dir_o.timestamp = properties.timestamp
|
|
|
|
|
// dir_o.files = new EntryValue(dir_o, [])
|
|
|
|
|
// dir_o.name = new EntryValue(dir_o, properties.name)
|
|
|
|
|
// return new RfwfsDirectory(dir_o)
|
|
|
|
|
}
|
|
|
|
|
public static directory<T extends Entry>(properties: DirectoryProperties<T>): RfwfsDirectory<T> {
|
|
|
|
|
const dir_o = { type: EntryType.Directory } as Directory<T>
|
|
|
|
|
dir_o.parent = properties.parent
|
|
|
|
|
dir_o.permissions = properties.permissions
|
|
|
|
|
dir_o.timestamp = properties.timestamp
|
|
|
|
|
dir_o.files = new EntryValue(dir_o, [])
|
|
|
|
|
dir_o.name = new EntryValue(dir_o, properties.name)
|
|
|
|
|
return new RfwfsDirectory(dir_o)
|
|
|
|
|
}
|
|
|
|
|
public static file(properties: FileProperties) {
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
class rfwfs<T extends Entry> extends rfwfs_lib {
|
|
|
|
|
public root: Root<T>;
|
|
|
|
|
class rfwfs extends rfwfs_lib {
|
|
|
|
|
public root: Root;
|
|
|
|
|
|
|
|
|
|
constructor() {
|
|
|
|
|
super()
|
|
|
|
|
this.root = {
|
|
|
|
|
type: EntryType.Root,
|
|
|
|
|
permissions: Permissions.r | Permissions.w,
|
|
|
|
|
timestamp: new EntryValueRoot((Date.now()/1000) | 0),
|
|
|
|
|
parent: null,
|
|
|
|
|
inner: new RfwfsRootDirectory(),
|
|
|
|
|
name: ROOT_ID.TRUNK,
|
|
|
|
|
} as Root<T>
|
|
|
|
|
this.root = { type: EntryType.Root } as Root
|
|
|
|
|
this.root.permissions = Permissions.r | Permissions.w
|
|
|
|
|
this.root.timestamp = (Date.now()/1000) | 0
|
|
|
|
|
this.root.parent = null
|
|
|
|
|
this.root.files = new EntryValue(this.root, [])
|
|
|
|
|
this.root.name = ROOT_ID.TRUNK
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public push_directory_into_root<T extends Entry>(dir: EntryCollection<T>): EntryCollection<T> {
|
|
|
|
|
this.root.inner.push(dir)
|
|
|
|
|
return dir
|
|
|
|
|
public sort() {
|
|
|
|
|
fs_dir_sort(this.root)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static file(
|
|
|
|
|
default_name: string,
|
|
|
|
|
default_permissions: Permissions,
|
|
|
|
|
default_parent: DirectoryAny,
|
|
|
|
|
default_timestamp?: number,
|
|
|
|
|
default_inner?: FileInner
|
|
|
|
|
): EntryFile {
|
|
|
|
|
const file = { type: EntryType.File } as EntryFile
|
|
|
|
|
file.hash = "0"
|
|
|
|
|
file.permissions = default_permissions
|
|
|
|
|
file.parent = default_parent
|
|
|
|
|
file.timestamp = new EntryValue(file, default_timestamp ? default_timestamp : (Date.now()/1000) | 0)
|
|
|
|
|
file.inner = new EntryValue(file, default_inner ? default_inner : "")
|
|
|
|
|
file.name = new EntryValue(file, default_name)
|
|
|
|
|
return file
|
|
|
|
|
public clone(file_name: string): WrapResultEntry<Entry, ReadStatus> {
|
|
|
|
|
if (rfwfs.read_write_access(this.root.permissions)) {
|
|
|
|
|
return fs_dir_clone(this.root, file_name)
|
|
|
|
|
}
|
|
|
|
|
return wrap_entry(ReadStatus.Denied)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static directory<T extends Entry>(
|
|
|
|
|
default_name: string,
|
|
|
|
|
default_permissions: Permissions,
|
|
|
|
|
default_parent: DirectoryAny,
|
|
|
|
|
default_timestamp?: number,
|
|
|
|
|
default_inner?: T[]
|
|
|
|
|
): EntryCollection<T> {
|
|
|
|
|
const directory = { type: EntryType.Directory } as EntryCollection<T>
|
|
|
|
|
directory.parent = default_parent
|
|
|
|
|
directory.permissions = default_permissions
|
|
|
|
|
directory.timestamp = new EntryValue(directory, default_timestamp ? default_timestamp : (Date.now()/1000) | 0)
|
|
|
|
|
directory.inner = new RfwfsDirectory(directory, default_inner ? default_inner : [])
|
|
|
|
|
directory.name = new EntryValue(directory, default_name)
|
|
|
|
|
return directory
|
|
|
|
|
public find(file_name: string): WrapResultEntry<Entry, ReadStatus> {
|
|
|
|
|
if (rfwfs.read_write_access(this.root.permissions)) {
|
|
|
|
|
return fs_dir_find(this.root, file_name)
|
|
|
|
|
}
|
|
|
|
|
return wrap_entry(ReadStatus.Denied)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static binary(
|
|
|
|
|
default_name: string,
|
|
|
|
|
default_permissions: Permissions,
|
|
|
|
|
default_parent: DirectoryAny,
|
|
|
|
|
default_timestamp?: number,
|
|
|
|
|
default_inner?: BinaryLambda
|
|
|
|
|
): EntryBinary {
|
|
|
|
|
const binary = { type: EntryType.Binary } as EntryBinary
|
|
|
|
|
binary.parent = default_parent
|
|
|
|
|
binary.permissions = default_permissions
|
|
|
|
|
binary.timestamp = new EntryValue(binary, default_timestamp ? default_timestamp : (Date.now()/1000) | 0)
|
|
|
|
|
binary.inner = new RfwfsBinary(binary, default_inner ? default_inner : () => {})
|
|
|
|
|
binary.name = new EntryValue(binary, default_name)
|
|
|
|
|
return binary
|
|
|
|
|
public push<T extends Entry>(entry: T): WrapResultNone<PushStatus> {
|
|
|
|
|
if (rfwfs.read_write_access(this.root.permissions)) {
|
|
|
|
|
return fs_dir_push(this.root, entry)
|
|
|
|
|
}
|
|
|
|
|
return wrap_none(PushStatus.Denied)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public pop(file_name: string): WrapResultEntry<Entry, ReadStatus> {
|
|
|
|
|
if (rfwfs.read_write_access(this.root.permissions)) {
|
|
|
|
|
fs_dir_pop(this.root, file_name)
|
|
|
|
|
}
|
|
|
|
|
return wrap_entry(ReadStatus.Denied)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public push_bulk_unsafe(dirs: DirectoryInRoot[]) {
|
|
|
|
|
dirs.forEach(dir => this.root.files.inner.push(dir))
|
|
|
|
|
this.sort()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public push_unsafe(dir: DirectoryInRoot) {
|
|
|
|
|
this.root.files.inner.push(dir)
|
|
|
|
|
this.sort()
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export default rfwfs
|
|
|
|
|
export {
|
|
|
|
|
type DirectoryAnyDepth,
|
|
|
|
|
type EntryCollection,
|
|
|
|
|
type DirectoryInRoot,
|
|
|
|
|
type RfwfsDirectory,
|
|
|
|
|
type DirectoryAny,
|
|
|
|
|
type BinaryError,
|
|
|
|
|
type Directory,
|
|
|
|
|
type FileInner,
|
|
|
|
|
type EntryFile,
|
|
|
|
|
type Entry,
|
|
|
|
|
Permissions,
|
|
|
|
|
EntryType,
|
|
|
|
|