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