annotate lisp/package-admin.el @ 442:abe6d1db359e r21-2-36

Import from CVS: tag r21-2-36
author cvs
date Mon, 13 Aug 2007 11:35:02 +0200
parents 8de8e3f6228a
children 576fb035e263
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1 ;;; package-admin.el --- Installation and Maintenance of XEmacs packages
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3 ;; Copyright (C) 1997 by Free Software Foundation, Inc.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5 ;; Author: SL Baur <steve@xemacs.org>
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6 ;; Keywords: internal
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
7
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
8 ;; This file is part of XEmacs.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
9
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
10 ;; XEmacs is free software; you can redistribute it and/or modify it
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
11 ;; under the terms of the GNU General Public License as published by
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
12 ;; the Free Software Foundation; either version 2, or (at your option)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
13 ;; any later version.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
14
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
15 ;; XEmacs is distributed in the hope that it will be useful, but
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
16 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
18 ;; General Public License for more details.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
19
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
20 ;; You should have received a copy of the GNU General Public License
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
21 ;; along with XEmacs; see the file COPYING. If not, write to the Free
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
22 ;; Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
23 ;; 02111-1307, USA.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
24
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
25 ;;; Synched up with: Not in FSF
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
26
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
27 ;;; Commentary:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
28
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
29 ;; First pass at lisp front end to package maintenance.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
30
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
31 ;;; Code:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
32
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
33 (require 'config)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
34
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
35 (defvar package-admin-xemacs (concat invocation-directory invocation-name)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
36 "Location of XEmacs binary to use.")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
37
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
38 (defvar package-admin-temp-buffer "*Package Output*"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
39 "Temporary buffer where output of backend commands is saved.")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
40
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
41 (defvar package-admin-install-function (if (eq system-type 'windows-nt)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
42 'package-admin-install-function-mswindows
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
43 'package-admin-default-install-function)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
44 "The function to call to install a package.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
45 Three args are passed: FILENAME PKG-DIR BUF
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
46 Install package FILENAME into directory PKG-DIR, with any messages output
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
47 to buffer BUF.")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
48
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
49 (defvar package-admin-error-messages '(
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
50 "No space left on device"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
51 "No such file or directory"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
52 "Filename too long"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
53 "Read-only file system"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
54 "File too large"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
55 "Too many open files"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
56 "Not enough space"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
57 "Permission denied"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
58 "Input/output error"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
59 "Out of memory"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
60 "Unable to create directory"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
61 "Directory checksum error"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
62 "Cannot exclusively open file"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
63 "corrupted file"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
64 "incomplete .* tree"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
65 "Bad table"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
66 "corrupt input"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
67 "invalid compressed data"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
68 "too many leaves in Huffman tree"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
69 "not a valid zip file"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
70 "first entry not deflated or stored"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
71 "encrypted file --"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
72 "unexpected end of file"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
73 )
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
74 "Regular expressions of possible error messages.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
75 After each package extraction, the `package-admin-temp-buffer' buffer is
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
76 scanned for these messages. An error code is returned if one of these are
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
77 found.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
78
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
79 This is awful, but it exists because error return codes aren't reliable
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
80 under MS Windows.")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
81
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
82 (defvar package-admin-tar-filename-regexps
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
83 '(
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
84 ;; GNU tar:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
85 ;; drwxrwxr-x john/doe 123 1997-02-18 15:48 pathname
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
86 "\\S-+\\s-+[-a-z0-9_/]+\\s-+[0-9]+\\s-+[-0-9]+\\s-+[0-9:]+\\s-+\\(\\S-.*\\)"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
87 ;; HP-UX & SunOS tar:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
88 ;; rwxrwxr-x 501/501 123 Feb 18 15:46 1997 pathname
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
89 ;; Solaris tar (phooey!):
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
90 ;; rwxrwxr-x501/501 123 Feb 18 15:46 1997 pathname
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
91 ;; AIX tar:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
92 ;; -rw-r--r-- 147 1019 32919 Mar 26 12:00:09 1992 pathname
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
93 "\\S-+\\s-*[-a-z0-9_]+[/ ][-a-z0-9_]+\\s-+[0-9]+\\s-+[a-z][a-z][a-z]\\s-+[0-9]+\\s-+[0-9:]+\\s-+[0-9]+\\s-+\\(\\S-.*\\)"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
94
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
95 ;; djtar:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
96 ;; drwx Aug 31 02:01:41 1998 123 pathname
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
97 "\\S-+\\s-+[a-z][a-z][a-z]\\s-+[0-9]+\\s-+[0-9:]+\\s-+[0-9]+\\s-+[0-9]+\\s-+\\(\\S-.*\\)"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
98
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
99 )
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
100 "List of regexps to use to search for tar filenames.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
101 Note that \"\\(\" and \"\\)\" must be used to delimit the pathname (as
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
102 match #1). Don't put \"^\" to match the beginning of the line; this
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
103 is already implicit, as `looking-at' is used. Filenames can,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
104 unfortunately, contain spaces, so be careful in constructing any
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
105 regexps.")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
106
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
107 ;;;###autoload
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
108 (defun package-admin-add-single-file-package (file destdir &optional pkg-dir)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
109 "Install a single file Lisp package into XEmacs package hierarchy.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
110 `file' should be the full path to the lisp file to install.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
111 `destdir' should be a simple directory name.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
112 The optional `pkg-dir' can be used to override the default package hierarchy
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
113 \(car \(last late-packages))."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
114 (interactive "fLisp File: \nsDestination: ")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
115 (when (null pkg-dir)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
116 (setq pkg-dir (car (last late-packages))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
117 (let ((destination (concat pkg-dir "/lisp/" destdir))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
118 (buf (get-buffer-create package-admin-temp-buffer)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
119 (call-process "add-little-package.sh"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
120 nil
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
121 buf
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
122 t
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
123 ;; rest of command line follows
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
124 package-admin-xemacs file destination)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
125
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
126 (defun package-admin-install-function-mswindows (file pkg-dir buf)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
127 "Install function for mswindows"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
128 (let ((default-directory (file-name-as-directory pkg-dir)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
129 (unless (file-directory-p default-directory)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
130 (make-directory default-directory t))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
131 (call-process "minitar" nil buf t file)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
132
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
133 (defun package-admin-default-install-function (file pkg-dir buf)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
134 "Default function to install a package.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
135 Install package FILENAME into directory PKG-DIR, with any messages output
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
136 to buffer BUF."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
137 (let* ((pkg-dir (file-name-as-directory pkg-dir))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
138 (default-directory pkg-dir)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
139 (filename (expand-file-name file)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
140 (unless (file-directory-p pkg-dir)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
141 (make-directory pkg-dir t))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
142 ;; Don't assume GNU tar.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
143 (if (shell-command (concat "gunzip -c " filename " | tar xvf -") buf)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
144 0
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
145 1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
146 ))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
147
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
148 ; (call-process "add-big-package.sh"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
149 ; nil
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
150 ; buf
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
151 ; t
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
152 ; ;; rest of command line follows
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
153 ; package-admin-xemacs file pkg-dir))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
154
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
155 (defun package-admin-get-install-dir (package pkg-dir &optional mule-related)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
156 "If PKG-DIR is non-nil return that,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
157 else return the current location of the package if it is already installed
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
158 or return a location appropriate for the package otherwise."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
159 (if pkg-dir
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
160 pkg-dir
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
161 (let ((package-feature (intern-soft (concat
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
162 (symbol-name package) "-autoloads")))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
163 autoload-dir)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
164 (when (and (not (eq package 'unknown))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
165 (featurep package-feature)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
166 (setq autoload-dir (feature-file package-feature))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
167 (setq autoload-dir (file-name-directory autoload-dir))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
168 (member autoload-dir late-package-load-path))
440
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 428
diff changeset
169 ;; Find the corresponding entry in late-package
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
170 (setq pkg-dir
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
171 (car-safe (member-if (lambda (h)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
172 (string-match (concat "^" (regexp-quote h))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
173 autoload-dir))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
174 late-packages))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
175 (if pkg-dir
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
176 pkg-dir
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
177 ;; Ok we need to guess
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
178 (if mule-related
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
179 (package-admin-get-install-dir 'mule-base nil nil)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
180 (if (eq package 'xemacs-base)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
181 (car (last late-packages))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
182 (package-admin-get-install-dir 'xemacs-base nil nil)))))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
183
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
184
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
185
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
186 (defun package-admin-get-manifest-file (pkg-topdir package)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
187 "Return the name of the MANIFEST file for package PACKAGE.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
188 Note that PACKAGE is a symbol, and not a string."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
189 (let (dir)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
190 (setq dir (expand-file-name "pkginfo" pkg-topdir))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
191 (expand-file-name (concat "MANIFEST." (symbol-name package)) dir)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
192 ))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
193
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
194 (defun package-admin-check-manifest (pkg-outbuf pkg-topdir)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
195 "Check for a MANIFEST.<package> file in the package distribution.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
196 If it doesn't exist, create and write one.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
197 PKG-OUTBUF is the buffer that holds the output from `tar', and PKG-TOPDIR
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
198 is the top-level directory under which the package was installed."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
199 (let ( (manifest-buf " *pkg-manifest*")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
200 old-case-fold-search regexp package-name pathname regexps)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
201 ;; Save and restore the case-fold-search status.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
202 ;; We do this in case we have to screw with it (as it the case of
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
203 ;; case-insensitive filesystems such as MS Windows).
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
204 (setq old-case-fold-search case-fold-search)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
205 (unwind-protect
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
206 (save-excursion ;; Probably redundant.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
207 (set-buffer (get-buffer pkg-outbuf)) ;; Probably already the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
208 ;; current buffer.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
209 (goto-char (point-min))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
210
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
211 ;; Make filenames case-insensitive, if necessary
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
212 (if (eq system-type 'windows-nt)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
213 (setq case-fold-search t))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
214
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
215 ;; We really should compute the regexp.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
216 ;; However, directory-sep-char is currently broken, but we need
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
217 ;; functional code *NOW*.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
218 (setq regexp "\\bpkginfo[\\/]MANIFEST\\...*")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
219
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
220 ;; Look for the manifest.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
221 (if (not (re-search-forward regexp nil t))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
222 (progn
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
223 ;; We didn't find a manifest. Make one.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
224
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
225 ;; Yuk. We weren't passed the package name, and so we have
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
226 ;; to dig for it. Look for it as the subdirectory name below
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
227 ;; "lisp", "man", "info", or "etc".
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
228 ;; Here, we don't use a single regexp because we want to search
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
229 ;; the directories for a package name in a particular order.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
230 ;; The problem is that packages could have directories like
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
231 ;; "etc/sounds/" or "etc/photos/" and we don't want to get
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
232 ;; these confused with the actual package name (although, in
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
233 ;; the case of "etc/sounds/", it's probably correct).
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
234 (if (catch 'done
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
235 (let ( (dirs '("lisp" "info" "man" "etc")) rexp)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
236 (while dirs
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
237 (setq rexp (concat "\\b" (car dirs)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
238 "[\\/]\\([^\\/]+\\)[\//]"))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
239 (if (re-search-forward rexp nil t)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
240 (throw 'done t))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
241 (setq dirs (cdr dirs))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
242 )))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
243 (progn
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
244 (setq package-name (buffer-substring (match-beginning 1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
245 (match-end 1)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
246
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
247 ;; Get and erase the manifest buffer
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
248 (setq manifest-buf (get-buffer-create manifest-buf))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
249 (buffer-disable-undo manifest-buf)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
250 (erase-buffer manifest-buf)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
251
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
252 ;; Now, scan through the output buffer, looking for
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
253 ;; file and directory names.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
254 (goto-char (point-min))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
255 ;; for each line ...
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
256 (while (< (point) (point-max))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
257 (beginning-of-line)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
258 (setq pathname nil)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
259
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
260 ;; scan through the regexps, looking for a pathname
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
261 (if (catch 'found-path
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
262 (setq regexps package-admin-tar-filename-regexps)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
263 (while regexps
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
264 (if (looking-at (car regexps))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
265 (progn
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
266 (setq pathname
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
267 (buffer-substring
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
268 (match-beginning 1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
269 (match-end 1)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
270 (throw 'found-path t)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
271 ))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
272 (setq regexps (cdr regexps))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
273 )
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
274 )
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
275 (progn
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
276 ;; found a pathname -- add it to the manifest
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
277 ;; buffer
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
278 (save-excursion
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
279 (set-buffer manifest-buf)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
280 (goto-char (point-max))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
281 (insert pathname "\n")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
282 )
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
283 ))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
284 (forward-line 1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
285 )
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
286
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
287 ;; Processed all lines.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
288 ;; Now, create the file, pkginfo/MANIFEST.<pkgname>
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
289
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
290 ;; We use `expand-file-name' instead of `concat',
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
291 ;; for portability.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
292 (setq pathname (expand-file-name "pkginfo"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
293 pkg-topdir))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
294 ;; Create pkginfo, if necessary
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
295 (if (not (file-directory-p pathname))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
296 (make-directory pathname))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
297 (setq pathname (expand-file-name
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
298 (concat "MANIFEST." package-name)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
299 pathname))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
300 (save-excursion
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
301 (set-buffer manifest-buf)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
302 ;; Put the files in sorted order
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
303 (sort-lines nil (point-min) (point-max))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
304 ;; Write the file.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
305 ;; Note that using `write-region' *BYPASSES* any check
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
306 ;; to see if XEmacs is currently editing/visiting the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
307 ;; file.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
308 (write-region (point-min) (point-max) pathname)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
309 )
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
310 (kill-buffer manifest-buf)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
311 )
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
312 (progn
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
313 ;; We can't determine the package name from an extracted
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
314 ;; file in the tar output buffer.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
315 ))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
316 ))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
317 )
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
318 ;; Restore old case-fold-search status
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
319 (setq case-fold-search old-case-fold-search))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
320 ))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
321
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
322 ;;;###autoload
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
323 (defun package-admin-add-binary-package (file &optional pkg-dir)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
324 "Install a pre-bytecompiled XEmacs package into package hierarchy."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
325 (interactive "fPackage tarball: ")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
326 (let ((buf (get-buffer-create package-admin-temp-buffer))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
327 (status 1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
328 start err-list
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
329 )
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
330 (setq pkg-dir (package-admin-get-install-dir 'unknown pkg-dir))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
331 ;; Ensure that the current directory doesn't change
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
332 (save-excursion
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
333 (set-buffer buf)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
334 ;; This is not really needed
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
335 (setq default-directory (file-name-as-directory pkg-dir))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
336 (setq case-fold-search t)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
337 (buffer-disable-undo)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
338 (goto-char (setq start (point-max)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
339 (if (= 0 (setq status (funcall package-admin-install-function
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
340 file pkg-dir buf)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
341 (progn
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
342 ;; First, check for errors.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
343 ;; We can't necessarily rely upon process error codes.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
344 (catch 'done
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
345 (goto-char start)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
346 (setq err-list package-admin-error-messages)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
347 (while err-list
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
348 (if (re-search-forward (car err-list) nil t)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
349 (progn
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
350 (setq status 1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
351 (throw 'done nil)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
352 ))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
353 (setq err-list (cdr err-list))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
354 )
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
355 )
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
356 ;; Make sure that the MANIFEST file exists
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
357 (package-admin-check-manifest buf pkg-dir)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
358 ))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
359 )
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
360 status
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
361 ))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
362
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
363 (defun package-admin-rmtree (directory)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
364 "Delete a directory and all of its contents, recursively.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
365 This is a feeble attempt at making a portable rmdir."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
366 (setq directory (file-name-as-directory directory))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
367 (let ((files (directory-files directory nil nil nil t))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
368 (dirs (directory-files directory nil nil nil 'dirs)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
369 (while dirs
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
370 (if (not (member (car dirs) '("." "..")))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
371 (let ((dir (expand-file-name (car dirs) directory)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
372 (condition-case err
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
373 (if (file-symlink-p dir) ;; just in case, handle symlinks
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
374 (delete-file dir)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
375 (package-admin-rmtree dir))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
376 (file-error
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
377 (message "%s: %s: \"%s\"" (nth 1 err) (nth 2 err) (nth 3 err)))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
378 (setq dirs (cdr dirs))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
379 (while files
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
380 (condition-case err
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
381 (delete-file (expand-file-name (car files) directory))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
382 (file-error
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
383 (message "%s: %s: \"%s\"" (nth 1 err) (nth 2 err) (nth 3 err))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
384 (setq files (cdr files)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
385 (condition-case err
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
386 (delete-directory directory)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
387 (file-error
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
388 (message "%s: %s: \"%s\"" (nth 1 err) (nth 2 err) (nth 3 err))))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
389
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
390 (defun package-admin-get-lispdir (pkg-topdir package)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
391 (let (package-lispdir)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
392 (if (and (setq package-lispdir (expand-file-name "lisp" pkg-topdir))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
393 (setq package-lispdir (expand-file-name (symbol-name package)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
394 package-lispdir))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
395 (file-accessible-directory-p package-lispdir))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
396 package-lispdir)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
397 ))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
398
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
399 (defun package-admin-delete-binary-package (package pkg-topdir)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
400 "Delete a binary installation of PACKAGE below directory PKG-TOPDIR.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
401 PACKAGE is a symbol, not a string."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
402 (let ( (tmpbuf " *pkg-manifest*") manifest-file package-lispdir dirs file)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
403 (setq pkg-topdir (package-admin-get-install-dir package pkg-topdir))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
404 (setq manifest-file (package-admin-get-manifest-file pkg-topdir package))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
405 (if (file-exists-p manifest-file)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
406 (progn
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
407 ;; The manifest file exists! Use it to delete the old distribution.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
408 (message "Removing old files for package \"%s\" ..." package)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
409 (sit-for 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
410 (setq tmpbuf (get-buffer-create tmpbuf))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
411 (with-current-buffer tmpbuf
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
412 (buffer-disable-undo)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
413 (erase-buffer)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
414 (insert-file-contents manifest-file)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
415 (goto-char (point-min))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
416
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
417 ;; For each entry in the MANIFEST ...
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
418 (while (< (point) (point-max))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
419 (beginning-of-line)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
420 (setq file (expand-file-name (buffer-substring
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
421 (point)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
422 (point-at-eol))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
423 pkg-topdir))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
424 (if (file-directory-p file)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
425 ;; Keep a record of each directory
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
426 (setq dirs (cons file dirs))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
427 ;; Delete each file.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
428 ;; Make sure that the file is writable.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
429 ;; (This is important under MS Windows.)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
430 ;; I do not know why it important under MS Windows but
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
431 ;; 1. It bombs out out when the file does not exist. This can be condition-cased
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
432 ;; 2. If I removed the write permissions, I do not want XEmacs to just ignore them.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
433 ;; If it wants to, XEmacs may ask, but that is about all
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
434 ;; (set-file-modes file 438) ;; 438 -> #o666
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
435 ;; Note, user might have removed the file!
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
436 (condition-case ()
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
437 (delete-file file)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
438 (error nil))) ;; We may want to turn the error into a Warning?
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
439 (forward-line 1))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
440
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
441 ;; Delete empty directories.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
442 (if dirs
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
443 (let ( (orig-default-directory default-directory)
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
444 ;; directory files file
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
445 )
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
446 ;; Make sure we preserve the existing `default-directory'.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
447 ;; JV, why does this change the default directory? Does it indeed?
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
448 (unwind-protect
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
449 (progn
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
450 ;; Warning: destructive sort!
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
451 (setq dirs (nreverse (sort dirs 'string<)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
452 ; ;; For each directory ...
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
453 ; (while dirs
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
454 ; (setq directory (file-name-as-directory (car dirs)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
455 ; (setq files (directory-files directory))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
456 ; ;; Delete the directory if it's empty.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
457 ; (if (catch 'done
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
458 ; (while files
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
459 ; (setq file (car files))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
460 ; (if (and (not (string= file "."))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
461 ; (not (string= file "..")))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
462 ; (throw 'done nil))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
463 ; (setq files (cdr files))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
464 ; )
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
465 ; t)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
466 ; (
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
467 ; (delete-directory directory))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
468 ; (setq dirs (cdr dirs))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
469 ; )
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
470 ;; JV, On all OS's that I know of delete-directory fails on
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
471 ;; on non-empty dirs anyway
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
472 (mapc
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
473 (lambda (dir)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
474 (condition-case ()
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
475 (delete-directory dir)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
476 dirs))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
477 (setq default-directory orig-default-directory)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
478 )))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
479 )
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
480 (kill-buffer tmpbuf)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
481 ;; Delete the MANIFEST file
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
482 ;; (set-file-modes manifest-file 438) ;; 438 -> #o666
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
483 ;; Note. Packages can have MANIFEST in MANIFEST.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
484 (condition-case ()
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
485 (delete-file manifest-file)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
486 (error nil)) ;; Do warning?
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
487 (message "Removing old files for package \"%s\" ... done" package))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
488 ;; The manifest file doesn't exist. Fallback to just deleting the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
489 ;; package-specific lisp directory, if it exists.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
490 ;;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
491 ;; Delete old lisp directory, if any
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
492 ;; Gads, this is ugly. However, we're not supposed to use `concat'
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
493 ;; in the name of portability.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
494 (when (setq package-lispdir (package-admin-get-lispdir pkg-topdir
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
495 package))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
496 (message "Removing old lisp directory \"%s\" ..."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
497 package-lispdir)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
498 (sit-for 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
499 (package-admin-rmtree package-lispdir)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
500 (message "Removing old lisp directory \"%s\" ... done"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
501 package-lispdir)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
502 ))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
503 ;; Delete the package from the database of installed packages.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
504 (package-delete-name package)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
505
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
506 (provide 'package-admin)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
507
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
508 ;;; package-admin.el ends here