Rename --load into --load-lisp-file

To avoid wasting everybody's time when trying to debug --load
command.load, rename the option to be more explicit about what it does.
Also implement some basic guards in the form of testing that the
filename extension is part of a very short whitelist: .lisp, .cl, .lsp
and .asd.
This commit is contained in:
Dimitri Fontaine 2014-09-02 22:33:51 +02:00
parent 6fda4eb52b
commit 9c604f969b
3 changed files with 31 additions and 10 deletions

View File

@ -1,7 +1,7 @@
.\" generated with Ronn/v0.7.3
.\" http://github.com/rtomayko/ronn/tree/0.7.3
.
.TH "PGLOADER" "1" "August 2014" "ff" ""
.TH "PGLOADER" "1" "September 2014" "ff" ""
.
.SH "NAME"
\fBpgloader\fR \- PostgreSQL data loader
@ -76,11 +76,11 @@ List known encodings in this version of pgloader\.
Parse given files in the command line as \fBpgloader\.conf\fR files with the \fBINI\fR syntax that was in use in pgloader versions 2\.x, and output the new command syntax for pgloader on standard output\.
.
.TP
\-l \fIfile\fR, \-\-load \fIfile\fR
\fB\-l <file>\fR, \fB\-\-load\-lisp\-file <file>\fR
Specify a lisp \fIfile\fR to compile and load into the pgloader image before reading the commands, allowing to define extra transformation function\. Those functions should be defined in the \fBpgloader\.transforms\fR package\. This option can appear more than once in the command line\.
.
.TP
\-\-self\-upgrade \fIdirectory\fR:
\fB\-\-self\-upgrade <directory>\fR:
.
.IP
Specify a \fIdirectory\fR where to find pgloader sources so that one of the very first things it does is dynamically loading\-in (and compiling to machine code) another version of itself, usually a newer one like a very recent git checkout\.

View File

@ -59,13 +59,13 @@ pgloader operates using commands which are read from files:
`INI` syntax that was in use in pgloader versions 2.x, and output the
new command syntax for pgloader on standard output.
* -l <file>, --load <file>:
* `-l <file>`, `--load-lisp-file <file>`:
Specify a lisp <file> to compile and load into the pgloader image before
reading the commands, allowing to define extra transformation function.
Those functions should be defined in the `pgloader.transforms` package.
This option can appear more than once in the command line.
* --self-upgrade <directory>:
* `--self-upgrade <directory>`:
Specify a <directory> where to find pgloader sources so that one of the
very first things it does is dynamically loading-in (and compiling to

View File

@ -39,8 +39,8 @@
(("logfile" #\L) :type string
:documentation "Filename where to send the logs.")
(("load" #\l) :type string :list t :optional t
:documentation "Read user code from file")
(("load-lisp-file" #\l) :type string :list t :optional t
:documentation "Read user code from files")
("self-upgrade" :type string :optional t
:documentation "Path to pgloader newer sources")))
@ -118,6 +118,19 @@
(mkdir-or-die summary-dir debug)
summary-pathname)))
(defvar *--load-list-file-extension-whitelist* '("lisp" "lsp" "cl" "asd")
"White list of file extensions allowed with the --load option.")
(defun load-extra-transformation-functions (filename)
"Load an extra filename to tweak pgloader's behavior."
(let ((pathname (uiop:parse-native-namestring filename)))
(unless (member (pathname-type pathname)
*--load-list-file-extension-whitelist*
:test #'string=)
(error "Unknown lisp file extension: ~s" (pathname-type pathname)))
(load (compile-file pathname :verbose nil :print nil))))
(defun main (argv)
"Entry point when building an executable image with buildapp"
(let ((args (rest argv)))
@ -130,7 +143,8 @@
(usage argv :quit t)))
(destructuring-bind (&key help version quiet verbose debug logfile
list-encodings upgrade-config load
list-encodings upgrade-config
((:load-lisp-file load))
client-min-messages log-min-messages summary
root-dir self-upgrade)
options
@ -200,8 +214,15 @@
(uiop:quit))
(when load
(loop for filename in load
do (load (compile-file filename :verbose nil :print nil))))
(loop for filename in load do
(handler-case
(load-extra-transformation-functions filename)
(condition (e)
(format *standard-output*
"Failed to load lisp source file ~s~%"
filename)
(format *standard-output* "~a~%" e)
(uiop:quit 3)))))
;; Now process the arguments
(when arguments