Improve self-upgrading.

There's no reason not to parse again the command line with the newly
loaded code actually, so be sure to do the self-upgrade dance first
thing and recurse to the pgloader::main function (with a guard).
This commit is contained in:
Dimitri Fontaine 2014-05-03 15:22:34 +02:00
parent f34017d023
commit 6e58db2994
2 changed files with 23 additions and 10 deletions

View File

@ -74,13 +74,19 @@ If you want to test the current repository version (or any checkout really),
it's possible to clone the sources then load them with an older pgloader
release:
$ git clone https://github.com/dimitri/pgloader.git /tmp/pgloader
$ /usr/bin/pgloader --self-upgrade /tmp/pgloader myfile.load
$ /usr/bin/pgloader --version
pgloader version "3.0.99"
compiled with SBCL 1.1.17
Here, the code from the *git clone* will be used at run-time. Of course,
code that has changed before the self-upgrade mechanism is executed will
have no change to get run again. That only includes command line options
processing, though.
$ git clone https://github.com/dimitri/pgloader.git /tmp/pgloader
$ /usr/bin/pgloader --self-upgrade /tmp/pgloader --version
Self-upgrading from sources at "/Users/dim/dev/pgloader/"
pgloader version "3.0.fecae2c"
compiled with SBCL 1.1.17
Here, the code from the *git clone* will be used at run-time. Self-upgrade
is done first, then the main program entry point is called again with the
new coded loaded in.
## The pgloader.lisp script

View File

@ -82,6 +82,9 @@
(command-line-arguments:show-option-help *opt-spec*)
(when quit (uiop:quit)))
(defvar *self-upgraded-already* nil
"Keep track if we did reload our own source code already.")
(defun self-upgrade (namestring)
"Load pgloader sources at PATH-TO-PGLOADER-SOURCES."
(let ((pgloader-pathname (uiop:directory-exists-p
@ -97,7 +100,8 @@
asdf:*central-registry*)))
(format t "Self-upgrading from sources at ~s~%"
(uiop:native-namestring pgloader-pathname))
(asdf:load-system :pgloader)))
(with-output-to-string (*standard-output*)
(asdf:operate 'asdf:load-op :pgloader :verbose nil))))
(condition (c)
(format t "Fatal: ~a~%" c)))))
@ -118,6 +122,13 @@
root-dir self-upgrade)
options
;; First thing: Self Upgrade?
(when self-upgrade
(unless *self-upgraded-already*
(self-upgrade self-upgrade)
(let ((*self-upgraded-already* t))
(main argv))))
;; First care about the root directory where pgloader is supposed to
;; output its data logs and reject files
(let ((root-dir-truename (probe-file root-dir)))
@ -159,10 +170,6 @@
(format t "~%~%"))
(uiop:quit))
;; Self Upgrade?
(when self-upgrade
(self-upgrade self-upgrade))
(when load
(loop for filename in load
do (load (compile-file filename :verbose nil :print nil))))