1
mirror of https://gitlab.com/jessieh/simple-shortener.git synced 2024-11-21 11:01:46 +00:00

Add user-readable error for missing DB mount dir

This commit is contained in:
Jessie Hildebrandt 2021-12-21 00:50:51 -05:00
parent 09a00637f6
commit e3deae0113
3 changed files with 48 additions and 0 deletions

22
src/modules/fs_utils.fnl Normal file
View File

@ -0,0 +1,22 @@
;; modules/fs_utils.fnl
;; Provides a collection of utilities for performing some filesystem operations
;; -------------------------------------------------------------------------- ;;
;; Module definition
(local fs_utils {})
(fn fs_utils.path_exists? [path]
"Return true if `path` exists and is accessible.
Note that this misuses os.rename in order to check `path`-- mightn't want to touch anything important with this..."
(let [(ok? _) (os.rename path path)]
ok?))
(fn fs_utils.dir_exists? [path]
"Return true if `path` is a directory and is accessible."
(fs_utils.path_exists? (.. path "/")))
;; -------------------------------------------------------------------------- ;;
;; Return module
fs_utils

View File

@ -8,6 +8,11 @@
(local lume (require :lume))
(local sqlite (require :sqlite))
;; -------------------------------------------------------------------------- ;;
;; Local modules
(local fs_utils (require :modules.fs_utils))
;; -------------------------------------------------------------------------- ;;
;; Constants
@ -39,6 +44,16 @@ ORDER BY created DESC")
;; -------------------------------------------------------------------------- ;;
;; Initialize database
;; ---------------------------------- ;;
;; Ensure 'db/' folder exists
(when (not (fs_utils.dir_exists? "db"))
(print "🚨 ERROR: No 'db/' folder to place SQLite database files in.\n❓ Did you forget to mount a volume at '/usr/simple-shortener/db?'")
(os.exit -1))
;; ---------------------------------- ;;
;; Connect to SQLite database
;; Tables:
;; links | Stores information about shortened links
;; link_id - The unique base62 identifying string for the shortened link

View File

@ -11,6 +11,7 @@
;; Local modules
(local config (require :modules.config))
(local fs_utils (require :modules.fs_utils))
;; -------------------------------------------------------------------------- ;;
;; Constants
@ -38,6 +39,16 @@ OR last_active <= strftime('%s', 'now', '-" config.session_max_idle_length_hours
;; -------------------------------------------------------------------------- ;;
;; Initialize database
;; ---------------------------------- ;;
;; Ensure 'db/' folder exists
(when (not (fs_utils.dir_exists? "db"))
(print "🚨 ERROR: No 'db/' folder to place SQLite database files in.\n❓ Did you forget to mount a volume at '/usr/simple-shortener/db?'")
(os.exit -1))
;; ---------------------------------- ;;
;; Connect to SQLite database
;; Tables:
;; sessions | Stores information about current (authorized) client sessions
;; session_id - The unique base62 identifying string for the client session