emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[nongnu] elpa/hyperdrive 960232a9b1 010/163: Add: (h/ensure-gateway)


From: ELPA Syncer
Subject: [nongnu] elpa/hyperdrive 960232a9b1 010/163: Add: (h/ensure-gateway)
Date: Fri, 31 May 2024 04:00:07 -0400 (EDT)

branch: elpa/hyperdrive
commit 960232a9b176ae3c6ca31ae24d457e260f07ad77
Author: Adam Porter <adam@alphapapa.net>
Commit: Joseph Turner <joseph@ushin.org>

    Add: (h/ensure-gateway)
---
 hyperdrive-lib.el | 24 ++++++++++++++++++++++++
 1 file changed, 24 insertions(+)

diff --git a/hyperdrive-lib.el b/hyperdrive-lib.el
index 85a467c76d..b5043136fe 100644
--- a/hyperdrive-lib.el
+++ b/hyperdrive-lib.el
@@ -167,6 +167,8 @@ make the request."
   ;;  could remove redundant calls to
   ;;  `h//fill-latest-version' everywhere else.
   (declare (indent defun))
+  (unless (h/ensure-gateway)
+    (h/error "Gateway not installed or incorrect version; request aborted"))
   (pcase method
     ((and (or 'get 'head)
           (guard (string-suffix-p "/" url)))
@@ -197,6 +199,28 @@ make the request."
        ;; We pass only the `plz-error' struct to the ELSE* function.
        (funcall else* (caddr err))))))
 
+(defun h/ensure-gateway ()
+  "Return non-nil if gateway version correct; or offer install and return nil."
+  (declare-function hyperdrive-hyper-gateway-ushin-version "hyperdrive")
+  (defvar h/gateway-version-correct-p)
+  (defvar h/gateway-version-expected)
+  (or h/gateway-version-correct-p
+      ;; Version unknown: verify it.
+      (when (equal h/gateway-version-expected
+                   ;; FIXME: If gateway is installed at correct version but not
+                   ;; running, this would try to reinstall it.
+                   (ignore-errors
+                     (hyperdrive-hyper-gateway-ushin-version)))
+        (setf h/gateway-version-correct-p t))
+      (if (yes-or-no-p "Gateway not installed at expected version; download 
correct version (y) or proceed anyway (n)? ")
+          ;; Abort request, install version and set 
`h/gateway-version-correct-p'.
+          (progn
+            (declare-function h/install "hyperdrive")
+            (h/install 'force)
+            nil)
+        ;; Override and use existing version.
+        (setf h/gateway-version-correct-p t))))
+
 (defun h/api-default-else (else plz-err)
   "Handle common errors, overriding ELSE.
 Checks for common errors; if none are found, calls ELSE with



reply via email to

[Prev in Thread] Current Thread [Next in Thread]