Add -t/--timeout switch to 'doom update'

To get around timeout issues on slower connections or larger packages.
This commit is contained in:
Henrik Lissner 2019-08-15 01:34:28 -04:00
parent b29a7ba8fe
commit 5aa7415d87
No known key found for this signature in database
GPG key ID: 5F6C0EA160557395

View file

@ -12,14 +12,21 @@
;; ;;
;;; Dispatchers ;;; Dispatchers
(defcli! (update u) () (defcli! (update u) (&rest args)
"Updates packages. "Updates packages.
This works by fetching all installed package repos and checking the distance
between HEAD and FETCH_HEAD. This can take a while.
This excludes packages whose `package!' declaration contains a non-nil :freeze This excludes packages whose `package!' declaration contains a non-nil :freeze
or :ignore property." or :ignore property."
(doom--ensure-autoloads-while (doom--ensure-autoloads-while
(straight-check-all) (straight-check-all)
(doom-packages-update doom-auto-accept))) (doom-packages-update
doom-auto-accept
(when-let (timeout (cadr (or (member "--timeout" args)
(member "-t" args))))
(string-to-number timeout)))))
(defcli! (rebuild build b) (&rest args) (defcli! (rebuild build b) (&rest args)
"Rebuilds all installed packages. "Rebuilds all installed packages.
@ -190,13 +197,15 @@ a list of packages that will be installed."
(cons 'error e)))))) (cons 'error e))))))
(defun doom-packages-update (&optional auto-accept-p) (defun doom-packages-update (&optional auto-accept-p timeout)
"Updates packages. "Updates packages.
Unless AUTO-ACCEPT-P is non-nil, this function will prompt for confirmation with Unless AUTO-ACCEPT-P is non-nil, this function will prompt for confirmation with
a list of packages that will be updated." a list of packages that will be updated."
(print! (start "Scanning for outdated packages (this may take a while)...")) (print! (start "Scanning for outdated packages (this may take a while)..."))
(print-group! (print-group!
(when timeout
(print! (info "Using %S as timeout value" timeout)))
;; REVIEW Does this fail gracefully enough? Is it error tolerant? ;; REVIEW Does this fail gracefully enough? Is it error tolerant?
;; TODO Add version-lock checks; don't want to spend all this effort on ;; TODO Add version-lock checks; don't want to spend all this effort on
;; packages that shouldn't be updated ;; packages that shouldn't be updated
@ -213,7 +222,7 @@ a list of packages that will be updated."
group future))) group future)))
(error! "Failed to create any threads"))) (error! "Failed to create any threads")))
(total (length futures)) (total (length futures))
(timeout 20)) (timeout (or timeout 45)))
(condition-case-unless-debug e (condition-case-unless-debug e
(let (specs) (let (specs)
(while futures (while futures
@ -229,9 +238,10 @@ a list of packages that will be updated."
(cdar futures) (cdar futures)
", "))) ", ")))
(throw 'timeout (pop futures))) (throw 'timeout (pop futures)))
(sleep-for 2) (sleep-for 1)
(cl-incf time) (when (cl-evenp time)
(print! ".")) (print! "."))
(cl-incf time))
(cl-destructuring-bind (status . result) (cl-destructuring-bind (status . result)
(or (async-get (car (pop futures))) (or (async-get (car (pop futures)))
(cons nil nil)) (cons nil nil))