mirror of
https://github.com/dimitri/el-get.git
synced 2024-09-29 04:58:53 +08:00
Review the :checksum patch, implement M-x el-get-checksum.
This commit is contained in:
parent
25990b6f75
commit
6e4f4007ea
|
@ -331,6 +331,13 @@ M-x el-get-make-recipes::
|
|||
recipe files: one file for each entry in +el-get-sources+ that is not
|
||||
just a +symbol+ and that is not found anywhere in +el-get-recipe-path+.
|
||||
|
||||
M-x el-get-checksum::
|
||||
|
||||
Will prompt for the name of an installed package, with complement, then
|
||||
compute its checksum if the package type supports that feature. The
|
||||
checksum is added to the kill-ring so that you're ready to yank it into
|
||||
your +el-get-sources+ :checksum property if you want to.
|
||||
|
||||
M-x el-get-emacswiki-refresh::
|
||||
|
||||
Will launch a subprocess that connects to EmacsWiki and fetch from there
|
||||
|
|
|
@ -283,7 +283,7 @@ definition provided by `el-get' recipes locally.
|
|||
Checksum calculation is currently supported by these methods
|
||||
with the following meaning:
|
||||
|
||||
* `http', `ftp' and `emacswiki' with the SHA1 of the downloaded file,
|
||||
* `http', `ftp' and `emacswiki' with the SHA1 of the downloaded file
|
||||
"
|
||||
|
||||
:type
|
||||
|
|
34
el-get.el
34
el-get.el
|
@ -40,6 +40,7 @@
|
|||
;; - implement :builtin property (useful for dealing with package.el)
|
||||
;; - fix recipes :build commands, must be either lists of strings or expr
|
||||
;; - add support for el-get-reload and do that at update time
|
||||
;; - implement :checksum property for http kinds of files
|
||||
;;
|
||||
;; 3.1 - 2011-09-15 - Get a fix
|
||||
;;
|
||||
|
@ -487,20 +488,18 @@ PACKAGE may be either a string or the corresponding symbol."
|
|||
(compute-checksum (el-get-method type :compute-checksum)))
|
||||
|
||||
;; check the checksum of the package here, as early as possible
|
||||
(and checksum
|
||||
(not compute-checksum)
|
||||
(error
|
||||
"Checksum verification of package %s is not supported with method %s."
|
||||
package type))
|
||||
(when (and checksum (not compute-checksum))
|
||||
(error
|
||||
"Checksum verification of package %s is not supported with method %s."
|
||||
package type))
|
||||
(when compute-checksum
|
||||
(let ((computed (funcall compute-checksum package)))
|
||||
(if checksum
|
||||
(when (not (equal computed checksum))
|
||||
(unless (equal computed checksum)
|
||||
(error "Checksum verification failed. Required: %s, actual: %s."
|
||||
checksum computed))
|
||||
(el-get-verbose-message
|
||||
"el-get: Checksum value for unchecked pakage %s is %s."
|
||||
package computed))))
|
||||
(el-get-verbose-message "el-get: pakage %s checksum is %s."
|
||||
package computed))))
|
||||
|
||||
;; post-install is the right place to run install-hook
|
||||
(run-hook-with-args hooks package)
|
||||
|
@ -675,6 +674,23 @@ entry which is not a symbol and is not already a known recipe."
|
|||
(el-get-write-recipe r dir)))
|
||||
(dired dir))
|
||||
|
||||
(compute-checksum (el-get-method type :compute-checksum)))
|
||||
|
||||
;;;###autoload
|
||||
(defun el-get-checksum (package)
|
||||
"Compute the checksum of the given package, and put it in the kill-ring"
|
||||
(interactive
|
||||
(list (el-get-read-package-with-status "Checksum" "installed")))
|
||||
(let* ((type (el-get-package-type package))
|
||||
(checksum (plist-get (el-get-package-def package) :checksum))
|
||||
(compute-checksum (el-get-method type :compute-checksum)))
|
||||
(when (and checksum (not compute-checksum))
|
||||
(error "package method %s does not support checksums" type))
|
||||
(when compute-checksum
|
||||
(let ((checksum (funcall compute-checksum package)))
|
||||
(message "Checksum for package %s is: %s" package checksum)
|
||||
(kill-new checksum)))))
|
||||
|
||||
|
||||
;;
|
||||
;; User Interface, Non Interactive part
|
||||
|
|
|
@ -20,6 +20,9 @@
|
|||
:group 'el-get
|
||||
:type 'hook)
|
||||
|
||||
(defvar el-get-http-checksums (make-hash-table)
|
||||
"Hash table for storing downloaded SHA1 checksums.")
|
||||
|
||||
(defun el-get-filename-from-url (url)
|
||||
"return a suitable filename from given url
|
||||
|
||||
|
@ -27,9 +30,6 @@ Test url: http://repo.or.cz/w/ShellArchive.git?a=blob_plain;hb=HEAD;f=ack.el"
|
|||
(replace-regexp-in-string "[^a-zA-Z0-9-_\.\+]" "_"
|
||||
(file-name-nondirectory url)))
|
||||
|
||||
(defvar el-get-http-checksums (make-hash-table)
|
||||
"Hash table for storing downloaded SHA1 checksums.")
|
||||
|
||||
(defun el-get-http-retrieve-callback (status package post-install-fun &optional dest sources)
|
||||
"Callback function for `url-retrieve', store the emacs lisp file for the package."
|
||||
(let* ((pdir (el-get-package-directory package))
|
||||
|
@ -52,16 +52,21 @@ Test url: http://repo.or.cz/w/ShellArchive.git?a=blob_plain;hb=HEAD;f=ack.el"
|
|||
(kill-buffer))
|
||||
(funcall post-install-fun package))
|
||||
|
||||
(defun el-get-http-dest-filename (package &optional url)
|
||||
"Return where to store the file at given URL for given PACKAGE"
|
||||
(let* ((pdir (el-get-package-directory package))
|
||||
(url (or url (plist-get (el-get-package-def package) :url)))
|
||||
(fname (or (plist-get (el-get-package-def package) :localname)
|
||||
(el-get-filename-from-url url))))
|
||||
(expand-file-name fname pdir)))
|
||||
|
||||
(defun el-get-http-install (package url post-install-fun &optional dest)
|
||||
"Dowload a single-file PACKAGE over HTTP and store it in DEST.
|
||||
|
||||
Should dest be omitted (nil), the url content will get written
|
||||
into the package :localname option or its `file-name-nondirectory' part."
|
||||
(let* ((pdir (el-get-package-directory package))
|
||||
(fname (or (plist-get (el-get-package-def package) :localname)
|
||||
(el-get-filename-from-url url)))
|
||||
(dest (or dest
|
||||
(concat (file-name-as-directory pdir) fname))))
|
||||
(dest (or dest (el-get-http-dest-filename package url))))
|
||||
(unless (file-directory-p pdir)
|
||||
(make-directory pdir))
|
||||
|
||||
|
@ -75,7 +80,15 @@ into the package :localname option or its `file-name-nondirectory' part."
|
|||
|
||||
(defun el-get-http-compute-checksum (package)
|
||||
"Look up download time SHA1 of PACKAGE."
|
||||
(gethash package el-get-http-checksums "not installed in this session"))
|
||||
(let ((checksum (gethash package el-get-http-checksums)))
|
||||
(unless checksum
|
||||
;; compute the checksum
|
||||
(setq checksum
|
||||
(with-temp-buffer
|
||||
(insert-file-contents-literally (el-get-http-dest-filename package))
|
||||
(sha1 (current-buffer))))
|
||||
(puthash package checksum el-get-http-checksums))
|
||||
checksum))
|
||||
|
||||
(el-get-register-method
|
||||
:http #'el-get-http-install #'el-get-http-install #'el-get-rmdir
|
||||
|
|
Loading…
Reference in New Issue
Block a user