aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChong Yidong2011-03-19 14:27:55 -0400
committerChong Yidong2011-03-19 14:27:55 -0400
commit4525ce3eb56a1f4b7c50eac9217854bbd170f660 (patch)
tree70e078b783c5886fc4e411734c39547678d5e7c9
parent0a19a6f87504ef65b1c946d5daa34b794d600b20 (diff)
downloademacs-4525ce3eb56a1f4b7c50eac9217854bbd170f660.tar.gz
emacs-4525ce3eb56a1f4b7c50eac9217854bbd170f660.zip
Fix tar package handling, and clean up package-subdirectory-regexp usage.
* lisp/startup.el (package-subdirectory-regexp): Move from package.el. Omit \\` and \\', and let callers add them. * lisp/emacs-lisp/package.el (package-strip-version) (package-load-all-descriptors): Add \\` and \\' to package-subdirectory-regexp before using it. (package-untar-buffer): New arg DIR; ensure that file untars only into this expected directory. Remove superfluous delete-region. (package-unpack): Caller changed. (package-tar-file-info): Use package-subdirectory-regexp.
-rw-r--r--lisp/ChangeLog13
-rw-r--r--lisp/emacs-lisp/package.el47
-rw-r--r--lisp/startup.el15
3 files changed, 46 insertions, 29 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog
index 3a8cf025ad6..42b4d759c07 100644
--- a/lisp/ChangeLog
+++ b/lisp/ChangeLog
@@ -1,3 +1,16 @@
12011-03-19 Chong Yidong <cyd@stupidchicken.com>
2
3 * startup.el (package-subdirectory-regexp): Move from package.el.
4 Omit \\` and \\', and let callers add them.
5
6 * emacs-lisp/package.el (package-strip-version)
7 (package-load-all-descriptors): Add \\` and \\' to
8 package-subdirectory-regexp before using it.
9 (package-untar-buffer): New arg DIR; ensure that file untars only
10 into this expected directory. Remove superfluous delete-region.
11 (package-unpack): Caller changed.
12 (package-tar-file-info): Use package-subdirectory-regexp.
13
12011-03-18 Stefan Monnier <monnier@iro.umontreal.ca> 142011-03-18 Stefan Monnier <monnier@iro.umontreal.ca>
2 15
3 * vc/diff-mode.el (diff-mode-map): Shadow problematic bindings from 16 * vc/diff-mode.el (diff-mode-map): Shadow problematic bindings from
diff --git a/lisp/emacs-lisp/package.el b/lisp/emacs-lisp/package.el
index 399e0fb2e24..5dc2938fe08 100644
--- a/lisp/emacs-lisp/package.el
+++ b/lisp/emacs-lisp/package.el
@@ -319,12 +319,6 @@ Like `package-alist', but maps package name to a second alist.
319The inner alist is keyed by version.") 319The inner alist is keyed by version.")
320(put 'package-obsolete-alist 'risky-local-variable t) 320(put 'package-obsolete-alist 'risky-local-variable t)
321 321
322(defconst package-subdirectory-regexp
323 "\\`\\([^.].*?\\)-\\([0-9]+\\(?:[.][0-9]+\\|\\(?:pre\\|beta\\|alpha\\)[0-9]+\\)*\\)\\'"
324 "Regular expression matching the name of a package subdirectory.
325The first subexpression is the package name.
326The second subexpression is the version string.")
327
328(defun package-version-join (vlist) 322(defun package-version-join (vlist)
329 "Return the version string corresponding to the list VLIST. 323 "Return the version string corresponding to the list VLIST.
330This is, approximately, the inverse of `version-to-list'. 324This is, approximately, the inverse of `version-to-list'.
@@ -357,7 +351,7 @@ This is, approximately, the inverse of `version-to-list'.
357(defun package-strip-version (dirname) 351(defun package-strip-version (dirname)
358 "Strip the version from a combined package name and version. 352 "Strip the version from a combined package name and version.
359E.g., if given \"quux-23.0\", will return \"quux\"" 353E.g., if given \"quux-23.0\", will return \"quux\""
360 (if (string-match package-subdirectory-regexp dirname) 354 (if (string-match (concat "\\`" package-subdirectory-regexp "\\'") dirname)
361 (match-string 1 dirname))) 355 (match-string 1 dirname)))
362 356
363(defun package-load-descriptor (dir package) 357(defun package-load-descriptor (dir package)
@@ -382,12 +376,13 @@ In each valid package subdirectory, this function loads the
382description file containing a call to `define-package', which 376description file containing a call to `define-package', which
383updates `package-alist' and `package-obsolete-alist'." 377updates `package-alist' and `package-obsolete-alist'."
384 (let ((all (memq 'all package-load-list)) 378 (let ((all (memq 'all package-load-list))
379 (regexp (concat "\\`" package-subdirectory-regexp "\\'"))
385 name version force) 380 name version force)
386 (dolist (dir (cons package-user-dir package-directory-list)) 381 (dolist (dir (cons package-user-dir package-directory-list))
387 (when (file-directory-p dir) 382 (when (file-directory-p dir)
388 (dolist (subdir (directory-files dir)) 383 (dolist (subdir (directory-files dir))
389 (when (and (file-directory-p (expand-file-name subdir dir)) 384 (when (and (file-directory-p (expand-file-name subdir dir))
390 (string-match package-subdirectory-regexp subdir)) 385 (string-match regexp subdir))
391 (setq name (intern (match-string 1 subdir)) 386 (setq name (intern (match-string 1 subdir))
392 version (match-string 2 subdir) 387 version (match-string 2 subdir)
393 force (assq name package-load-list)) 388 force (assq name package-load-list))
@@ -579,30 +574,29 @@ EXTRA-PROPERTIES is currently unused."
579 (package-autoload-ensure-default-file generated-autoload-file)) 574 (package-autoload-ensure-default-file generated-autoload-file))
580 (update-directory-autoloads pkg-dir))) 575 (update-directory-autoloads pkg-dir)))
581 576
582(defun package-untar-buffer () 577(defvar tar-parse-info)
578(declare-function tar-untar-buffer "tar-mode" ())
579
580(defun package-untar-buffer (dir)
583 "Untar the current buffer. 581 "Untar the current buffer.
584This uses `tar-untar-buffer' if it is available. 582This uses `tar-untar-buffer' from Tar mode. All files should
585Otherwise it uses an external `tar' program. 583untar into a directory named DIR; otherwise, signal an error."
586`default-directory' should be set by the caller."
587 (require 'tar-mode) 584 (require 'tar-mode)
588 (if (fboundp 'tar-untar-buffer) 585 (tar-mode)
589 (progn 586 ;; Make sure everything extracts into DIR.
590 ;; tar-mode messes with narrowing, so we just let it have the 587 (let ((regexp (concat "\\`" (regexp-quote dir) "/")))
591 ;; whole buffer to play with. 588 (dolist (tar-data tar-parse-info)
592 (delete-region (point-min) (point)) 589 (unless (string-match regexp (aref tar-data 2))
593 (tar-mode) 590 (error "Package does not untar cleanly into directory %s/" dir))))
594 (tar-untar-buffer)) 591 (tar-untar-buffer))
595 ;; FIXME: check the result.
596 (call-process-region (point) (point-max) "tar" nil '(nil nil) nil
597 "xf" "-")))
598 592
599(defun package-unpack (name version) 593(defun package-unpack (name version)
600 (let ((pkg-dir (expand-file-name (concat (symbol-name name) "-" version) 594 (let* ((dirname (concat (symbol-name name) "-" version))
601 package-user-dir))) 595 (pkg-dir (expand-file-name dirname package-user-dir)))
602 (make-directory package-user-dir t) 596 (make-directory package-user-dir t)
603 ;; FIXME: should we delete PKG-DIR if it exists? 597 ;; FIXME: should we delete PKG-DIR if it exists?
604 (let* ((default-directory (file-name-as-directory package-user-dir))) 598 (let* ((default-directory (file-name-as-directory package-user-dir)))
605 (package-untar-buffer) 599 (package-untar-buffer dirname)
606 (package-generate-autoloads (symbol-name name) pkg-dir) 600 (package-generate-autoloads (symbol-name name) pkg-dir)
607 (let ((load-path (cons pkg-dir load-path))) 601 (let ((load-path (cons pkg-dir load-path)))
608 (byte-recompile-directory pkg-dir 0 t))))) 602 (byte-recompile-directory pkg-dir 0 t)))))
@@ -942,7 +936,8 @@ FILE is the name of the tar file to examine.
942The return result is a vector like `package-buffer-info'." 936The return result is a vector like `package-buffer-info'."
943 (let ((default-directory (file-name-directory file)) 937 (let ((default-directory (file-name-directory file))
944 (file (file-name-nondirectory file))) 938 (file (file-name-nondirectory file)))
945 (unless (string-match "^\\(.+\\)-\\([0-9.]+\\)\\.tar$" file) 939 (unless (string-match (concat "\\`" package-subdirectory-regexp "\\.tar\\'")
940 file)
946 (error "Invalid package name `%s'" file)) 941 (error "Invalid package name `%s'" file))
947 (let* ((pkg-name (match-string-no-properties 1 file)) 942 (let* ((pkg-name (match-string-no-properties 1 file))
948 (pkg-version (match-string-no-properties 2 file)) 943 (pkg-version (match-string-no-properties 2 file))
diff --git a/lisp/startup.el b/lisp/startup.el
index 65b1a013c21..e8e85a41c77 100644
--- a/lisp/startup.el
+++ b/lisp/startup.el
@@ -392,6 +392,15 @@ Warning Warning!!! Pure space overflow !!!Warning Warning
392 :type 'directory 392 :type 'directory
393 :initialize 'custom-initialize-delay) 393 :initialize 'custom-initialize-delay)
394 394
395(defconst package-subdirectory-regexp
396 "\\([^.].*?\\)-\\([0-9]+\\(?:[.][0-9]+\\|\\(?:pre\\|beta\\|alpha\\)[0-9]+\\)*\\)"
397 "Regular expression matching the name of a package subdirectory.
398The first subexpression is the package name.
399The second subexpression is the version string.
400
401The regexp should not contain a starting \"\\`\" or a trailing
402 \"\\'\"; those are added automatically by callers.")
403
395(defun normal-top-level-add-subdirs-to-load-path () 404(defun normal-top-level-add-subdirs-to-load-path ()
396 "Add all subdirectories of current directory to `load-path'. 405 "Add all subdirectories of current directory to `load-path'.
397More precisely, this uses only the subdirectories whose names 406More precisely, this uses only the subdirectories whose names
@@ -1194,9 +1203,9 @@ the `--debug-init' option to view a complete error backtrace."
1194 (when (file-directory-p dir) 1203 (when (file-directory-p dir)
1195 (dolist (subdir (directory-files dir)) 1204 (dolist (subdir (directory-files dir))
1196 (when (and (file-directory-p (expand-file-name subdir dir)) 1205 (when (and (file-directory-p (expand-file-name subdir dir))
1197 ;; package-subdirectory-regexp from package.el 1206 (string-match
1198 (string-match "\\`\\([^.].*?\\)-\\([0-9]+\\(?:[.][0-9]+\\|\\(?:pre\\|beta\\|alpha\\)[0-9]+\\)*\\)\\'" 1207 (concat "\\`" package-subdirectory-regexp "\\'")
1199 subdir)) 1208 subdir))
1200 (throw 'package-dir-found t))))))) 1209 (throw 'package-dir-found t)))))))
1201 (package-initialize)) 1210 (package-initialize))
1202 1211