From 83315fc895efe7a5253974a0ad38d360c208c511 Mon Sep 17 00:00:00 2001 From: Sean Whitton Date: Sat, 29 May 2021 16:04:41 -0700 Subject: add WITH-FLAGFILE Signed-off-by: Sean Whitton --- src/combinator.lisp | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) (limited to 'src/combinator.lisp') diff --git a/src/combinator.lisp b/src/combinator.lisp index 2101132..892d9c8 100644 --- a/src/combinator.lisp +++ b/src/combinator.lisp @@ -219,3 +219,29 @@ affect /root and not /home." (if (and (stringp user) (string= user "root")) `(eseqprops ,@properties) `(reconnects. `((:as :to ,,user)) ,@properties))) + +(defmacro with-flagfile (flagfile &body propapps) + "Apply PROPAPPS unless FLAGFILE exists on the remote; after applying, create +FLAGFILE. +Useful to ensure that something is done just once. Has the semantics that if +FLAGFILE exists, PROPAPPS are assumed to all be already applied." + `(with-flagfile* + ,flagfile + ,(if (cdr propapps) `(eseqprops ,@propapps) (car propapps)))) + +(define-function-property-combinator with-flagfile* (flagfile propapp) + (:retprop :type (propapptype propapp) + :desc (get (car propapp) 'desc) + :hostattrs (get (car propapp) 'hostattrs) + :check (lambda (&rest ignore) + (declare (ignore ignore)) + (remote-exists-p flagfile)) + :apply (lambda (&rest ignore) + (declare (ignore ignore)) + (prog1 (propappapply propapp) + (mrun "touch" flagfile))) + :unapply (lambda (&rest ignore) + (declare (ignore ignore)) + (prog1 (propappunapply propapp) + (mrun "rm" flagfile))) + :args (cdr propapp))) -- cgit v1.2.3