From d80887d2819b4cd551d6e4c2d0e08cbd12fa1051 Mon Sep 17 00:00:00 2001 From: rhpidfyre Date: Thu, 6 Mar 2025 20:47:38 -0500 Subject: [PATCH] `PushStatus` enum i forgor about the permissions system here... maybe users soon for fun.. --- src/rt/rfwfs/main.ts | 30 ++++++++++++++++++++++-------- 1 file changed, 22 insertions(+), 8 deletions(-) diff --git a/src/rt/rfwfs/main.ts b/src/rt/rfwfs/main.ts index 5f6dbde..7b7f4df 100644 --- a/src/rt/rfwfs/main.ts +++ b/src/rt/rfwfs/main.ts @@ -10,6 +10,11 @@ const enum Permissions { rw, none } +const enum PushStatus { + Ok, + Duplicate, + Denied, +} interface Entry { readonly name: string, @@ -27,7 +32,7 @@ interface EntryFile extends Entry { interface EntryCollection extends EntryCollectionInner { pop: (file_name: string) => T | undefined, find: (file_name: string) => T | undefined - push: (entry: E) => boolean, + push: (entry: Entry) => PushStatus, sort: () => void, } interface Rfwfs { @@ -35,20 +40,29 @@ interface Rfwfs { is_file: (entry: T) => boolean, new_entry: (name: string, permissions: Permissions, timestamp: number, inner: T) => EntryFile, new_collection: (inner: T[]) => EntryCollection, +function readable(self: EntryCollection): boolean { + return self.permissions === Permissions.rw || self.permissions === Permissions.r +} + +function writable(self: EntryCollection): boolean { + return self.permissions === Permissions.rw || self.permissions === Permissions.w } function sort(self: EntryCollection) { self.collection.sort((a,z) => a.name.localeCompare(z.name)) } -function push(self: EntryCollection, entry: Entry) { - const no_duplicates = entry_search(self.collection, entry.name) - if (!no_duplicates) { - self.push(entry) - self.sort() - return true +function push(self: EntryCollection, entry: Entry): PushStatus { + if (writable(self)) { + const no_duplicates = entry_search(self.collection, entry.name) + if (!no_duplicates) { + self.push(entry) + self.sort() + return PushStatus.Ok + } + return PushStatus.Duplicate } - return false + return PushStatus.Denied } function find(self: EntryCollection, file_name: string) {