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