From 84ca2a0113561afe4e25f52100c47cba7c33ad08 Mon Sep 17 00:00:00 2001 From: Jaidyn Ann <10477760+JadedCtrl@users.noreply.github.com> Date: Sat, 20 May 2023 08:34:15 -0500 Subject: [PATCH] Add global-user 'local' directory, with symlinks to joined channels --- chatdir.scm | 32 ++++++++++++++------------------ tests/tests.scm | 10 ++++++++-- 2 files changed, 22 insertions(+), 20 deletions(-) diff --git a/chatdir.scm b/chatdir.scm index cb3f710..53dcb7e 100644 --- a/chatdir.scm +++ b/chatdir.scm @@ -79,7 +79,7 @@ ;; Create a user's server-wide global-user directory. ;; Quite simple, compared to channel-user-add! (define (user-add! root username) - (create-directory (subpath root ".users" username) #t)) + (create-directory (subpath root ".users" username "local") #t)) ;; Add a user to a channel, creating their channel-user directory. @@ -97,25 +97,21 @@ (let* ([g-name (if global-name global-name username)] [user-path (subpath root channel ".users" "all" username)] [g-user-path (subpath root ".users" g-name)]) - (if (not (or (file-exists? user-path) (directory-exists? user-path))) - (cond - ;; global+global-pairity means that we make a symlink between the global-user and - ;; channel-user; as such the “global” symlink's path is `./`. - [(and global? global-pairity?) - (user-add! root g-name) - (create-symbolic-link (subpath "../../../.users" g-name) user-path) - (create-symbolic-link "./" ;;g-user-path - (subpath user-path "global"))] - ;; Make a channel-user directory and a global-user directory, and link “global” - ;; property. - [global? - (user-add! root g-name) - (create-directory user-path #t) - (create-symbolic-link (subpath "../../../../.users" g-name) - (subpath user-path "global"))] + (cond [(or (file-exists? user-path) (directory-exists? user-path)) + #f] + ;; If global, we gotta do some symlink dancing. + [global? + (user-add! root g-name) + (if global-pairity? + (create-symbolic-link (subpath "../../../.users" g-name) user-path) + (create-directory user-path #t)) + (create-symbolic-link (subpath "../../../../.users" g-name) + (subpath user-path "global")) + (create-symbolic-link (subpath "../../../" channel ".users" "all" username) + (subpath g-user-path "local" channel))] ;; This is a channel-only user, don't bother with symlink fanciness. [#t - (create-directory user-path #t)])))) + (create-directory user-path #t)]))) ;; Sets a file in the user's directory to given value. diff --git a/tests/tests.scm b/tests/tests.scm index a9a8681..cffcc13 100644 --- a/tests/tests.scm +++ b/tests/tests.scm @@ -159,9 +159,15 @@ ;; /.users/birdo → /living room/.users/birdo (channel-user-add! *dir* *new-room* "birdo" #t #t) (channel-user-file-set! *dir* *new-room* "birdo" "nick" "rose") -(check (symbolic-link? (subpath *new-room-all* "birdo")) +(check (read-symbolic-link (subpath *new-room-all* "birdo")) => - #t) + "../../../.users/birdo") +(check (read-symbolic-link (subpath *new-room-all* "birdo" "global")) + => + "../../../../.users/birdo") +(check (read-symbolic-link (subpath *users-dir* "birdo" "local" *new-room*)) + => + (subpath "../../../" *new-room* ".users" "all" "birdo")) (check (user-file-get *dir* "birdo" "nick") => "rose")