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