annotate lisp/package-admin.el @ 420:41dbb7a9d5f2 r21-2-18

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