From 6e58db2994e46a2308a104fe54efa486e30bcca1 Mon Sep 17 00:00:00 2001 From: Dimitri Fontaine Date: Sat, 3 May 2014 15:22:34 +0200 Subject: [PATCH] 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). --- README.md | 16 +++++++++++----- src/main.lisp | 17 ++++++++++++----- 2 files changed, 23 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index e5c0ef0..37c41f8 100644 --- a/README.md +++ b/README.md @@ -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: + $ /usr/bin/pgloader --version + pgloader version "3.0.99" + compiled with SBCL 1.1.17 + $ git clone https://github.com/dimitri/pgloader.git /tmp/pgloader - $ /usr/bin/pgloader --self-upgrade /tmp/pgloader myfile.load + $ /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. 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. +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 diff --git a/src/main.lisp b/src/main.lisp index 1fd5ca6..9556e4a 100644 --- a/src/main.lisp +++ b/src/main.lisp @@ -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))))