diff options
| author | Artur Malabarba | 2015-04-05 15:43:59 +0100 |
|---|---|---|
| committer | Artur Malabarba | 2015-04-06 11:19:04 +0100 |
| commit | 7436b68132daa1a941bfbc73a16ce43f5e72a746 (patch) | |
| tree | b615074c3cc34930ceb6a6fbb2ffd890c84dba2a /lisp | |
| parent | b884ff380dc341ca8dc8fcfe4357110e191216ce (diff) | |
| download | emacs-7436b68132daa1a941bfbc73a16ce43f5e72a746.tar.gz emacs-7436b68132daa1a941bfbc73a16ce43f5e72a746.zip | |
emacs-lisp/package.el: Async support in download-transaction
Diffstat (limited to 'lisp')
| -rw-r--r-- | lisp/ChangeLog | 2 | ||||
| -rw-r--r-- | lisp/emacs-lisp/package.el | 93 |
2 files changed, 61 insertions, 34 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog index 94b4be74584..37bf841d6e6 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog | |||
| @@ -82,6 +82,8 @@ | |||
| 82 | * emacs-lisp/package.el: Add package-initialize to user-init-file. | 82 | * emacs-lisp/package.el: Add package-initialize to user-init-file. |
| 83 | (package--ensure-init-file): New function. | 83 | (package--ensure-init-file): New function. |
| 84 | (package-install, package-install-from-buffer): Use it. | 84 | (package-install, package-install-from-buffer): Use it. |
| 85 | (package-download-transaction, package-install-from-archive): Add | ||
| 86 | ASYNC and CALLBACK arguments. | ||
| 85 | 87 | ||
| 86 | 2015-04-05 Pete Williamson <petewil@chromium.org> (tiny-change) | 88 | 2015-04-05 Pete Williamson <petewil@chromium.org> (tiny-change) |
| 87 | 89 | ||
diff --git a/lisp/emacs-lisp/package.el b/lisp/emacs-lisp/package.el index 18802701a0a..2e6ad99d705 100644 --- a/lisp/emacs-lisp/package.el +++ b/lisp/emacs-lisp/package.el | |||
| @@ -1658,43 +1658,56 @@ if all the in-between dependencies are also in PACKAGE-LIST." | |||
| 1658 | "Return the archive containing the package NAME." | 1658 | "Return the archive containing the package NAME." |
| 1659 | (cdr (assoc (package-desc-archive desc) package-archives))) | 1659 | (cdr (assoc (package-desc-archive desc) package-archives))) |
| 1660 | 1660 | ||
| 1661 | (defun package-install-from-archive (pkg-desc) | 1661 | (defun package-install-from-archive (pkg-desc &optional async callback) |
| 1662 | "Download and install a tar package." | 1662 | "Download and install a tar package. |
| 1663 | If ASYNC is non-nil, perform the download asynchronously. | ||
| 1664 | If CALLBACK is non-nil, call it with no arguments once the | ||
| 1665 | operation is done." | ||
| 1663 | ;; This won't happen, unless the archive is doing something wrong. | 1666 | ;; This won't happen, unless the archive is doing something wrong. |
| 1664 | (when (eq (package-desc-kind pkg-desc) 'dir) | 1667 | (when (eq (package-desc-kind pkg-desc) 'dir) |
| 1665 | (error "Can't install directory package from archive")) | 1668 | (error "Can't install directory package from archive")) |
| 1666 | (let* ((location (package-archive-base pkg-desc)) | 1669 | (let* ((location (package-archive-base pkg-desc)) |
| 1667 | (file (concat (package-desc-full-name pkg-desc) | 1670 | (file (concat (package-desc-full-name pkg-desc) |
| 1668 | (package-desc-suffix pkg-desc))) | 1671 | (package-desc-suffix pkg-desc)))) |
| 1669 | (sig-file (concat file ".sig")) | 1672 | (package--with-work-buffer-async location file async |
| 1670 | good-signatures pkg-descs) | 1673 | (if (or (not package-check-signature) |
| 1671 | (package--with-work-buffer location file | 1674 | (member (package-desc-archive pkg-desc) |
| 1672 | (if (and package-check-signature | 1675 | package-unsigned-archives)) |
| 1673 | (not (member (package-desc-archive pkg-desc) | 1676 | ;; If we don't care about the signature, unpack and we're |
| 1674 | package-unsigned-archives))) | 1677 | ;; done. |
| 1675 | (if (package--archive-file-exists-p location sig-file) | 1678 | (progn (package-unpack pkg-desc) |
| 1676 | (setq good-signatures (package--check-signature location file)) | 1679 | (funcall callback)) |
| 1677 | (unless (eq package-check-signature 'allow-unsigned) | 1680 | ;; If we care, check it and *then* write the file. |
| 1678 | (error "Unsigned package: `%s'" | 1681 | (let ((content (buffer-string))) |
| 1679 | (package-desc-name pkg-desc))))) | 1682 | (package--check-signature |
| 1680 | (package-unpack pkg-desc)) | 1683 | location file content async |
| 1681 | ;; Here the package has been installed successfully, mark it as | 1684 | ;; This function will be called after signature checking. |
| 1682 | ;; signed if appropriate. | 1685 | (lambda (&optional good-sigs) |
| 1683 | (when good-signatures | 1686 | (unless (or good-sigs (eq package-check-signature 'allow-unsigned)) |
| 1684 | ;; Write out good signatures into NAME-VERSION.signed file. | 1687 | ;; Even if the sig fails, this download is done, so |
| 1685 | (write-region (mapconcat #'epg-signature-to-string good-signatures "\n") | 1688 | ;; remove it from the in-progress list. |
| 1686 | nil | 1689 | (error "Unsigned package: `%s'" |
| 1687 | (expand-file-name | 1690 | (package-desc-name pkg-desc))) |
| 1688 | (concat (package-desc-full-name pkg-desc) | 1691 | ;; Signature checked, unpack now. |
| 1689 | ".signed") | 1692 | (with-temp-buffer (insert content) |
| 1690 | package-user-dir) | 1693 | (package-unpack pkg-desc)) |
| 1691 | nil 'silent) | 1694 | ;; Here the package has been installed successfully, mark it as |
| 1692 | ;; Update the old pkg-desc which will be shown on the description buffer. | 1695 | ;; signed if appropriate. |
| 1693 | (setf (package-desc-signed pkg-desc) t) | 1696 | (when good-sigs |
| 1694 | ;; Update the new (activated) pkg-desc as well. | 1697 | ;; Write out good signatures into NAME-VERSION.signed file. |
| 1695 | (setq pkg-descs (cdr (assq (package-desc-name pkg-desc) package-alist))) | 1698 | (write-region (mapconcat #'epg-signature-to-string good-sigs "\n") |
| 1696 | (if pkg-descs | 1699 | nil |
| 1697 | (setf (package-desc-signed (car pkg-descs)) t))))) | 1700 | (expand-file-name |
| 1701 | (concat (package-desc-full-name pkg-desc) ".signed") | ||
| 1702 | package-user-dir) | ||
| 1703 | nil 'silent) | ||
| 1704 | ;; Update the old pkg-desc which will be shown on the description buffer. | ||
| 1705 | (setf (package-desc-signed pkg-desc) t) | ||
| 1706 | ;; Update the new (activated) pkg-desc as well. | ||
| 1707 | (when-let ((pkg-descs (cdr (assq (package-desc-name pkg-desc) package-alist)))) | ||
| 1708 | (setf (package-desc-signed (car pkg-descs)) t))) | ||
| 1709 | (when (functionp callback) | ||
| 1710 | (funcall callback))))))))) | ||
| 1698 | 1711 | ||
| 1699 | (defun package-installed-p (package &optional min-version) | 1712 | (defun package-installed-p (package &optional min-version) |
| 1700 | "Return true if PACKAGE, of MIN-VERSION or newer, is installed. | 1713 | "Return true if PACKAGE, of MIN-VERSION or newer, is installed. |
| @@ -1715,13 +1728,25 @@ If PACKAGE is a package-desc object, MIN-VERSION is ignored." | |||
| 1715 | ;; Also check built-in packages. | 1728 | ;; Also check built-in packages. |
| 1716 | (package-built-in-p package min-version)))) | 1729 | (package-built-in-p package min-version)))) |
| 1717 | 1730 | ||
| 1718 | (defun package-download-transaction (packages) | 1731 | (defun package-download-transaction (packages &optional async callback) |
| 1719 | "Download and install all the packages in PACKAGES. | 1732 | "Download and install all the packages in PACKAGES. |
| 1720 | PACKAGES should be a list of package-desc. | 1733 | PACKAGES should be a list of package-desc. |
| 1734 | If ASYNC is non-nil, perform the downloads asynchronously. | ||
| 1735 | If CALLBACK is non-nil, call it with no arguments once the | ||
| 1736 | entire operation is done. | ||
| 1737 | |||
| 1721 | This function assumes that all package requirements in | 1738 | This function assumes that all package requirements in |
| 1722 | PACKAGES are satisfied, i.e. that PACKAGES is computed | 1739 | PACKAGES are satisfied, i.e. that PACKAGES is computed |
| 1723 | using `package-compute-transaction'." | 1740 | using `package-compute-transaction'." |
| 1724 | (mapc #'package-install-from-archive packages)) | 1741 | (cond |
| 1742 | (packages (package-install-from-archive | ||
| 1743 | (car packages) | ||
| 1744 | async | ||
| 1745 | (lambda () | ||
| 1746 | (package-download-transaction (cdr packages)) | ||
| 1747 | (when (functionp callback) | ||
| 1748 | (funcall callback))))) | ||
| 1749 | (callback (funcall callback)))) | ||
| 1725 | 1750 | ||
| 1726 | (defun package--ensure-init-file () | 1751 | (defun package--ensure-init-file () |
| 1727 | "Ensure that the user's init file calls `package-initialize'." | 1752 | "Ensure that the user's init file calls `package-initialize'." |