diff --git a/src/archive.lisp b/src/archive.lisp index 7afd27c..6d35a58 100644 --- a/src/archive.lisp +++ b/src/archive.lisp @@ -4,13 +4,6 @@ (in-package #:pgloader.archive) -(defparameter *default-tmpdir* - (let* ((tmpdir (uiop:getenv "TMPDIR")) - (tmpdir (or (and tmpdir (probe-file tmpdir)) "/tmp")) - (tmpdir (fad:pathname-as-directory tmpdir))) - (fad:pathname-as-directory (merge-pathnames "pgloader" tmpdir))) - "Place where to fetch and expand archives on-disk.") - (defun http-fetch-file (url &key (tmpdir *default-tmpdir*)) "Download a file from URL into TMPDIR." diff --git a/src/main.lisp b/src/main.lisp index bc16639..cd67d14 100644 --- a/src/main.lisp +++ b/src/main.lisp @@ -86,10 +86,14 @@ (setf *root-dir* (fad:pathname-as-directory root-dir)) (mkdir-or-die *root-dir* debug) + ;; Set parameters that come from the environement + (init-params-from-environment) + ;; Then process options (when debug (format t "sb-impl::*default-external-format* ~s~%" - sb-impl::*default-external-format*)) + sb-impl::*default-external-format*) + (format t "tmpdir: ~s~%" *default-tmpdir*)) (when version (format t "pgloader version ~s~%" *version-string*)) diff --git a/src/params.lisp b/src/params.lisp index 041f684..b8aac0e 100644 --- a/src/params.lisp +++ b/src/params.lisp @@ -23,6 +23,8 @@ #:*myconn-user* #:*myconn-pass* #:*state* + #:*default-tmpdir* + #:init-params-from-environment #:getenv-default)) (in-package :pgloader.params) @@ -83,3 +85,26 @@ (defparameter *myconn-port* 3306) (defparameter *myconn-user* (uiop:getenv "USER")) (defparameter *myconn-pass* nil) + +;;; +;;; Archive processing: downloads and unzip. +;;; +(defparameter *default-tmpdir* + (let* ((tmpdir (uiop:getenv "TMPDIR")) + (tmpdir (or (and tmpdir (probe-file tmpdir)) "/tmp")) + (tmpdir (fad:pathname-as-directory tmpdir))) + (fad:pathname-as-directory (merge-pathnames "pgloader" tmpdir))) + "Place where to fetch and expand archives on-disk.") + +;;; +;;; Run time initialisation of ENV provided parameters +;;; +;;; The command parser dynamically inspect the environment when building the +;;; connection parameters, so that we don't need to provision for those here. +;;; +(defun init-params-from-environment () + "Some of our parameters get their default value from the env. Do that at + runtime when using a compiled binary." + (setf *default-tmpdir* + (fad:pathname-as-directory + (getenv-default "TMPDIR" *default-tmpdir*))))