1
0
Fork 0

- [TUI] added a check for configuration file to ensure equal number of usernames and server name are specified.

- [TUI] fixed checks of configuration file.
This commit is contained in:
cage 2024-03-17 14:11:42 +01:00
parent 41511b70eb
commit c459c34dd1
5 changed files with 32 additions and 19 deletions

View File

@ -79,7 +79,7 @@
(declare (ignore rest))
(setf *client-configuration* all))))))
(when perform-missing-value-check
(swconf:perform-missing-value-check file))
(swconf:perform-trivial-configuration-checks file))
(if *client-configuration*
(values *client-configuration* file)
(error (format nil (_ "fatal error: The file ~a is empty") file)))))

View File

@ -120,20 +120,23 @@ etc.) happened"
(multiple-value-bind (x configuration-file-path)
(swconf:load-config-file swconf:+shared-conf-filename+)
(declare (ignore x))
(swconf:perform-missing-value-check configuration-file-path))
(swconf:perform-trivial-configuration-checks configuration-file-path))
(error (e)
(format *error-output* "~a~%" e)
(os-utils:exit-program 1)))
(handler-bind ((error
(lambda (e)
(format *error-output*
(_ "Non fatal error~%~a~%Tinmop will add an empty file for you in ~a. This file will be enough to use the program as a gemini client but to connect to pleroma the file must be properly filled.~%Consult the manpage ~a(1) for more details")
(res:home-confdir)
e
+program-name+)
(invoke-restart 'res:create-empty-in-home))))
(swconf:load-config-file swconf:+conf-filename+)
(swconf:set-current-username-and-server)))
(handler-case
(progn
(swconf:load-config-file swconf:+conf-filename+ t)
(swconf:set-current-username-and-server))
(error (e)
(format *error-output*
(_ "Configuration error~%~a~%Tinmop will create an empty file for you in ~a (if such file does not exists). This file will be enough to use the program as a gemini client but to connect to pleroma the file must be properly filled.~2%Consult the manpage ~a(1) for more details.~2%If you already wrote a configuration file, check the error printed below, try to fix the configuration file and restart ~a.~%")
e
(res:home-confdir)
+program-name+
+program-name+)
(res:create-empty-file-in-home swconf:+conf-filename+)
(os-utils:exit-program 1))))
(defun shared-init (&key (verbose t))
(num:lcg-set-seed)

View File

@ -517,6 +517,7 @@
:create-empty-in-home
:get-config-file
:get-sys-config-file
:create-empty-file-in-home
:get-data-file
:get-data-dir))
@ -1368,7 +1369,7 @@
:attributes
:parse-config
:parse
:perform-missing-value-check
:perform-trivial-configuration-checks
:load-config-file
:gen-simple-access
:access-non-null-conf-value

View File

@ -43,6 +43,9 @@
(fs:make-directory (home-datadir))
(fs:make-directory (home-confdir)))
(defun create-empty-file-in-home (path)
(fs:create-file path :skip-if-exists t))
(defun get-resource-file (system-dir home-dir path)
(let ((system-file (fs:cat-parent-dir system-dir path))
(home-file (fs:cat-parent-dir home-dir path)))
@ -60,7 +63,7 @@
(return-system-filename ()
system-file)
(create-empty-in-home ()
(fs:create-file home-file :skip-if-exists t)
(create-empty-file-in-home home-file)
(get-resource-file system-dir home-dir path))))))))
(defun get-resource-dir (system-dir home-dir path)

View File

@ -648,14 +648,16 @@
mentions
montage)
(defun perform-missing-value-check (file)
(defun perform-trivial-configuration-checks (file)
(handler-case
(trivial-configuration-missing-value-check)
(progn
(trivial-configuration-missing-value-check)
(trivial-configuration-checks))
(error (e)
(error (format nil "Error while loading the file ~a~%~a~%" file e)))))
(defun load-config-file (&optional (virtual-filepath +conf-filename+)
(perform-missing-value-check nil))
(perform-checks nil))
(let* ((file (res:get-config-file virtual-filepath))
(tree (parse-config (fs:namestring->pathname file))))
(loop for entry in tree do
@ -680,8 +682,8 @@
(apply #'access:set-accesses value *software-configuration* key)
(declare (ignore rest))
(setf *software-configuration* all))))))
(when perform-missing-value-check
(perform-missing-value-check file))
(when perform-checks
(perform-trivial-configuration-checks file))
(if *software-configuration*
(values *software-configuration* file)
(error (format nil (_ "fatal error: The file ~a is empty") file)))))
@ -1700,3 +1702,7 @@
#'config-announcements-separator)
do
(funcall fn)))
(defun trivial-configuration-checks ()
(assert (length= (config-username)
(config-server-name))))