2012-09-04 14:28:19 +05:30
|
|
|
/*-
|
2013-03-23 12:48:06 +05:30
|
|
|
* Copyright (c) 2012-2013 Juan Romero Pardines.
|
2012-09-04 14:28:19 +05:30
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
|
|
|
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
|
|
|
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
|
|
|
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|
|
|
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
|
|
|
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
|
|
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
|
|
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
|
|
|
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
*/
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/stat.h>
|
2012-10-04 20:43:33 +05:30
|
|
|
#include <sys/mman.h>
|
2012-09-04 14:28:19 +05:30
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdbool.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <strings.h>
|
2013-06-19 14:58:51 +05:30
|
|
|
#include <stdarg.h>
|
2012-09-04 14:28:19 +05:30
|
|
|
#include <errno.h>
|
|
|
|
#include <assert.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <getopt.h>
|
|
|
|
#include <ftw.h>
|
|
|
|
#include <fcntl.h>
|
2012-09-23 18:24:04 +05:30
|
|
|
#include <libgen.h>
|
2013-04-01 14:19:25 +05:30
|
|
|
#include <locale.h>
|
2012-09-04 14:28:19 +05:30
|
|
|
|
2013-06-20 16:01:02 +05:30
|
|
|
#include <xbps.h>
|
2012-09-04 14:28:19 +05:30
|
|
|
#include "queue.h"
|
|
|
|
|
2013-01-04 15:05:00 +05:30
|
|
|
#ifdef __clang__
|
|
|
|
#pragma clang diagnostic ignored "-Wformat-nonliteral"
|
|
|
|
#endif
|
|
|
|
|
2012-09-04 14:28:19 +05:30
|
|
|
#define _PROGNAME "xbps-create"
|
|
|
|
|
|
|
|
struct xentry {
|
|
|
|
TAILQ_ENTRY(xentry) entries;
|
|
|
|
char *file, *type, *target, *hash;
|
|
|
|
};
|
|
|
|
|
|
|
|
static TAILQ_HEAD(xentry_head, xentry) xentry_list =
|
|
|
|
TAILQ_HEAD_INITIALIZER(xentry_list);
|
|
|
|
|
2012-09-05 12:30:09 +05:30
|
|
|
static uint64_t instsize;
|
2013-06-20 13:56:12 +05:30
|
|
|
static xbps_dictionary_t pkg_propsd, pkg_filesd;
|
2012-09-04 14:28:19 +05:30
|
|
|
static const char *destdir;
|
|
|
|
|
|
|
|
static void __attribute__((noreturn))
|
|
|
|
usage(void)
|
|
|
|
{
|
2012-09-24 14:19:45 +05:30
|
|
|
fprintf(stdout,
|
2012-11-02 19:33:33 +05:30
|
|
|
"Usage: %s [OPTIONS] destdir\n\n"
|
|
|
|
"OPTIONS\n"
|
|
|
|
" -A --architecture Package architecture (e.g: noarch, i686, etc).\n"
|
|
|
|
" -B --built-with Package builder string (e.g: xbps-src-30).\n"
|
|
|
|
" -C --conflicts Conflicts (blank separated list,\n"
|
|
|
|
" e.g: 'foo>=2.0 blah<=2.0').\n"
|
|
|
|
" -D --dependencies Dependencies (blank separated list,\n"
|
|
|
|
" e.g: 'foo>=1.0_1 blah<2.1').\n"
|
|
|
|
" -F --config-files Configuration files (blank separated list,\n"
|
|
|
|
" e.g '/etc/foo.conf /etc/foo-blah.conf').\n"
|
|
|
|
" -H --homepage Homepage.\n"
|
|
|
|
" -h --help Show help.\n"
|
|
|
|
" -l --license License.\n"
|
|
|
|
" -M --mutable-files Mutable files list (blank separated list,\n"
|
|
|
|
" e.g: '/usr/lib/foo /usr/bin/blah').\n"
|
|
|
|
" -m --maintainer Maintainer.\n"
|
|
|
|
" -n --pkgver Package name/version tuple (e.g `foo-1.0_1').\n"
|
|
|
|
" -P --provides Provides (blank separated list,\n"
|
|
|
|
" e.g: 'foo-9999 blah-1.0').\n"
|
|
|
|
" -p --preserve Enable package preserve boolean.\n"
|
|
|
|
" -q --quiet Work silently.\n"
|
|
|
|
" -R --replaces Replaces (blank separated list,\n"
|
|
|
|
" e.g: 'foo>=1.0 blah<2.0').\n"
|
|
|
|
" -S --long-desc Long description (80 cols per line).\n"
|
|
|
|
" -s --desc Short description (max 80 characters).\n"
|
2012-12-24 15:25:17 +05:30
|
|
|
" -V --version Prints XBPS release version.\n"
|
2013-03-23 12:48:06 +05:30
|
|
|
" --build-options A string with the used build options.\n"
|
2012-12-24 15:25:17 +05:30
|
|
|
" --shlib-provides List of provided shared libraries (blank separated list,\n"
|
|
|
|
" e.g 'libfoo.so.1 libblah.so.2').\n"
|
|
|
|
" --shlib-requires List of required shared libraries (blank separated list,\n"
|
|
|
|
" e.g 'libfoo.so.1 libblah.so.2').\n\n"
|
2012-11-02 19:33:33 +05:30
|
|
|
"NOTE:\n"
|
|
|
|
" At least three flags are required: architecture, pkgver and desc.\n\n"
|
|
|
|
"EXAMPLE:\n"
|
|
|
|
" $ %s -A noarch -n foo-1.0_1 -s \"foo pkg\" destdir\n",
|
2012-09-04 14:28:19 +05:30
|
|
|
_PROGNAME, _PROGNAME);
|
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void __attribute__((noreturn))
|
|
|
|
die(const char *fmt, ...)
|
|
|
|
{
|
|
|
|
va_list ap;
|
|
|
|
int save_errno = errno;
|
|
|
|
|
|
|
|
va_start(ap, fmt);
|
|
|
|
fprintf(stderr, "%s: ERROR: ", _PROGNAME);
|
|
|
|
vfprintf(stderr, fmt, ap);
|
|
|
|
fprintf(stderr, " %s\n", save_errno ? strerror(save_errno) : "");
|
|
|
|
va_end(ap);
|
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
process_array(const char *key, const char *val)
|
|
|
|
{
|
2013-06-20 13:56:12 +05:30
|
|
|
xbps_array_t array;
|
2012-09-04 14:28:19 +05:30
|
|
|
char *args, *p = NULL, *saveptr;
|
|
|
|
|
|
|
|
assert(key);
|
|
|
|
|
|
|
|
if (val == NULL)
|
|
|
|
return;
|
|
|
|
|
2013-06-20 13:56:12 +05:30
|
|
|
array = xbps_array_create();
|
2012-09-04 14:28:19 +05:30
|
|
|
assert(array);
|
|
|
|
|
|
|
|
if (strchr(val, ' ') == NULL) {
|
2013-06-20 13:56:12 +05:30
|
|
|
xbps_array_add_cstring_nocopy(array, val);
|
2012-09-04 14:28:19 +05:30
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
args = strdup(val);
|
|
|
|
assert(args);
|
|
|
|
|
|
|
|
for ((p = strtok_r(args, " ", &saveptr)); p;
|
|
|
|
(p = strtok_r(NULL, " ", &saveptr))) {
|
|
|
|
if (p == NULL)
|
|
|
|
continue;
|
2013-06-20 13:56:12 +05:30
|
|
|
xbps_array_add_cstring(array, p);
|
2012-09-04 14:28:19 +05:30
|
|
|
}
|
|
|
|
free(args);
|
|
|
|
out:
|
2013-06-20 13:56:12 +05:30
|
|
|
xbps_dictionary_set(pkg_propsd, key, array);
|
|
|
|
xbps_object_release(array);
|
2012-09-04 14:28:19 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
static bool
|
|
|
|
entry_is_conf_file(const char *file)
|
|
|
|
{
|
2013-06-20 13:56:12 +05:30
|
|
|
xbps_array_t a;
|
2012-09-04 14:28:19 +05:30
|
|
|
const char *curfile;
|
2013-06-15 13:59:43 +05:30
|
|
|
unsigned int i;
|
2012-09-04 14:28:19 +05:30
|
|
|
|
|
|
|
assert(file);
|
|
|
|
|
2013-06-20 13:56:12 +05:30
|
|
|
a = xbps_dictionary_get(pkg_propsd, "conf_files");
|
|
|
|
if (a == NULL || xbps_array_count(a) == 0)
|
2012-09-04 14:28:19 +05:30
|
|
|
return false;
|
|
|
|
|
2013-06-20 13:56:12 +05:30
|
|
|
for (i = 0; i < xbps_array_count(a); i++) {
|
|
|
|
xbps_array_get_cstring_nocopy(a, i, &curfile);
|
2012-09-04 14:28:19 +05:30
|
|
|
if (strcmp(file, curfile) == 0)
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
ftw_cb(const char *fpath, const struct stat *sb, int type, struct FTW *ftwbuf)
|
|
|
|
{
|
|
|
|
struct xentry *xe = NULL;
|
|
|
|
const char *filep = NULL;
|
2013-05-27 16:33:40 +05:30
|
|
|
char *buf, *p, *p2, *dname;
|
2012-09-23 18:24:04 +05:30
|
|
|
ssize_t r;
|
2012-09-04 14:28:19 +05:30
|
|
|
|
|
|
|
(void)ftwbuf;
|
|
|
|
|
2012-09-05 12:30:09 +05:30
|
|
|
/* Ignore metadata files generated by xbps-src and destdir */
|
2012-09-04 14:28:19 +05:30
|
|
|
if ((strcmp(fpath, ".") == 0) ||
|
|
|
|
(strcmp(fpath, "./props.plist") == 0) ||
|
2012-09-05 12:30:09 +05:30
|
|
|
(strcmp(fpath, "./files.plist") == 0) ||
|
2012-09-23 05:03:51 +05:30
|
|
|
(strcmp(fpath, "./flist") == 0) ||
|
2012-12-24 16:09:10 +05:30
|
|
|
(strcmp(fpath, "./rdeps") == 0) ||
|
|
|
|
(strcmp(fpath, "./shlib-provides") == 0) ||
|
|
|
|
(strcmp(fpath, "./shlib-requires") == 0))
|
2012-09-04 14:28:19 +05:30
|
|
|
return 0;
|
|
|
|
|
|
|
|
/* sanitized file path */
|
2012-09-05 12:30:09 +05:30
|
|
|
filep = strchr(fpath, '.') + 1;
|
2012-09-04 14:28:19 +05:30
|
|
|
xe = calloc(1, sizeof(*xe));
|
|
|
|
assert(xe);
|
2012-09-05 12:30:09 +05:30
|
|
|
xe->file = strdup(fpath);
|
2012-09-04 14:28:19 +05:30
|
|
|
assert(xe->file);
|
2012-09-05 13:29:45 +05:30
|
|
|
|
2012-09-04 14:28:19 +05:30
|
|
|
if ((strcmp(fpath, "./INSTALL") == 0) ||
|
|
|
|
(strcmp(fpath, "./REMOVE") == 0)) {
|
|
|
|
/* metadata file */
|
|
|
|
xe->type = strdup("metadata");
|
|
|
|
assert(xe->type);
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (type == FTW_SL) {
|
2012-09-05 12:30:09 +05:30
|
|
|
/*
|
|
|
|
* Symlinks.
|
|
|
|
*
|
|
|
|
* Find out target file.
|
|
|
|
*/
|
2012-09-04 14:28:19 +05:30
|
|
|
xe->type = strdup("links");
|
|
|
|
assert(xe->type);
|
2012-09-23 18:24:04 +05:30
|
|
|
buf = malloc(sb->st_size+1);
|
|
|
|
assert(buf);
|
|
|
|
r = readlink(fpath, buf, sb->st_size+1);
|
|
|
|
if (r < 0 || r > sb->st_size)
|
|
|
|
die("failed to process symlink %s:", fpath);
|
2012-09-05 13:29:45 +05:30
|
|
|
|
2012-09-23 18:24:04 +05:30
|
|
|
buf[sb->st_size] = '\0';
|
|
|
|
/*
|
|
|
|
* Check if symlink is absolute or relative; on the former
|
|
|
|
* make it absolute for the target object.
|
|
|
|
*/
|
2012-09-23 19:18:02 +05:30
|
|
|
if (strncmp(buf, "../", 3) == 0) {
|
|
|
|
p = realpath(fpath, NULL);
|
2012-10-04 13:10:52 +05:30
|
|
|
if (p == NULL) {
|
|
|
|
/*
|
|
|
|
* This symlink points to an unexistent file,
|
|
|
|
* which might be provided in another package.
|
|
|
|
* So let's use the same target.
|
|
|
|
*/
|
|
|
|
xe->target = strdup(buf);
|
|
|
|
} else {
|
2013-05-27 16:33:40 +05:30
|
|
|
/*
|
|
|
|
* Sanitize destdir just in case.
|
|
|
|
*/
|
|
|
|
if ((p2 = realpath(destdir, NULL)) == NULL)
|
|
|
|
die("failed to sanitize destdir %s: %s", destdir, strerror(errno));
|
|
|
|
|
|
|
|
xe->target = strdup(p+strlen(p2));
|
|
|
|
free(p2);
|
2012-10-04 13:10:52 +05:30
|
|
|
free(p);
|
|
|
|
}
|
2012-09-23 19:18:02 +05:30
|
|
|
} else if (strchr(buf, '/') == NULL) {
|
2012-09-23 18:24:04 +05:30
|
|
|
p = strdup(filep);
|
|
|
|
assert(p);
|
|
|
|
dname = dirname(p);
|
|
|
|
assert(dname);
|
|
|
|
xe->target = xbps_xasprintf("%s/%s", dname, buf);
|
|
|
|
free(p);
|
|
|
|
} else {
|
|
|
|
xe->target = strdup(buf);
|
|
|
|
}
|
2012-09-04 14:28:19 +05:30
|
|
|
assert(xe->target);
|
2012-09-23 18:24:04 +05:30
|
|
|
free(buf);
|
2012-09-04 14:28:19 +05:30
|
|
|
} else if (type == FTW_F) {
|
|
|
|
/*
|
2012-09-05 12:30:09 +05:30
|
|
|
* Regular files.
|
|
|
|
* Find out if it's a configuration file or not
|
|
|
|
* and calculate sha256 hash.
|
2012-09-04 14:28:19 +05:30
|
|
|
*/
|
2012-09-05 13:29:45 +05:30
|
|
|
if (entry_is_conf_file(filep))
|
2012-09-04 14:28:19 +05:30
|
|
|
xe->type = strdup("conf_files");
|
|
|
|
else
|
|
|
|
xe->type = strdup("files");
|
|
|
|
|
|
|
|
assert(xe->type);
|
|
|
|
if ((xe->hash = xbps_file_hash(fpath)) == NULL)
|
|
|
|
die("failed to process hash for %s:", fpath);
|
2012-09-05 12:30:09 +05:30
|
|
|
|
2012-12-12 08:18:27 +05:30
|
|
|
if (sb->st_nlink <= 1)
|
|
|
|
instsize += sb->st_size;
|
2012-09-05 12:30:09 +05:30
|
|
|
|
2012-12-12 08:18:27 +05:30
|
|
|
} else if (type == FTW_D || type == FTW_DP) {
|
2012-09-04 14:28:19 +05:30
|
|
|
/* directory */
|
|
|
|
xe->type = strdup("dirs");
|
|
|
|
assert(xe->type);
|
|
|
|
}
|
|
|
|
|
|
|
|
out:
|
|
|
|
TAILQ_INSERT_TAIL(&xentry_list, xe, entries);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2012-09-08 09:46:51 +05:30
|
|
|
process_xentry(const char *key, const char *mutable_files)
|
2012-09-04 14:28:19 +05:30
|
|
|
{
|
2013-06-20 13:56:12 +05:30
|
|
|
xbps_array_t a;
|
|
|
|
xbps_dictionary_t d;
|
2012-09-04 14:28:19 +05:30
|
|
|
struct xentry *xe;
|
2012-09-08 09:46:51 +05:30
|
|
|
char *p, *saveptr, *args, *tok;
|
|
|
|
bool found = false, mutable_found = false;
|
2012-09-04 14:28:19 +05:30
|
|
|
|
2013-06-20 13:56:12 +05:30
|
|
|
a = xbps_array_create();
|
2012-09-04 14:28:19 +05:30
|
|
|
assert(a);
|
|
|
|
|
|
|
|
TAILQ_FOREACH_REVERSE(xe, &xentry_list, xentry_head, entries) {
|
|
|
|
if (strcmp(xe->type, key))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
found = true;
|
2013-06-20 13:56:12 +05:30
|
|
|
d = xbps_dictionary_create();
|
2012-09-04 14:28:19 +05:30
|
|
|
assert(d);
|
2012-09-05 12:30:09 +05:30
|
|
|
/* sanitize file path */
|
|
|
|
p = strchr(xe->file, '.') + 1;
|
2012-09-08 09:46:51 +05:30
|
|
|
/*
|
|
|
|
* Find out if this file is mutable.
|
|
|
|
*/
|
|
|
|
if (mutable_files) {
|
|
|
|
if ((strchr(mutable_files, ' ') == NULL) &&
|
|
|
|
(strcmp(mutable_files, p) == 0))
|
2013-06-20 13:56:12 +05:30
|
|
|
xbps_dictionary_set_bool(d, "mutable", true);
|
2012-09-08 09:46:51 +05:30
|
|
|
else {
|
|
|
|
args = strdup(mutable_files);
|
|
|
|
assert(args);
|
|
|
|
for ((tok = strtok_r(args, " ", &saveptr)); tok;
|
|
|
|
(tok = strtok_r(NULL, " ", &saveptr))) {
|
|
|
|
if (strcmp(tok, p) == 0) {
|
|
|
|
mutable_found = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
free(args);
|
|
|
|
if (mutable_found) {
|
2013-06-20 13:56:12 +05:30
|
|
|
xbps_dictionary_set_bool(d, "mutable",
|
2012-09-08 09:46:51 +05:30
|
|
|
true);
|
|
|
|
mutable_found = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2013-06-20 13:56:12 +05:30
|
|
|
xbps_dictionary_set_cstring(d, "file", p);
|
2012-09-04 14:28:19 +05:30
|
|
|
if (xe->target)
|
2013-06-20 13:56:12 +05:30
|
|
|
xbps_dictionary_set_cstring(d, "target", xe->target);
|
2012-09-04 14:28:19 +05:30
|
|
|
else if (xe->hash)
|
2013-06-20 13:56:12 +05:30
|
|
|
xbps_dictionary_set_cstring(d, "sha256", xe->hash);
|
|
|
|
xbps_array_add(a, d);
|
|
|
|
xbps_object_release(d);
|
2012-09-04 14:28:19 +05:30
|
|
|
}
|
|
|
|
if (found)
|
2013-06-20 13:56:12 +05:30
|
|
|
xbps_dictionary_set(pkg_filesd, key, a);
|
2012-09-04 14:28:19 +05:30
|
|
|
|
2013-06-20 13:56:12 +05:30
|
|
|
xbps_object_release(a);
|
2012-09-04 14:28:19 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2012-09-08 09:46:51 +05:30
|
|
|
process_destdir(const char *mutable_files)
|
2012-09-04 14:28:19 +05:30
|
|
|
{
|
|
|
|
if (nftw(".", ftw_cb, 20, FTW_PHYS|FTW_MOUNT) != 0)
|
|
|
|
die("failed to process destdir files (nftw):");
|
|
|
|
|
|
|
|
/* Process regular files */
|
2012-09-08 09:46:51 +05:30
|
|
|
process_xentry("files", mutable_files);
|
2012-09-04 14:28:19 +05:30
|
|
|
|
|
|
|
/* Process configuration files */
|
2012-09-08 09:46:51 +05:30
|
|
|
process_xentry("conf_files", NULL);
|
2012-09-04 14:28:19 +05:30
|
|
|
|
|
|
|
/* Process symlinks */
|
2012-09-08 09:46:51 +05:30
|
|
|
process_xentry("links", NULL);
|
2012-09-04 14:28:19 +05:30
|
|
|
|
|
|
|
/* Process directories */
|
2012-09-08 09:46:51 +05:30
|
|
|
process_xentry("dirs", NULL);
|
2012-09-04 14:28:19 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2012-12-12 08:18:27 +05:30
|
|
|
write_entry(struct archive *ar, struct archive_entry *entry)
|
2012-09-04 14:28:19 +05:30
|
|
|
{
|
2012-12-12 08:18:27 +05:30
|
|
|
char buf[16384];
|
|
|
|
const char *name;
|
2012-09-23 18:24:04 +05:30
|
|
|
int fd = -1;
|
2012-12-12 08:18:27 +05:30
|
|
|
off_t len;
|
|
|
|
ssize_t buf_len;
|
|
|
|
|
|
|
|
if (archive_entry_pathname(entry) == NULL)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (archive_write_header(ar, entry)) {
|
|
|
|
die("cannot write %s to archive: %s",
|
|
|
|
archive_entry_pathname(entry),
|
|
|
|
archive_error_string(ar));
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Only regular files can have data. */
|
|
|
|
if (archive_entry_filetype(entry) != AE_IFREG ||
|
|
|
|
archive_entry_size(entry) == 0) {
|
|
|
|
archive_entry_free(entry);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
name = archive_entry_sourcepath(entry);
|
|
|
|
fd = open(name, O_RDONLY);
|
|
|
|
assert(fd != -1);
|
|
|
|
|
|
|
|
len = archive_entry_size(entry);
|
|
|
|
while (len > 0) {
|
|
|
|
buf_len = (len > (off_t)sizeof(buf)) ?
|
|
|
|
(ssize_t)sizeof(buf) : (ssize_t)len;
|
|
|
|
|
|
|
|
if ((buf_len = read(fd, buf, buf_len)) == 0)
|
|
|
|
break;
|
|
|
|
else if (buf_len < 0)
|
|
|
|
die("cannot read from %s", name);
|
|
|
|
|
|
|
|
archive_write_data(ar, buf, (size_t)buf_len);
|
|
|
|
len -= buf_len;
|
|
|
|
}
|
|
|
|
close(fd);
|
|
|
|
|
|
|
|
archive_entry_free(entry);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
process_entry_file(struct archive *ar,
|
|
|
|
struct archive_entry_linkresolver *resolver,
|
|
|
|
struct xentry *xe, const char *filematch)
|
|
|
|
{
|
|
|
|
struct archive_entry *entry, *sparse_entry;
|
|
|
|
struct stat st;
|
|
|
|
char buf[16384], *p;
|
|
|
|
ssize_t len;
|
2012-09-04 14:28:19 +05:30
|
|
|
|
|
|
|
assert(ar);
|
|
|
|
assert(xe);
|
|
|
|
|
|
|
|
if (filematch && strcmp(xe->file, filematch))
|
|
|
|
return;
|
|
|
|
|
2012-12-12 08:18:27 +05:30
|
|
|
p = xbps_xasprintf("%s/%s", destdir, xe->file);
|
|
|
|
if (lstat(p, &st) == -1)
|
|
|
|
die("failed to add entry (fstat) %s to archive:", xe->file);
|
2012-09-04 14:28:19 +05:30
|
|
|
|
|
|
|
entry = archive_entry_new();
|
|
|
|
assert(entry);
|
2012-09-23 18:24:04 +05:30
|
|
|
archive_entry_set_pathname(entry, xe->file);
|
2013-03-15 17:44:57 +05:30
|
|
|
if (st.st_uid == geteuid())
|
|
|
|
st.st_uid = 0;
|
|
|
|
if (st.st_gid == getegid())
|
|
|
|
st.st_gid = 0;
|
|
|
|
|
2012-12-12 08:18:27 +05:30
|
|
|
archive_entry_copy_stat(entry, &st);
|
2012-09-23 18:24:04 +05:30
|
|
|
archive_entry_copy_sourcepath(entry, p);
|
2013-03-15 14:01:15 +05:30
|
|
|
if (st.st_uid == geteuid())
|
|
|
|
archive_entry_set_uname(entry, "root");
|
|
|
|
if (st.st_gid == getegid())
|
|
|
|
archive_entry_set_gname(entry, "root");
|
2012-09-05 12:30:09 +05:30
|
|
|
|
2012-09-23 18:24:04 +05:30
|
|
|
if (S_ISLNK(st.st_mode)) {
|
2012-12-12 08:18:27 +05:30
|
|
|
len = readlink(p, buf, sizeof(buf));
|
|
|
|
if (len < 0 || len > st.st_size)
|
2012-09-23 18:24:04 +05:30
|
|
|
die("failed to add entry %s (readlink) to archive:",
|
|
|
|
xe->file);
|
2012-12-12 08:18:27 +05:30
|
|
|
buf[len] = '\0';
|
|
|
|
archive_entry_set_symlink(entry, buf);
|
2012-09-23 18:24:04 +05:30
|
|
|
}
|
|
|
|
free(p);
|
2012-12-12 08:18:27 +05:30
|
|
|
|
|
|
|
archive_entry_linkify(resolver, &entry, &sparse_entry);
|
|
|
|
|
|
|
|
if (entry != NULL)
|
|
|
|
write_entry(ar, entry);
|
|
|
|
if (sparse_entry != NULL)
|
|
|
|
write_entry(ar, sparse_entry);
|
2012-09-04 14:28:19 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2012-12-12 08:18:27 +05:30
|
|
|
process_archive(struct archive *ar,
|
|
|
|
struct archive_entry_linkresolver *resolver,
|
|
|
|
const char *pkgver, bool quiet)
|
2012-09-04 14:28:19 +05:30
|
|
|
{
|
|
|
|
struct xentry *xe;
|
|
|
|
char *xml;
|
|
|
|
|
|
|
|
/* Add INSTALL/REMOVE metadata scripts first */
|
|
|
|
TAILQ_FOREACH(xe, &xentry_list, entries) {
|
2012-12-12 08:18:27 +05:30
|
|
|
process_entry_file(ar, resolver, xe, "./INSTALL");
|
|
|
|
process_entry_file(ar, resolver, xe, "./REMOVE");
|
2012-09-04 14:28:19 +05:30
|
|
|
}
|
2012-09-05 12:30:09 +05:30
|
|
|
/*
|
|
|
|
* Add the installed-size object.
|
|
|
|
*/
|
2013-06-20 13:56:12 +05:30
|
|
|
xbps_dictionary_set_uint64(pkg_propsd, "installed_size", instsize);
|
2012-09-04 14:28:19 +05:30
|
|
|
|
|
|
|
/* Add props.plist metadata file */
|
2013-06-20 13:56:12 +05:30
|
|
|
xml = xbps_dictionary_externalize(pkg_propsd);
|
2012-09-04 14:28:19 +05:30
|
|
|
assert(xml);
|
2013-06-10 13:58:39 +05:30
|
|
|
xbps_archive_append_buf(ar, xml, strlen(xml), "./props.plist",
|
|
|
|
0644, "root", "root");
|
2012-09-04 14:28:19 +05:30
|
|
|
free(xml);
|
|
|
|
|
|
|
|
/* Add files.plist metadata file */
|
2013-06-20 13:56:12 +05:30
|
|
|
xml = xbps_dictionary_externalize(pkg_filesd);
|
2012-09-04 14:28:19 +05:30
|
|
|
assert(xml);
|
2013-06-10 13:58:39 +05:30
|
|
|
xbps_archive_append_buf(ar, xml, strlen(xml), "./files.plist",
|
|
|
|
0644, "root", "root");
|
2012-09-04 14:28:19 +05:30
|
|
|
free(xml);
|
|
|
|
|
|
|
|
/* Add all package data files and release resources */
|
|
|
|
while ((xe = TAILQ_FIRST(&xentry_list)) != NULL) {
|
|
|
|
TAILQ_REMOVE(&xentry_list, xe, entries);
|
|
|
|
if ((strcmp(xe->type, "metadata") == 0) ||
|
2012-12-14 16:28:30 +05:30
|
|
|
(strcmp(xe->type, "dirs") == 0))
|
2012-09-04 14:28:19 +05:30
|
|
|
continue;
|
2012-12-14 16:28:30 +05:30
|
|
|
|
2012-09-23 05:03:51 +05:30
|
|
|
if (!quiet) {
|
|
|
|
printf("%s: adding `%s' ...\n", pkgver, xe->file);
|
|
|
|
fflush(stdout);
|
|
|
|
}
|
2012-12-12 08:18:27 +05:30
|
|
|
process_entry_file(ar, resolver, xe, NULL);
|
2012-09-04 14:28:19 +05:30
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-09-05 12:30:09 +05:30
|
|
|
static void
|
|
|
|
set_build_date(void)
|
|
|
|
{
|
|
|
|
char outstr[64];
|
|
|
|
time_t t;
|
|
|
|
struct tm *tmp;
|
|
|
|
|
|
|
|
t = time(NULL);
|
|
|
|
tmp = localtime(&t);
|
|
|
|
assert(tmp);
|
|
|
|
|
|
|
|
if (strftime(outstr, sizeof(outstr)-1, "%F %R %Z", tmp) == 0)
|
|
|
|
die("failed to set build-date object (strftime):");
|
|
|
|
|
2013-06-20 13:56:12 +05:30
|
|
|
if (!xbps_dictionary_set_cstring(pkg_propsd, "build-date", outstr))
|
2012-09-05 12:30:09 +05:30
|
|
|
die("failed to add build-date object:");
|
|
|
|
}
|
|
|
|
|
2012-09-04 14:28:19 +05:30
|
|
|
int
|
|
|
|
main(int argc, char **argv)
|
|
|
|
{
|
2012-11-20 08:51:26 +05:30
|
|
|
const char *shortopts = "A:B:C:D:F:G:H:hl:M:m:n:P:pqR:S:s:V";
|
2012-11-02 19:33:33 +05:30
|
|
|
const struct option longopts[] = {
|
2012-09-04 14:28:19 +05:30
|
|
|
{ "architecture", required_argument, NULL, 'A' },
|
2012-09-11 11:48:31 +05:30
|
|
|
{ "built-with", required_argument, NULL, 'B' },
|
2012-11-20 08:51:26 +05:30
|
|
|
{ "source-revisions", required_argument, NULL, 'G' },
|
2012-09-04 14:28:19 +05:30
|
|
|
{ "conflicts", required_argument, NULL, 'C' },
|
|
|
|
{ "dependencies", required_argument, NULL, 'D' },
|
|
|
|
{ "config-files", required_argument, NULL, 'F' },
|
2012-09-24 15:59:27 +05:30
|
|
|
{ "homepage", required_argument, NULL, 'H' },
|
|
|
|
{ "help", no_argument, NULL, 'h' },
|
2012-09-04 14:28:19 +05:30
|
|
|
{ "license", required_argument, NULL, 'l' },
|
|
|
|
{ "mutable-files", required_argument, NULL, 'M' },
|
|
|
|
{ "maintainer", required_argument, NULL, 'm' },
|
|
|
|
{ "pkgver", required_argument, NULL, 'n' },
|
|
|
|
{ "provides", required_argument, NULL, 'P' },
|
|
|
|
{ "preserve", no_argument, NULL, 'p' },
|
2012-09-23 05:03:51 +05:30
|
|
|
{ "quiet", no_argument, NULL, 'q' },
|
2012-09-04 14:28:19 +05:30
|
|
|
{ "replaces", required_argument, NULL, 'R' },
|
|
|
|
{ "long-desc", required_argument, NULL, 'S' },
|
|
|
|
{ "desc", required_argument, NULL, 's' },
|
|
|
|
{ "version", no_argument, NULL, 'V' },
|
2012-12-24 15:25:17 +05:30
|
|
|
{ "shlib-provides", required_argument, NULL, '0' },
|
|
|
|
{ "shlib-requires", required_argument, NULL, '1' },
|
2013-03-23 12:48:06 +05:30
|
|
|
{ "build-options", required_argument, NULL, '2' },
|
2012-11-02 19:33:33 +05:30
|
|
|
{ NULL, 0, NULL, 0 }
|
2012-09-04 14:28:19 +05:30
|
|
|
};
|
|
|
|
struct archive *ar;
|
2012-12-12 08:18:27 +05:30
|
|
|
struct archive_entry *entry, *sparse_entry;
|
|
|
|
struct archive_entry_linkresolver *resolver;
|
2012-09-04 14:28:19 +05:30
|
|
|
struct stat st;
|
2012-09-11 11:48:31 +05:30
|
|
|
const char *conflicts, *deps, *homepage, *license, *maint, *bwith;
|
2012-09-04 14:28:19 +05:30
|
|
|
const char *provides, *pkgver, *replaces, *desc, *ldesc;
|
|
|
|
const char *arch, *config_files, *mutable_files, *version;
|
2013-03-23 12:48:06 +05:30
|
|
|
const char *buildopts, *shlib_provides, *shlib_requires;
|
2012-11-20 08:51:26 +05:30
|
|
|
const char *srcrevs = NULL;
|
2012-09-05 12:30:09 +05:30
|
|
|
char *pkgname, *binpkg, *tname, *p, cwd[PATH_MAX-1];
|
2012-09-23 05:03:51 +05:30
|
|
|
bool quiet = false, preserve = false;
|
2012-09-05 12:30:09 +05:30
|
|
|
int c, pkg_fd;
|
|
|
|
mode_t myumask;
|
2012-09-04 14:28:19 +05:30
|
|
|
|
|
|
|
arch = conflicts = deps = homepage = license = maint = NULL;
|
2013-03-23 12:48:06 +05:30
|
|
|
provides = pkgver = replaces = desc = ldesc = bwith = buildopts = NULL;
|
2012-12-24 15:25:17 +05:30
|
|
|
config_files = mutable_files = shlib_provides = shlib_requires = NULL;
|
2012-09-04 14:28:19 +05:30
|
|
|
|
2012-11-02 19:33:33 +05:30
|
|
|
while ((c = getopt_long(argc, argv, shortopts, longopts, NULL)) != -1) {
|
2012-09-23 05:03:51 +05:30
|
|
|
if (optarg && strcmp(optarg, "") == 0)
|
|
|
|
optarg = NULL;
|
|
|
|
|
2012-09-04 14:28:19 +05:30
|
|
|
switch (c) {
|
|
|
|
case 'A':
|
|
|
|
arch = optarg;
|
|
|
|
break;
|
2012-09-11 11:48:31 +05:30
|
|
|
case 'B':
|
|
|
|
bwith = optarg;
|
|
|
|
break;
|
2012-09-04 14:28:19 +05:30
|
|
|
case 'C':
|
|
|
|
conflicts = optarg;
|
|
|
|
break;
|
|
|
|
case 'D':
|
|
|
|
deps = optarg;
|
|
|
|
break;
|
|
|
|
case 'F':
|
|
|
|
config_files = optarg;
|
|
|
|
break;
|
2012-11-20 08:51:26 +05:30
|
|
|
case 'G':
|
|
|
|
srcrevs = optarg;
|
|
|
|
break;
|
2012-09-04 14:28:19 +05:30
|
|
|
case 'h':
|
2012-09-24 15:59:27 +05:30
|
|
|
usage();
|
|
|
|
break;
|
|
|
|
case 'H':
|
2012-09-04 14:28:19 +05:30
|
|
|
homepage = optarg;
|
|
|
|
break;
|
|
|
|
case 'l':
|
|
|
|
license = optarg;
|
|
|
|
break;
|
|
|
|
case 'M':
|
|
|
|
mutable_files = optarg;
|
|
|
|
break;
|
|
|
|
case 'm':
|
|
|
|
maint = optarg;
|
|
|
|
break;
|
|
|
|
case 'n':
|
|
|
|
pkgver = optarg;
|
|
|
|
break;
|
|
|
|
case 'P':
|
|
|
|
provides = optarg;
|
|
|
|
break;
|
|
|
|
case 'p':
|
|
|
|
preserve = true;
|
|
|
|
break;
|
2012-09-23 05:03:51 +05:30
|
|
|
case 'q':
|
|
|
|
quiet = true;
|
|
|
|
break;
|
2012-09-04 14:28:19 +05:30
|
|
|
case 'R':
|
|
|
|
replaces = optarg;
|
|
|
|
break;
|
|
|
|
case 'S':
|
|
|
|
ldesc = optarg;
|
|
|
|
break;
|
|
|
|
case 's':
|
|
|
|
desc = optarg;
|
|
|
|
break;
|
|
|
|
case 'V':
|
|
|
|
printf("%s\n", XBPS_RELVER);
|
|
|
|
exit(EXIT_SUCCESS);
|
2012-12-24 15:25:17 +05:30
|
|
|
case '0':
|
|
|
|
shlib_provides = optarg;
|
|
|
|
break;
|
|
|
|
case '1':
|
|
|
|
shlib_requires = optarg;
|
|
|
|
break;
|
2013-03-23 12:48:06 +05:30
|
|
|
case '2':
|
|
|
|
buildopts = optarg;
|
|
|
|
break;
|
2012-09-04 14:28:19 +05:30
|
|
|
case '?':
|
|
|
|
default:
|
|
|
|
usage();
|
|
|
|
}
|
|
|
|
}
|
2012-11-02 19:33:33 +05:30
|
|
|
if (argc == optind)
|
2012-09-30 10:42:31 +05:30
|
|
|
usage();
|
|
|
|
|
2012-11-02 19:33:33 +05:30
|
|
|
destdir = argv[optind];
|
2012-09-30 10:42:31 +05:30
|
|
|
|
2013-04-01 14:19:25 +05:30
|
|
|
setlocale(LC_ALL, "");
|
|
|
|
|
2012-09-30 10:42:31 +05:30
|
|
|
if (pkgver == NULL)
|
2012-09-04 14:28:19 +05:30
|
|
|
die("pkgver not set!");
|
|
|
|
else if (desc == NULL)
|
|
|
|
die("short description not set!");
|
|
|
|
else if (arch == NULL)
|
|
|
|
die("architecture not set!");
|
|
|
|
/*
|
|
|
|
* Sanity check for required options.
|
|
|
|
*/
|
|
|
|
pkgname = xbps_pkg_name(pkgver);
|
|
|
|
if (pkgname == NULL)
|
|
|
|
die("invalid pkgver! got `%s' expected `foo-1.0_1'", pkgver);
|
|
|
|
version = xbps_pkg_version(pkgver);
|
|
|
|
if (version == NULL)
|
|
|
|
die("invalid pkgver! got `%s' expected `foo-1.0_1'", pkgver);
|
|
|
|
|
|
|
|
if (stat(destdir, &st) == -1)
|
|
|
|
die("failed to stat() destdir `%s':", destdir);
|
|
|
|
if (!S_ISDIR(st.st_mode))
|
|
|
|
die("destdir `%s' is not a directory!", destdir);
|
|
|
|
/*
|
|
|
|
* Process XBPS_PKGPROPS metadata file.
|
|
|
|
*/
|
2013-06-20 13:56:12 +05:30
|
|
|
pkg_propsd = xbps_dictionary_create();
|
2012-09-04 14:28:19 +05:30
|
|
|
assert(pkg_propsd);
|
|
|
|
|
|
|
|
/* Required properties */
|
2013-06-20 13:56:12 +05:30
|
|
|
xbps_dictionary_set_cstring_nocopy(pkg_propsd, "architecture", arch);
|
|
|
|
xbps_dictionary_set_cstring_nocopy(pkg_propsd, "pkgname", pkgname);
|
|
|
|
xbps_dictionary_set_cstring_nocopy(pkg_propsd, "version", version);
|
|
|
|
xbps_dictionary_set_cstring_nocopy(pkg_propsd, "pkgver", pkgver);
|
|
|
|
xbps_dictionary_set_cstring_nocopy(pkg_propsd, "short_desc", desc);
|
2012-09-05 12:30:09 +05:30
|
|
|
set_build_date();
|
2012-09-04 14:28:19 +05:30
|
|
|
|
|
|
|
/* Optional properties */
|
|
|
|
if (homepage)
|
2013-06-20 13:56:12 +05:30
|
|
|
xbps_dictionary_set_cstring_nocopy(pkg_propsd,
|
2012-09-11 11:48:31 +05:30
|
|
|
"homepage", homepage);
|
2012-09-04 14:28:19 +05:30
|
|
|
if (license)
|
2013-06-20 13:56:12 +05:30
|
|
|
xbps_dictionary_set_cstring_nocopy(pkg_propsd,
|
2012-09-11 11:48:31 +05:30
|
|
|
"license", license);
|
2012-09-04 14:28:19 +05:30
|
|
|
if (maint)
|
2013-06-20 13:56:12 +05:30
|
|
|
xbps_dictionary_set_cstring_nocopy(pkg_propsd,
|
2012-09-11 11:48:31 +05:30
|
|
|
"maintainer", maint);
|
2012-09-04 14:28:19 +05:30
|
|
|
if (ldesc)
|
2013-06-20 13:56:12 +05:30
|
|
|
xbps_dictionary_set_cstring_nocopy(pkg_propsd,
|
2012-09-11 11:48:31 +05:30
|
|
|
"long_desc", ldesc);
|
|
|
|
if (bwith)
|
2013-06-20 13:56:12 +05:30
|
|
|
xbps_dictionary_set_cstring_nocopy(pkg_propsd,
|
2012-09-11 11:48:31 +05:30
|
|
|
"packaged-with", bwith);
|
2012-11-20 08:51:26 +05:30
|
|
|
if (srcrevs)
|
2013-06-20 13:56:12 +05:30
|
|
|
xbps_dictionary_set_cstring_nocopy(pkg_propsd,
|
2012-11-20 08:51:26 +05:30
|
|
|
"source-revisions", srcrevs);
|
2012-09-04 14:28:19 +05:30
|
|
|
if (preserve)
|
2013-06-20 13:56:12 +05:30
|
|
|
xbps_dictionary_set_bool(pkg_propsd, "preserve", true);
|
2013-03-23 12:48:06 +05:30
|
|
|
if (buildopts)
|
2013-06-20 13:56:12 +05:30
|
|
|
xbps_dictionary_set_cstring_nocopy(pkg_propsd,
|
2013-03-23 12:48:06 +05:30
|
|
|
"build-options", buildopts);
|
2012-09-04 14:28:19 +05:30
|
|
|
|
|
|
|
/* Optional arrays */
|
|
|
|
process_array("run_depends", deps);
|
|
|
|
process_array("conf_files", config_files);
|
|
|
|
process_array("conflicts", conflicts);
|
|
|
|
process_array("provides", provides);
|
|
|
|
process_array("replaces", replaces);
|
2012-12-24 15:25:17 +05:30
|
|
|
process_array("shlib-provides", shlib_provides);
|
|
|
|
process_array("shlib-requires", shlib_requires);
|
2012-09-04 14:28:19 +05:30
|
|
|
|
2012-09-05 12:30:09 +05:30
|
|
|
/* save cwd */
|
|
|
|
memset(&cwd, 0, sizeof(cwd));
|
|
|
|
p = getcwd(cwd, sizeof(cwd));
|
|
|
|
assert(p);
|
|
|
|
|
2012-09-04 14:28:19 +05:30
|
|
|
if (chdir(destdir) == -1)
|
2012-09-05 12:30:09 +05:30
|
|
|
die("cannot chdir() to destdir %s:", destdir);
|
2012-09-04 14:28:19 +05:30
|
|
|
/*
|
|
|
|
* Process XBPS_PKGFILES metadata file.
|
|
|
|
*/
|
2013-06-20 13:56:12 +05:30
|
|
|
pkg_filesd = xbps_dictionary_create();
|
2012-09-04 14:28:19 +05:30
|
|
|
assert(pkg_filesd);
|
2012-09-08 09:46:51 +05:30
|
|
|
process_destdir(mutable_files);
|
2012-09-04 14:28:19 +05:30
|
|
|
|
2012-09-05 12:30:09 +05:30
|
|
|
/* Back to original cwd after file tree walk processing */
|
2012-11-25 15:33:03 +05:30
|
|
|
if (chdir(p) == -1)
|
2012-09-05 12:30:09 +05:30
|
|
|
die("cannot chdir() to cwd %s:", cwd);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Create a temp file to store archive data.
|
|
|
|
*/
|
|
|
|
tname = xbps_xasprintf(".xbps-pkg-XXXXXX");
|
|
|
|
pkg_fd = mkstemp(tname);
|
|
|
|
assert(pkg_fd != -1);
|
2012-09-04 14:28:19 +05:30
|
|
|
/*
|
2012-09-05 12:30:09 +05:30
|
|
|
* Process the binary package's archive (ustar compressed with xz).
|
2012-09-04 14:28:19 +05:30
|
|
|
*/
|
|
|
|
ar = archive_write_new();
|
|
|
|
assert(ar);
|
|
|
|
archive_write_add_filter_xz(ar);
|
2012-12-12 08:18:27 +05:30
|
|
|
archive_write_set_format_pax_restricted(ar);
|
|
|
|
if ((resolver = archive_entry_linkresolver_new()) == NULL)
|
|
|
|
die("cannot create link resolver");
|
|
|
|
archive_entry_linkresolver_set_strategy(resolver,
|
|
|
|
archive_format(ar));
|
|
|
|
|
2012-09-04 14:28:19 +05:30
|
|
|
archive_write_set_options(ar, "compression-level=9");
|
2012-09-05 12:30:09 +05:30
|
|
|
if (archive_write_open_fd(ar, pkg_fd) != 0)
|
|
|
|
die("Failed to open %s fd for writing:", tname);
|
2012-09-04 14:28:19 +05:30
|
|
|
|
2012-12-12 08:18:27 +05:30
|
|
|
process_archive(ar, resolver, pkgver, quiet);
|
|
|
|
/* Process hardlinks */
|
|
|
|
entry = NULL;
|
|
|
|
archive_entry_linkify(resolver, &entry, &sparse_entry);
|
|
|
|
while (entry != NULL) {
|
|
|
|
write_entry(ar, entry);
|
|
|
|
entry = NULL;
|
|
|
|
archive_entry_linkify(resolver, &entry, &sparse_entry);
|
|
|
|
}
|
|
|
|
archive_entry_linkresolver_free(resolver);
|
|
|
|
/* close and free archive */
|
2012-09-05 12:30:09 +05:30
|
|
|
archive_write_free(ar);
|
2012-12-12 08:18:27 +05:30
|
|
|
|
2012-09-05 12:30:09 +05:30
|
|
|
/*
|
|
|
|
* Archive was created successfully; flush data to storage,
|
|
|
|
* set permissions and rename to dest file; from the caller's
|
|
|
|
* perspective it's atomic.
|
|
|
|
*/
|
2012-09-04 14:28:19 +05:30
|
|
|
binpkg = xbps_xasprintf("%s.%s.xbps", pkgver, arch);
|
|
|
|
|
2012-09-05 12:30:09 +05:30
|
|
|
(void)fsync(pkg_fd);
|
|
|
|
myumask = umask(0);
|
|
|
|
(void)umask(myumask);
|
2012-09-04 14:28:19 +05:30
|
|
|
|
2012-09-05 12:30:09 +05:30
|
|
|
if (fchmod(pkg_fd, 0666 & ~myumask) == -1)
|
|
|
|
die("cannot fchmod() %s:", tname);
|
|
|
|
|
2012-12-14 16:28:30 +05:30
|
|
|
close(pkg_fd);
|
|
|
|
|
2012-09-05 12:30:09 +05:30
|
|
|
if (rename(tname, binpkg) == -1)
|
|
|
|
die("cannot rename %s to %s:", tname, binpkg);
|
|
|
|
|
|
|
|
/* Success, release resources */
|
2012-09-23 05:03:51 +05:30
|
|
|
if (!quiet)
|
|
|
|
printf("%s: binary package created successfully (%s)\n",
|
|
|
|
pkgver, binpkg);
|
2012-09-04 14:28:19 +05:30
|
|
|
|
|
|
|
exit(EXIT_SUCCESS);
|
|
|
|
}
|