Review the --root-dir patches for better default management.

Also ensure the directory we're given actually exists on disk, creating it
if necessary, and bail out early in case for whatever reason it's not
possible to create the directory.
This commit is contained in:
Dimitri Fontaine 2013-11-21 11:27:54 +01:00
parent 17ef2f1933
commit d52240a95e
2 changed files with 26 additions and 7 deletions

View File

@ -35,7 +35,7 @@
("log-min-messages" :type string :initial-value "notice"
:documentation "Filter logs seen in the logfile")
(("root-dir" #\D) :type string :initial-value "/tmp/pgloader/"
(("root-dir" #\D) :type string :initial-value ,*root-dir*
:documentation "Output root directory.")
(("upgrade-config" #\U) :type boolean
@ -44,7 +44,7 @@
(("list-encodings" #\E) :type boolean
:documentation "List pgloader known encodings and exit.")
(("logfile" #\L) :type string :initial-value nil
(("logfile" #\L) :type string :initial-value ,*log-filename*
:documentation "Filename where to send the logs.")
(("load" #\l) :type string :list t :optional t
@ -57,6 +57,18 @@
(trivial-backtrace:print-backtrace condition :output stream :verbose t)
(trivial-backtrace:print-condition condition stream)))
(defun mkdir-or-die (path debug &optional (stream *standard-output*))
"Create a directory at given PATH and exit with an error message when
that's not possible."
(handler-case
(ensure-directories-exist path)
(condition (e)
;; any error here is a panic
(if debug
(print-backtrace e debug stream)
(format stream "PANIC: ~a.~%" e))
(uiop:quit))))
(defun main (argv)
"Entry point when building an executable image with buildapp"
(let ((args (rest argv)))
@ -69,10 +81,12 @@
root-dir)
options
(setf (symbol-value '*root-dir*) root-dir )
(when (not logfile)
(setf logfile (make-pathname :directory *root-dir* :name "pgloader" :type "log")))
;; First care about the root directory where pgloader is supposed to
;; output its data logs and reject files
(setf *root-dir* (fad:pathname-as-directory root-dir))
(mkdir-or-die *root-dir* debug)
;; Then process options
(when debug
(format t "sb-impl::*default-external-format* ~s~%"
sb-impl::*default-external-format*))
@ -100,6 +114,7 @@
(loop for filename in load
do (load (compile-file filename :verbose nil :print nil))))
;; Now process the arguments
(when arguments
;; Start the logs system
(let ((log-min-messages

View File

@ -38,9 +38,13 @@
(defparameter *csv-path-root*
(merge-pathnames "csv/" (user-homedir-pathname)))
(defparameter *root-dir* nil)
(defparameter *root-dir*
(make-pathname :directory "/tmp/pgloader/")
"Top directory where to store all data logs and reject files.")
(defparameter *log-filename* nil)
(defparameter *log-filename*
(make-pathname :directory "/tmp/pgloader/" :name "pgloader" :type "log")
"Main pgloader log file")
(defparameter *client-min-messages* :notice)
(defparameter *log-min-messages* :info)