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