| @@ -1,412 +1,411 @@ | | | @@ -1,412 +1,411 @@ |
1 | /* $NetBSD: build.c,v 1.9 2009/02/02 12:35:01 joerg Exp $ */ | | 1 | /* $NetBSD: build.c,v 1.10 2009/02/05 16:06:55 joerg Exp $ */ |
2 | | | 2 | |
3 | #if HAVE_CONFIG_H | | 3 | #if HAVE_CONFIG_H |
4 | #include "config.h" | | 4 | #include "config.h" |
5 | #endif | | 5 | #endif |
6 | #include <nbcompat.h> | | 6 | #include <nbcompat.h> |
7 | #if HAVE_SYS_CDEFS_H | | 7 | #if HAVE_SYS_CDEFS_H |
8 | #include <sys/cdefs.h> | | 8 | #include <sys/cdefs.h> |
9 | #endif | | 9 | #endif |
10 | __RCSID("$NetBSD: build.c,v 1.9 2009/02/02 12:35:01 joerg Exp $"); | | 10 | __RCSID("$NetBSD: build.c,v 1.10 2009/02/05 16:06:55 joerg Exp $"); |
11 | | | 11 | |
12 | /*- | | 12 | /*- |
13 | * Copyright (c) 2007 Joerg Sonnenberger <joerg@NetBSD.org>. | | 13 | * Copyright (c) 2007 Joerg Sonnenberger <joerg@NetBSD.org>. |
14 | * All rights reserved. | | 14 | * All rights reserved. |
15 | * | | 15 | * |
16 | * This code was developed as part of Google's Summer of Code 2007 program. | | 16 | * This code was developed as part of Google's Summer of Code 2007 program. |
17 | * | | 17 | * |
18 | * Redistribution and use in source and binary forms, with or without | | 18 | * Redistribution and use in source and binary forms, with or without |
19 | * modification, are permitted provided that the following conditions | | 19 | * modification, are permitted provided that the following conditions |
20 | * are met: | | 20 | * are met: |
21 | * | | 21 | * |
22 | * 1. Redistributions of source code must retain the above copyright | | 22 | * 1. Redistributions of source code must retain the above copyright |
23 | * notice, this list of conditions and the following disclaimer. | | 23 | * notice, this list of conditions and the following disclaimer. |
24 | * 2. Redistributions in binary form must reproduce the above copyright | | 24 | * 2. Redistributions in binary form must reproduce the above copyright |
25 | * notice, this list of conditions and the following disclaimer in | | 25 | * notice, this list of conditions and the following disclaimer in |
26 | * the documentation and/or other materials provided with the | | 26 | * the documentation and/or other materials provided with the |
27 | * distribution. | | 27 | * distribution. |
28 | * | | 28 | * |
29 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | | 29 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
30 | * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | | 30 | * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
31 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS | | 31 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS |
32 | * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE | | 32 | * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE |
33 | * COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, | | 33 | * COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, |
34 | * INCIDENTAL, SPECIAL, EXEMPLARY OR CONSEQUENTIAL DAMAGES (INCLUDING, | | 34 | * INCIDENTAL, SPECIAL, EXEMPLARY OR CONSEQUENTIAL DAMAGES (INCLUDING, |
35 | * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | | 35 | * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
36 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED | | 36 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED |
37 | * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, | | 37 | * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, |
38 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT | | 38 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT |
39 | * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | | 39 | * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
40 | * SUCH DAMAGE. | | 40 | * SUCH DAMAGE. |
41 | */ | | 41 | */ |
42 | | | 42 | |
43 | /* | | 43 | /* |
44 | * FreeBSD install - a package for the installation and maintainance | | 44 | * FreeBSD install - a package for the installation and maintainance |
45 | * of non-core utilities. | | 45 | * of non-core utilities. |
46 | * | | 46 | * |
47 | * Redistribution and use in source and binary forms, with or without | | 47 | * Redistribution and use in source and binary forms, with or without |
48 | * modification, are permitted provided that the following conditions | | 48 | * modification, are permitted provided that the following conditions |
49 | * are met: | | 49 | * are met: |
50 | * 1. Redistributions of source code must retain the above copyright | | 50 | * 1. Redistributions of source code must retain the above copyright |
51 | * notice, this list of conditions and the following disclaimer. | | 51 | * notice, this list of conditions and the following disclaimer. |
52 | * 2. Redistributions in binary form must reproduce the above copyright | | 52 | * 2. Redistributions in binary form must reproduce the above copyright |
53 | * notice, this list of conditions and the following disclaimer in the | | 53 | * notice, this list of conditions and the following disclaimer in the |
54 | * documentation and/or other materials provided with the distribution. | | 54 | * documentation and/or other materials provided with the distribution. |
55 | * | | 55 | * |
56 | * Jordan K. Hubbard | | 56 | * Jordan K. Hubbard |
57 | * 18 July 1993 | | 57 | * 18 July 1993 |
58 | * | | 58 | * |
59 | * This is the main body of the create module. | | 59 | * This is the main body of the create module. |
60 | * | | 60 | * |
61 | */ | | 61 | */ |
62 | | | 62 | |
63 | #include "lib.h" | | 63 | #include "lib.h" |
64 | #include "create.h" | | 64 | #include "create.h" |
65 | | | 65 | |
66 | #if HAVE_ERR_H | | 66 | #if HAVE_ERR_H |
67 | #include <err.h> | | 67 | #include <err.h> |
68 | #endif | | 68 | #endif |
69 | #if HAVE_GRP_H | | 69 | #if HAVE_GRP_H |
70 | #include <grp.h> | | 70 | #include <grp.h> |
71 | #endif | | 71 | #endif |
72 | #if HAVE_PWD_H | | 72 | #if HAVE_PWD_H |
73 | #include <pwd.h> | | 73 | #include <pwd.h> |
74 | #endif | | 74 | #endif |
75 | #if HAVE_UNISTD_H | | 75 | #if HAVE_UNISTD_H |
76 | #include <unistd.h> | | 76 | #include <unistd.h> |
77 | #endif | | 77 | #endif |
78 | #if HAVE_FCNTL_H | | 78 | #if HAVE_FCNTL_H |
79 | #include <fcntl.h> | | 79 | #include <fcntl.h> |
80 | #endif | | 80 | #endif |
81 | | | 81 | |
82 | #include <archive.h> | | 82 | #include <archive.h> |
83 | #include <archive_entry.h> | | 83 | #include <archive_entry.h> |
84 | | | 84 | |
85 | static struct memory_file *contents_file; | | 85 | static struct memory_file *contents_file; |
86 | static struct memory_file *comment_file; | | 86 | static struct memory_file *comment_file; |
87 | static struct memory_file *desc_file; | | 87 | static struct memory_file *desc_file; |
88 | static struct memory_file *install_file; | | 88 | static struct memory_file *install_file; |
89 | static struct memory_file *deinstall_file; | | 89 | static struct memory_file *deinstall_file; |
90 | static struct memory_file *display_file; | | 90 | static struct memory_file *display_file; |
91 | static struct memory_file *build_version_file; | | 91 | static struct memory_file *build_version_file; |
92 | static struct memory_file *build_info_file; | | 92 | static struct memory_file *build_info_file; |
93 | static struct memory_file *size_pkg_file; | | 93 | static struct memory_file *size_pkg_file; |
94 | static struct memory_file *size_all_file; | | 94 | static struct memory_file *size_all_file; |
95 | static struct memory_file *preserve_file; | | 95 | static struct memory_file *preserve_file; |
96 | static struct memory_file *views_file; | | 96 | static struct memory_file *views_file; |
97 | | | 97 | |
98 | static void | | 98 | static void |
99 | write_meta_file(struct memory_file *file, struct archive *archive) | | 99 | write_meta_file(struct memory_file *file, struct archive *archive) |
100 | { | | 100 | { |
101 | struct archive_entry *entry; | | 101 | struct archive_entry *entry; |
102 | | | 102 | |
103 | entry = archive_entry_new(); | | 103 | entry = archive_entry_new(); |
104 | archive_entry_set_pathname(entry, file->name); | | 104 | archive_entry_set_pathname(entry, file->name); |
105 | archive_entry_copy_stat(entry, &file->st); | | 105 | archive_entry_copy_stat(entry, &file->st); |
106 | | | 106 | |
107 | archive_entry_set_uname(entry, file->owner); | | 107 | archive_entry_set_uname(entry, file->owner); |
108 | archive_entry_set_gname(entry, file->group); | | 108 | archive_entry_set_gname(entry, file->group); |
109 | | | 109 | |
110 | if (archive_write_header(archive, entry)) | | 110 | if (archive_write_header(archive, entry)) |
111 | errx(2, "cannot write to archive: %s", archive_error_string(archive)); | | 111 | errx(2, "cannot write to archive: %s", archive_error_string(archive)); |
112 | | | 112 | |
113 | archive_write_data(archive, file->data, file->len); | | 113 | archive_write_data(archive, file->data, file->len); |
114 | | | 114 | |
115 | archive_entry_free(entry); | | 115 | archive_entry_free(entry); |
116 | } | | 116 | } |
117 | | | 117 | |
118 | static void | | 118 | static void |
119 | write_entry(struct archive *archive, struct archive_entry *entry) | | 119 | write_entry(struct archive *archive, struct archive_entry *entry) |
120 | { | | 120 | { |
121 | char buf[16384]; | | 121 | char buf[16384]; |
122 | const char *name; | | 122 | const char *name; |
123 | int fd; | | 123 | int fd; |
124 | off_t len; | | 124 | off_t len; |
125 | ssize_t buf_len; | | 125 | ssize_t buf_len; |
126 | | | 126 | |
127 | if (archive_entry_pathname(entry) == NULL) { | | 127 | if (archive_entry_pathname(entry) == NULL) { |
128 | warnx("entry with NULL path"); | | 128 | warnx("entry with NULL path"); |
129 | return; | | 129 | return; |
130 | } | | 130 | } |
131 | | | 131 | |
132 | if (archive_write_header(archive, entry)) { | | 132 | if (archive_write_header(archive, entry)) { |
133 | errx(2, "cannot write to archive: %s", | | 133 | errx(2, "cannot write to archive: %s", |
134 | archive_error_string(archive)); | | 134 | archive_error_string(archive)); |
135 | } | | 135 | } |
136 | | | 136 | |
137 | /* Only regular files can have data. */ | | 137 | /* Only regular files can have data. */ |
138 | if (archive_entry_filetype(entry) != AE_IFREG || | | 138 | if (archive_entry_filetype(entry) != AE_IFREG || |
139 | archive_entry_size(entry) == 0) { | | 139 | archive_entry_size(entry) == 0) { |
140 | archive_entry_free(entry); | | 140 | archive_entry_free(entry); |
141 | return; | | 141 | return; |
142 | } | | 142 | } |
143 | | | 143 | |
144 | name = archive_entry_pathname(entry); | | 144 | name = archive_entry_pathname(entry); |
145 | | | 145 | |
146 | if ((fd = open(name, O_RDONLY)) == -1) | | 146 | if ((fd = open(name, O_RDONLY)) == -1) |
147 | err(2, "cannot open data file %s", name); | | 147 | err(2, "cannot open data file %s", name); |
148 | | | 148 | |
149 | len = archive_entry_size(entry); | | 149 | len = archive_entry_size(entry); |
150 | | | 150 | |
151 | while (len > 0) { | | 151 | while (len > 0) { |
152 | buf_len = (len > sizeof(buf)) ? sizeof(buf) : (ssize_t)len; | | 152 | buf_len = (len > sizeof(buf)) ? sizeof(buf) : (ssize_t)len; |
153 | | | 153 | |
154 | if ((buf_len = read(fd, buf, buf_len)) == 0) | | 154 | if ((buf_len = read(fd, buf, buf_len)) == 0) |
155 | break; | | 155 | break; |
156 | else if (buf_len < 0) | | 156 | else if (buf_len < 0) |
157 | err(2, "cannot read from %s", name); | | 157 | err(2, "cannot read from %s", name); |
158 | | | 158 | |
159 | archive_write_data(archive, buf, (size_t)buf_len); | | 159 | archive_write_data(archive, buf, (size_t)buf_len); |
160 | len -= buf_len; | | 160 | len -= buf_len; |
161 | } | | 161 | } |
162 | | | 162 | |
163 | close(fd); | | 163 | close(fd); |
164 | | | 164 | |
165 | archive_entry_free(entry); | | 165 | archive_entry_free(entry); |
166 | } | | 166 | } |
167 | | | 167 | |
168 | static void | | 168 | static void |
169 | write_normal_file(const char *name, struct archive *archive, | | 169 | write_normal_file(const char *name, struct archive *archive, |
170 | struct archive_entry_linkresolver *resolver, | | 170 | struct archive_entry_linkresolver *resolver, |
171 | const char *owner, const char *group) | | 171 | const char *owner, const char *group) |
172 | { | | 172 | { |
173 | char buf[16384]; | | 173 | char buf[16384]; |
174 | ssize_t buf_len; | | 174 | ssize_t buf_len; |
175 | struct archive_entry *entry, *sparse_entry; | | 175 | struct archive_entry *entry, *sparse_entry; |
176 | struct stat st; | | 176 | struct stat st; |
177 | | | 177 | |
178 | if (lstat(name, &st) == -1) | | 178 | if (lstat(name, &st) == -1) |
179 | err(2, "lstat failed for file %s", name); | | 179 | err(2, "lstat failed for file %s", name); |
180 | | | 180 | |
181 | entry = archive_entry_new(); | | 181 | entry = archive_entry_new(); |
182 | archive_entry_set_pathname(entry, name); | | 182 | archive_entry_set_pathname(entry, name); |
183 | archive_entry_copy_stat(entry, &st); | | 183 | archive_entry_copy_stat(entry, &st); |
184 | | | 184 | |
185 | if (owner != NULL) { | | 185 | if (owner != NULL) { |
186 | uid_t uid; | | 186 | uid_t uid; |
187 | | | 187 | |
188 | archive_entry_set_uname(entry, owner); | | 188 | archive_entry_set_uname(entry, owner); |
189 | if (uid_from_user(owner, &uid) == -1) | | 189 | if (uid_from_user(owner, &uid) == -1) |
190 | errx(2, "user %s unknown", owner); | | 190 | errx(2, "user %s unknown", owner); |
191 | archive_entry_set_uid(entry, uid); | | 191 | archive_entry_set_uid(entry, uid); |
192 | } else { | | 192 | } else { |
193 | archive_entry_set_uname(entry, user_from_uid(st.st_uid, 1)); | | 193 | archive_entry_set_uname(entry, user_from_uid(st.st_uid, 1)); |
194 | } | | 194 | } |
195 | | | 195 | |
196 | if (group != NULL) { | | 196 | if (group != NULL) { |
197 | gid_t gid; | | 197 | gid_t gid; |
198 | | | 198 | |
199 | archive_entry_set_gname(entry, group); | | 199 | archive_entry_set_gname(entry, group); |
200 | if (gid_from_group(group, &gid) == -1) | | 200 | if (gid_from_group(group, &gid) == -1) |
201 | errx(2, "group %s unknown", group); | | 201 | errx(2, "group %s unknown", group); |
202 | archive_entry_set_gid(entry, gid); | | 202 | archive_entry_set_gid(entry, gid); |
203 | } else { | | 203 | } else { |
204 | archive_entry_set_gname(entry, group_from_gid(st.st_gid, 1)); | | 204 | archive_entry_set_gname(entry, group_from_gid(st.st_gid, 1)); |
205 | } | | 205 | } |
206 | | | 206 | |
207 | if ((st.st_mode & S_IFMT) == S_IFLNK) { | | 207 | if ((st.st_mode & S_IFMT) == S_IFLNK) { |
208 | buf_len = readlink(name, buf, sizeof buf); | | 208 | buf_len = readlink(name, buf, sizeof buf); |
209 | if (buf_len < 0) | | 209 | if (buf_len < 0) |
210 | err(2, "cannot read symlink %s", name); | | 210 | err(2, "cannot read symlink %s", name); |
211 | buf[buf_len] = '\0'; | | 211 | buf[buf_len] = '\0'; |
212 | archive_entry_set_symlink(entry, buf); | | 212 | archive_entry_set_symlink(entry, buf); |
213 | } | | 213 | } |
214 | | | 214 | |
215 | archive_entry_linkify(resolver, &entry, &sparse_entry); | | 215 | archive_entry_linkify(resolver, &entry, &sparse_entry); |
216 | | | 216 | |
217 | if (entry != NULL) | | 217 | if (entry != NULL) |
218 | write_entry(archive, entry); | | 218 | write_entry(archive, entry); |
219 | if (sparse_entry != NULL) | | 219 | if (sparse_entry != NULL) |
220 | write_entry(archive, sparse_entry); | | 220 | write_entry(archive, sparse_entry); |
221 | } | | 221 | } |
222 | | | 222 | |
223 | static void | | 223 | static void |
224 | make_dist(const char *pkg, const char *suffix, const package_t *plist) | | 224 | make_dist(const char *pkg, const char *suffix, const package_t *plist) |
225 | { | | 225 | { |
226 | char *archive_name; | | 226 | char *archive_name; |
227 | const char *owner, *group; | | 227 | const char *owner, *group; |
228 | const plist_t *p; | | 228 | const plist_t *p; |
229 | struct archive *archive; | | 229 | struct archive *archive; |
230 | struct archive_entry *entry, *sparse_entry; | | 230 | struct archive_entry *entry, *sparse_entry; |
231 | struct archive_entry_linkresolver *resolver; | | 231 | struct archive_entry_linkresolver *resolver; |
232 | char *initial_cwd; | | 232 | char *initial_cwd; |
233 | | | 233 | |
234 | archive = archive_write_new(); | | 234 | archive = archive_write_new(); |
235 | archive_write_set_format_pax_restricted(archive); | | 235 | archive_write_set_format_pax_restricted(archive); |
236 | if ((resolver = archive_entry_linkresolver_new()) == NULL) | | 236 | if ((resolver = archive_entry_linkresolver_new()) == NULL) |
237 | errx(2, "cannot create link resolver"); | | 237 | errx(2, "cannot create link resolver"); |
238 | archive_entry_linkresolver_set_strategy(resolver, | | 238 | archive_entry_linkresolver_set_strategy(resolver, |
239 | archive_format(archive)); | | 239 | archive_format(archive)); |
240 | | | 240 | |
241 | if (strcmp(suffix, "tbz") == 0 || strcmp(suffix, "tar.bz2") == 0) | | 241 | if (strcmp(suffix, "tbz") == 0 || strcmp(suffix, "tar.bz2") == 0) |
242 | archive_write_set_compression_bzip2(archive); | | 242 | archive_write_set_compression_bzip2(archive); |
243 | else if (strcmp(suffix, "tgz") == 0 || strcmp(suffix, "tar.gz") == 0) | | 243 | else if (strcmp(suffix, "tgz") == 0 || strcmp(suffix, "tar.gz") == 0) |
244 | archive_write_set_compression_gzip(archive); | | 244 | archive_write_set_compression_gzip(archive); |
245 | else | | 245 | else |
246 | archive_write_set_compression_none(archive); | | 246 | archive_write_set_compression_none(archive); |
247 | | | 247 | |
248 | archive_name = xasprintf("%s.%s", pkg, suffix); | | 248 | archive_name = xasprintf("%s.%s", pkg, suffix); |
249 | | | 249 | |
250 | if (archive_write_open_file(archive, archive_name)) | | 250 | if (archive_write_open_file(archive, archive_name)) |
251 | errx(2, "cannot create archive: %s", archive_error_string(archive)); | | 251 | errx(2, "cannot create archive: %s", archive_error_string(archive)); |
252 | | | 252 | |
253 | free(archive_name); | | 253 | free(archive_name); |
254 | | | 254 | |
255 | owner = DefaultOwner; | | 255 | owner = DefaultOwner; |
256 | group = DefaultGroup; | | 256 | group = DefaultGroup; |
257 | | | 257 | |
258 | write_meta_file(contents_file, archive); | | 258 | write_meta_file(contents_file, archive); |
259 | write_meta_file(comment_file, archive); | | 259 | write_meta_file(comment_file, archive); |
260 | write_meta_file(desc_file, archive); | | 260 | write_meta_file(desc_file, archive); |
261 | | | 261 | |
262 | if (Install) | | 262 | if (Install) |
263 | write_meta_file(install_file, archive); | | 263 | write_meta_file(install_file, archive); |
264 | if (DeInstall) | | 264 | if (DeInstall) |
265 | write_meta_file(deinstall_file, archive); | | 265 | write_meta_file(deinstall_file, archive); |
266 | if (Display) | | 266 | if (Display) |
267 | write_meta_file(display_file, archive); | | 267 | write_meta_file(display_file, archive); |
268 | if (BuildVersion) | | 268 | if (BuildVersion) |
269 | write_meta_file(build_version_file, archive); | | 269 | write_meta_file(build_version_file, archive); |
270 | if (BuildInfo) | | 270 | if (BuildInfo) |
271 | write_meta_file(build_info_file, archive); | | 271 | write_meta_file(build_info_file, archive); |
272 | if (SizePkg) | | 272 | if (SizePkg) |
273 | write_meta_file(size_pkg_file, archive); | | 273 | write_meta_file(size_pkg_file, archive); |
274 | if (SizeAll) | | 274 | if (SizeAll) |
275 | write_meta_file(size_all_file, archive); | | 275 | write_meta_file(size_all_file, archive); |
276 | if (Preserve) | | 276 | if (Preserve) |
277 | write_meta_file(preserve_file, archive); | | 277 | write_meta_file(preserve_file, archive); |
278 | if (create_views) | | 278 | if (create_views) |
279 | write_meta_file(views_file, archive); | | 279 | write_meta_file(views_file, archive); |
280 | | | 280 | |
281 | initial_cwd = getcwd(NULL, 0); | | 281 | initial_cwd = getcwd(NULL, 0); |
282 | | | 282 | |
283 | for (p = plist->head; p; p = p->next) { | | 283 | for (p = plist->head; p; p = p->next) { |
284 | if (p->type == PLIST_FILE) { | | 284 | if (p->type == PLIST_FILE) { |
285 | write_normal_file(p->name, archive, resolver, owner, group); | | 285 | write_normal_file(p->name, archive, resolver, owner, group); |
286 | } else if (p->type == PLIST_CWD || p->type == PLIST_SRC) { | | 286 | } else if (p->type == PLIST_CWD || p->type == PLIST_SRC) { |
287 | | | 287 | |
288 | /* XXX let PLIST_SRC override PLIST_CWD */ | | 288 | /* XXX let PLIST_SRC override PLIST_CWD */ |
289 | if (p->type == PLIST_CWD && p->next != NULL && | | 289 | if (p->type == PLIST_CWD && p->next != NULL && |
290 | p->next->type == PLIST_SRC) { | | 290 | p->next->type == PLIST_SRC) { |
291 | continue; | | 291 | continue; |
292 | } | | 292 | } |
293 | chdir(p->name); | | 293 | chdir(p->name); |
294 | } else if (p->type == PLIST_IGNORE) { | | 294 | } else if (p->type == PLIST_IGNORE) { |
295 | p = p->next; | | 295 | p = p->next; |
296 | } else if (p->type == PLIST_CHOWN) { | | 296 | } else if (p->type == PLIST_CHOWN) { |
297 | if (p->name != NULL) | | 297 | if (p->name != NULL) |
298 | owner = p->name; | | 298 | owner = p->name; |
299 | else | | 299 | else |
300 | owner = DefaultOwner; | | 300 | owner = DefaultOwner; |
301 | } else if (p->type == PLIST_CHGRP) { | | 301 | } else if (p->type == PLIST_CHGRP) { |
302 | if (p->name != NULL) | | 302 | if (p->name != NULL) |
303 | group = p->name; | | 303 | group = p->name; |
304 | else | | 304 | else |
305 | group = DefaultGroup; | | 305 | group = DefaultGroup; |
306 | } | | 306 | } |
307 | } | | 307 | } |
308 | | | 308 | |
309 | entry = NULL; | | 309 | entry = NULL; |
310 | archive_entry_linkify(resolver, &entry, &sparse_entry); | | 310 | archive_entry_linkify(resolver, &entry, &sparse_entry); |
311 | while (entry != NULL) { | | 311 | while (entry != NULL) { |
312 | write_entry(archive, entry); | | 312 | write_entry(archive, entry); |
313 | entry = NULL; | | 313 | entry = NULL; |
314 | archive_entry_linkify(resolver, &entry, &sparse_entry); | | 314 | archive_entry_linkify(resolver, &entry, &sparse_entry); |
315 | } | | 315 | } |
316 | | | 316 | |
317 | archive_entry_linkresolver_free(resolver); | | 317 | archive_entry_linkresolver_free(resolver); |
318 | | | 318 | |
319 | if (archive_write_close(archive)) | | 319 | if (archive_write_close(archive)) |
320 | errx(2, "cannot finish archive: %s", archive_error_string(archive)); | | 320 | errx(2, "cannot finish archive: %s", archive_error_string(archive)); |
321 | archive_write_finish(archive); | | 321 | archive_write_finish(archive); |
322 | | | 322 | |
323 | chdir(initial_cwd); | | | |
324 | free(initial_cwd); | | 323 | free(initial_cwd); |
325 | } | | 324 | } |
326 | | | 325 | |
327 | static struct memory_file * | | 326 | static struct memory_file * |
328 | load_and_add(package_t *plist, const char *input_name, | | 327 | load_and_add(package_t *plist, const char *input_name, |
329 | const char *target_name, mode_t perm) | | 328 | const char *target_name, mode_t perm) |
330 | { | | 329 | { |
331 | struct memory_file *file; | | 330 | struct memory_file *file; |
332 | | | 331 | |
333 | file = load_memory_file(input_name, target_name, DefaultOwner, | | 332 | file = load_memory_file(input_name, target_name, DefaultOwner, |
334 | DefaultGroup, perm); | | 333 | DefaultGroup, perm); |
335 | add_plist(plist, PLIST_IGNORE, NULL); | | 334 | add_plist(plist, PLIST_IGNORE, NULL); |
336 | add_plist(plist, PLIST_FILE, target_name); | | 335 | add_plist(plist, PLIST_FILE, target_name); |
337 | | | 336 | |
338 | return file; | | 337 | return file; |
339 | } | | 338 | } |
340 | | | 339 | |
341 | static struct memory_file * | | 340 | static struct memory_file * |
342 | make_and_add(package_t *plist, const char *target_name, | | 341 | make_and_add(package_t *plist, const char *target_name, |
343 | char *content, mode_t perm) | | 342 | char *content, mode_t perm) |
344 | { | | 343 | { |
345 | struct memory_file *file; | | 344 | struct memory_file *file; |
346 | | | 345 | |
347 | file = make_memory_file(target_name, content, strlen(content), | | 346 | file = make_memory_file(target_name, content, strlen(content), |
348 | DefaultOwner, DefaultGroup, perm); | | 347 | DefaultOwner, DefaultGroup, perm); |
349 | add_plist(plist, PLIST_IGNORE, NULL); | | 348 | add_plist(plist, PLIST_IGNORE, NULL); |
350 | add_plist(plist, PLIST_FILE, target_name); | | 349 | add_plist(plist, PLIST_FILE, target_name); |
351 | | | 350 | |
352 | return file; | | 351 | return file; |
353 | } | | 352 | } |
354 | | | 353 | |
355 | int | | 354 | int |
356 | pkg_build(const char *pkg, const char *full_pkg, const char *suffix, | | 355 | pkg_build(const char *pkg, const char *full_pkg, const char *suffix, |
357 | package_t *plist) | | 356 | package_t *plist) |
358 | { | | 357 | { |
359 | char *plist_buf; | | 358 | char *plist_buf; |
360 | size_t plist_len; | | 359 | size_t plist_len; |
361 | | | 360 | |
362 | /* Now put the release specific items in */ | | 361 | /* Now put the release specific items in */ |
363 | add_plist(plist, PLIST_CWD, "."); | | 362 | add_plist(plist, PLIST_CWD, "."); |
364 | comment_file = make_and_add(plist, COMMENT_FNAME, Comment, 0444); | | 363 | comment_file = make_and_add(plist, COMMENT_FNAME, Comment, 0444); |
365 | desc_file = make_and_add(plist, DESC_FNAME, Desc, 0444); | | 364 | desc_file = make_and_add(plist, DESC_FNAME, Desc, 0444); |
366 | | | 365 | |
367 | if (Install) { | | 366 | if (Install) { |
368 | install_file = load_and_add(plist, Install, INSTALL_FNAME, | | 367 | install_file = load_and_add(plist, Install, INSTALL_FNAME, |
369 | 0555); | | 368 | 0555); |
370 | } | | 369 | } |
371 | if (DeInstall) { | | 370 | if (DeInstall) { |
372 | deinstall_file = load_and_add(plist, DeInstall, | | 371 | deinstall_file = load_and_add(plist, DeInstall, |
373 | DEINSTALL_FNAME, 0555); | | 372 | DEINSTALL_FNAME, 0555); |
374 | } | | 373 | } |
375 | if (Display) { | | 374 | if (Display) { |
376 | display_file = load_and_add(plist, Display, | | 375 | display_file = load_and_add(plist, Display, |
377 | DISPLAY_FNAME, 0444); | | 376 | DISPLAY_FNAME, 0444); |
378 | add_plist(plist, PLIST_DISPLAY, DISPLAY_FNAME); | | 377 | add_plist(plist, PLIST_DISPLAY, DISPLAY_FNAME); |
379 | } | | 378 | } |
380 | if (BuildVersion) { | | 379 | if (BuildVersion) { |
381 | build_version_file = load_and_add(plist, BuildVersion, | | 380 | build_version_file = load_and_add(plist, BuildVersion, |
382 | BUILD_VERSION_FNAME, 0444); | | 381 | BUILD_VERSION_FNAME, 0444); |
383 | } | | 382 | } |
384 | if (BuildInfo) { | | 383 | if (BuildInfo) { |
385 | build_info_file = load_and_add(plist, BuildInfo, | | 384 | build_info_file = load_and_add(plist, BuildInfo, |
386 | BUILD_INFO_FNAME, 0444); | | 385 | BUILD_INFO_FNAME, 0444); |
387 | } | | 386 | } |
388 | if (SizePkg) { | | 387 | if (SizePkg) { |
389 | size_pkg_file = load_and_add(plist, SizePkg, | | 388 | size_pkg_file = load_and_add(plist, SizePkg, |
390 | SIZE_PKG_FNAME, 0444); | | 389 | SIZE_PKG_FNAME, 0444); |
391 | } | | 390 | } |
392 | if (SizeAll) { | | 391 | if (SizeAll) { |
393 | size_all_file = load_and_add(plist, SizeAll, | | 392 | size_all_file = load_and_add(plist, SizeAll, |
394 | SIZE_ALL_FNAME, 0444); | | 393 | SIZE_ALL_FNAME, 0444); |
395 | } | | 394 | } |
396 | if (Preserve) { | | 395 | if (Preserve) { |
397 | preserve_file = load_and_add(plist, Preserve, | | 396 | preserve_file = load_and_add(plist, Preserve, |
398 | PRESERVE_FNAME, 0444); | | 397 | PRESERVE_FNAME, 0444); |
399 | } | | 398 | } |
400 | if (create_views) | | 399 | if (create_views) |
401 | views_file = make_and_add(plist, VIEWS_FNAME, "", 0444); | | 400 | views_file = make_and_add(plist, VIEWS_FNAME, "", 0444); |
402 | | | 401 | |
403 | /* Finally, write out the packing list */ | | 402 | /* Finally, write out the packing list */ |
404 | stringify_plist(plist, &plist_buf, &plist_len, realprefix); | | 403 | stringify_plist(plist, &plist_buf, &plist_len, realprefix); |
405 | contents_file = make_memory_file(CONTENTS_FNAME, plist_buf, plist_len, | | 404 | contents_file = make_memory_file(CONTENTS_FNAME, plist_buf, plist_len, |
406 | DefaultOwner, DefaultGroup, 0644); | | 405 | DefaultOwner, DefaultGroup, 0644); |
407 | | | 406 | |
408 | /* And stick it into a tar ball */ | | 407 | /* And stick it into a tar ball */ |
409 | make_dist(pkg, suffix, plist); | | 408 | make_dist(pkg, suffix, plist); |
410 | | | 409 | |
411 | return TRUE; /* Success */ | | 410 | return TRUE; /* Success */ |
412 | } | | 411 | } |