2012-09-04 14:28:19 +05:30
|
|
|
/*-
|
2020-04-29 17:42:10 +05:30
|
|
|
* Copyright (c) 2012-2019 Juan Romero Pardines.
|
|
|
|
* 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.
|
2012-09-04 14:28:19 +05:30
|
|
|
*/
|
|
|
|
#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>
|
2018-07-07 15:45:00 +05:30
|
|
|
#include <dirent.h>
|
2012-09-04 14:28:19 +05:30
|
|
|
|
2013-06-20 16:01:02 +05:30
|
|
|
#include <xbps.h>
|
2018-07-06 11:37:55 +05:30
|
|
|
#include "queue.h"
|
2012-09-04 14:28:19 +05:30
|
|
|
|
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"
|
|
|
|
|
2022-12-23 02:30:47 +05:30
|
|
|
enum entry_type {
|
|
|
|
ENTRY_TYPE_METADATA = 1,
|
|
|
|
ENTRY_TYPE_LINKS,
|
|
|
|
ENTRY_TYPE_DIRS,
|
|
|
|
ENTRY_TYPE_FILES,
|
|
|
|
ENTRY_TYPE_CONF_FILES,
|
|
|
|
};
|
|
|
|
|
2018-07-06 11:37:55 +05:30
|
|
|
struct xentry {
|
|
|
|
TAILQ_ENTRY(xentry) entries;
|
2019-06-16 19:56:38 +05:30
|
|
|
uint64_t size;
|
2022-12-23 02:30:47 +05:30
|
|
|
enum entry_type type;
|
|
|
|
char *file, *target;
|
2020-02-10 06:24:52 +05:30
|
|
|
char sha256[XBPS_SHA256_SIZE];
|
2018-07-06 11:37:55 +05:30
|
|
|
ino_t inode;
|
|
|
|
};
|
|
|
|
|
|
|
|
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;
|
2016-03-27 07:16:42 +05:30
|
|
|
static xbps_dictionary_t pkg_propsd, pkg_filesd, all_filesd;
|
2012-09-04 14:28:19 +05:30
|
|
|
static const char *destdir;
|
|
|
|
|
|
|
|
static void __attribute__((noreturn))
|
2020-04-21 00:55:14 +05:30
|
|
|
usage(bool fail)
|
2012-09-04 14:28:19 +05:30
|
|
|
{
|
2012-09-24 14:19:45 +05:30
|
|
|
fprintf(stdout,
|
2014-05-29 15:06:39 +05:30
|
|
|
"Usage: %s [OPTIONS] -A <arch> -n <pkgver> -s \"<desc>\" destdir\n\n"
|
2012-11-02 19:33:33 +05:30
|
|
|
"OPTIONS\n"
|
2020-04-21 00:55:14 +05:30
|
|
|
" -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, e.g: 'foo>=2.0 blah<=2.0')\n"
|
|
|
|
" -c, --changelog Changelog URL\n"
|
|
|
|
" -D, --dependencies Dependencies (blank separated list, 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 usage\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, 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, e.g: 'foo>=1.0 blah<2.0')\n"
|
|
|
|
" -r, --reverts Reverts (blank separated list, e.g: '1.0_1 2.0_3')\n"
|
|
|
|
" -S, --long-desc Long description (80 cols per line)\n"
|
|
|
|
" -s, --desc Short description (max 80 characters)\n"
|
|
|
|
" -t, --tags A list of tags/categories (blank separated list)\n"
|
|
|
|
" -V, --version Show XBPS version\n"
|
|
|
|
" --alternatives List of available alternatives this pkg provides\n"
|
|
|
|
" This expects a blank separated list of <name>:<symlink>:<target>, e.g\n"
|
|
|
|
" 'vi:/usr/bin/vi:/usr/bin/vim foo:/usr/bin/foo:/usr/bin/blah'\n"
|
|
|
|
" --build-options A string with the used build options\n"
|
|
|
|
" --compression Compression format: none, gzip, bzip2, lz4, xz, zstd (default)\n"
|
|
|
|
" --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);
|
2020-04-21 00:55:14 +05:30
|
|
|
exit(fail ? EXIT_FAILURE : EXIT_SUCCESS);
|
2012-09-04 14:28:19 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
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);
|
2022-12-23 02:46:47 +05:30
|
|
|
fprintf(stderr, ": %s\n", save_errno ? strerror(save_errno) : "");
|
|
|
|
va_end(ap);
|
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void __attribute__((noreturn))
|
|
|
|
diex(const char *fmt, ...)
|
|
|
|
{
|
|
|
|
va_list ap;
|
|
|
|
|
|
|
|
va_start(ap, fmt);
|
|
|
|
fprintf(stderr, "%s: ERROR: ", _PROGNAME);
|
|
|
|
vfprintf(stderr, fmt, ap);
|
|
|
|
fprintf(stderr, "\n");
|
2012-09-04 14:28:19 +05:30
|
|
|
va_end(ap);
|
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
}
|
|
|
|
|
2019-10-26 02:16:14 +05:30
|
|
|
static void __attribute__((noreturn))
|
|
|
|
die_archive(struct archive *ar, const char *fmt, ...)
|
|
|
|
{
|
|
|
|
va_list ap;
|
|
|
|
|
|
|
|
va_start(ap, fmt);
|
|
|
|
fprintf(stderr, "%s: ERROR: ", _PROGNAME);
|
|
|
|
vfprintf(stderr, fmt, ap);
|
2022-12-23 02:46:47 +05:30
|
|
|
fprintf(stderr, ": %s\n", archive_error_string(ar));
|
2019-10-26 02:16:14 +05:30
|
|
|
va_end(ap);
|
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
}
|
|
|
|
|
2022-12-23 02:30:47 +05:30
|
|
|
static const char *
|
|
|
|
entry_type_str(enum entry_type type)
|
|
|
|
{
|
|
|
|
switch (type) {
|
|
|
|
case ENTRY_TYPE_LINKS:
|
|
|
|
return "links";
|
|
|
|
case ENTRY_TYPE_DIRS:
|
|
|
|
return "dirs";
|
|
|
|
case ENTRY_TYPE_FILES:
|
|
|
|
return "files";
|
|
|
|
case ENTRY_TYPE_CONF_FILES:
|
|
|
|
return "conf_files";
|
|
|
|
case ENTRY_TYPE_METADATA:
|
|
|
|
return "metadata";
|
|
|
|
}
|
|
|
|
diex("unknown entry type");
|
|
|
|
}
|
|
|
|
|
2012-09-04 14:28:19 +05:30
|
|
|
static void
|
|
|
|
process_array(const char *key, const char *val)
|
|
|
|
{
|
2014-05-16 13:17:35 +05:30
|
|
|
xbps_array_t array = NULL;
|
|
|
|
char *args, *p = NULL, *saveptr = NULL;
|
2012-09-04 14:28:19 +05:30
|
|
|
|
|
|
|
assert(key);
|
|
|
|
|
|
|
|
if (val == NULL)
|
|
|
|
return;
|
|
|
|
|
2013-06-20 13:56:12 +05:30
|
|
|
array = xbps_array_create();
|
2022-12-23 02:46:47 +05:30
|
|
|
if (array == NULL)
|
|
|
|
die("xbps_array_create");
|
2012-09-04 14:28:19 +05:30
|
|
|
|
|
|
|
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);
|
2022-12-23 02:46:47 +05:30
|
|
|
if (args == NULL)
|
|
|
|
die("strdup");
|
2012-09-04 14:28:19 +05:30
|
|
|
|
|
|
|
for ((p = strtok_r(args, " ", &saveptr)); p;
|
|
|
|
(p = strtok_r(NULL, " ", &saveptr))) {
|
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
|
|
|
}
|
|
|
|
|
2015-10-18 14:08:35 +05:30
|
|
|
static void
|
|
|
|
process_one_alternative(const char *altgrname, const char *val)
|
|
|
|
{
|
|
|
|
xbps_dictionary_t d;
|
|
|
|
xbps_array_t a;
|
|
|
|
char *altfiles;
|
|
|
|
bool alloc = false;
|
|
|
|
|
|
|
|
if ((d = xbps_dictionary_get(pkg_propsd, "alternatives")) == NULL) {
|
|
|
|
d = xbps_dictionary_create();
|
2022-12-23 02:46:47 +05:30
|
|
|
if (d == NULL)
|
|
|
|
die("xbps_dictionary_create");
|
2015-10-18 14:08:35 +05:30
|
|
|
alloc = true;
|
|
|
|
}
|
|
|
|
if ((a = xbps_dictionary_get(d, altgrname)) == NULL) {
|
|
|
|
a = xbps_array_create();
|
2022-12-23 02:46:47 +05:30
|
|
|
if (a == NULL)
|
|
|
|
die("xbps_array_create");
|
2015-10-18 14:08:35 +05:30
|
|
|
}
|
|
|
|
altfiles = strchr(val, ':') + 1;
|
|
|
|
assert(altfiles);
|
|
|
|
|
|
|
|
xbps_array_add_cstring(a, altfiles);
|
|
|
|
xbps_dictionary_set(d, altgrname, a);
|
|
|
|
xbps_dictionary_set(pkg_propsd, "alternatives", d);
|
|
|
|
|
|
|
|
if (alloc) {
|
|
|
|
xbps_object_release(a);
|
|
|
|
xbps_object_release(d);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
2018-07-18 07:54:26 +05:30
|
|
|
process_dict_of_arrays(const char *key UNUSED, const char *val)
|
2015-10-18 14:08:35 +05:30
|
|
|
{
|
|
|
|
char *altgrname, *args, *p, *saveptr;
|
|
|
|
|
|
|
|
assert(key);
|
|
|
|
|
|
|
|
if (val == NULL)
|
|
|
|
return;
|
|
|
|
|
|
|
|
args = strdup(val);
|
|
|
|
assert(args);
|
|
|
|
|
|
|
|
if (strchr(args, ' ') == NULL) {
|
|
|
|
altgrname = strtok(args, ":");
|
|
|
|
assert(altgrname);
|
|
|
|
process_one_alternative(altgrname, val);
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
for ((p = strtok_r(args, " ", &saveptr)); p;
|
|
|
|
(p = strtok_r(NULL, " ", &saveptr))) {
|
|
|
|
char *b;
|
|
|
|
|
|
|
|
b = strdup(p);
|
|
|
|
assert(b);
|
|
|
|
altgrname = strtok(b, ":");
|
|
|
|
assert(altgrname);
|
|
|
|
process_one_alternative(altgrname, p);
|
|
|
|
free(b);
|
|
|
|
}
|
|
|
|
out:
|
|
|
|
free(args);
|
|
|
|
}
|
|
|
|
|
2014-07-27 14:54:49 +05:30
|
|
|
static void
|
|
|
|
process_file(const char *file, const char *key)
|
|
|
|
{
|
|
|
|
void *blob;
|
|
|
|
FILE *f;
|
|
|
|
struct stat st;
|
|
|
|
size_t len;
|
|
|
|
xbps_data_t data;
|
|
|
|
|
|
|
|
if ((f = fopen(file, "r")) == NULL)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (fstat(fileno(f), &st) == -1) {
|
|
|
|
fclose(f);
|
2022-12-23 02:46:47 +05:30
|
|
|
die("lstat: %s", file);
|
2014-07-27 14:54:49 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
if (S_ISREG(st.st_mode) == 0) {
|
|
|
|
fclose(f);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
len = st.st_size;
|
|
|
|
|
|
|
|
if ((blob = malloc(len)) == NULL) {
|
|
|
|
fclose(f);
|
2022-12-23 02:46:47 +05:30
|
|
|
die("malloc");
|
2014-07-27 14:54:49 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
if (fread(blob, len, 1, f) != len) {
|
|
|
|
if (ferror(f)) {
|
|
|
|
fclose(f);
|
2022-12-23 02:46:47 +05:30
|
|
|
die("fread: %s", file);
|
2014-07-27 14:54:49 +05:30
|
|
|
}
|
|
|
|
}
|
|
|
|
fclose(f);
|
|
|
|
|
|
|
|
if ((data = xbps_data_create_data(blob, len)) == NULL)
|
2022-12-23 02:46:47 +05:30
|
|
|
die("xbps_data_create_data: %s", file);
|
2014-07-27 14:54:49 +05:30
|
|
|
|
|
|
|
free(blob);
|
|
|
|
|
|
|
|
if (!xbps_dictionary_set(pkg_propsd, key, data))
|
2022-12-23 02:46:47 +05:30
|
|
|
die("xbps_dictionary_set: %s", key);
|
2014-07-27 14:54:49 +05:30
|
|
|
|
|
|
|
xbps_object_release(data);
|
|
|
|
}
|
|
|
|
|
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;
|
2019-06-27 20:39:43 +05:30
|
|
|
const char *curfile = NULL;
|
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-09-15 13:36:49 +05:30
|
|
|
for (unsigned int i = 0; i < xbps_array_count(a); i++) {
|
2013-06-20 13:56:12 +05:30
|
|
|
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
|
2018-07-18 07:54:26 +05:30
|
|
|
ftw_cb(const char *fpath, const struct stat *sb, const struct dirent *dir UNUSED)
|
2012-09-04 14:28:19 +05:30
|
|
|
{
|
2018-07-06 11:37:55 +05:30
|
|
|
struct xentry *xe = NULL;
|
2016-03-27 07:16:42 +05:30
|
|
|
xbps_dictionary_t fileinfo = NULL;
|
2012-09-04 14:28:19 +05:30
|
|
|
const char *filep = NULL;
|
2022-12-23 02:12:32 +05:30
|
|
|
char *p, *p2, *dname;
|
2020-02-10 06:24:52 +05:30
|
|
|
char sha256[XBPS_SHA256_SIZE];
|
2012-09-04 14:28:19 +05:30
|
|
|
|
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) ||
|
2014-07-27 14:54:49 +05:30
|
|
|
(strcmp(fpath, "./INSTALL.msg") == 0) ||
|
|
|
|
(strcmp(fpath, "./REMOVE.msg") == 0) ||
|
2012-09-04 14:28:19 +05:30
|
|
|
(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;
|
2016-03-27 07:16:42 +05:30
|
|
|
fileinfo = xbps_dictionary_create();
|
2018-07-06 11:37:55 +05:30
|
|
|
xe = calloc(1, sizeof(*xe));
|
2022-12-23 02:30:47 +05:30
|
|
|
if (xe == NULL)
|
2022-12-23 02:46:47 +05:30
|
|
|
die("calloc");
|
2022-12-23 02:30:47 +05:30
|
|
|
|
2016-03-27 07:16:42 +05:30
|
|
|
/* XXX: fileinfo contains the sanatized path, whereas xe contains the
|
|
|
|
* unsanatized path!
|
|
|
|
*
|
|
|
|
* when handing the files over, do not use the dictionary directly. Instead
|
|
|
|
* use the keysym, as this value has the unsanatized path.
|
|
|
|
*/
|
|
|
|
xbps_dictionary_set_cstring(fileinfo, "file", filep);
|
|
|
|
xbps_dictionary_set(all_filesd, fpath, fileinfo);
|
2018-07-06 11:37:55 +05:30
|
|
|
xe->file = strdup(fpath);
|
|
|
|
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 */
|
2016-03-27 07:16:42 +05:30
|
|
|
xbps_dictionary_set_cstring_nocopy(fileinfo, "type", "metadata");
|
2022-12-23 02:30:47 +05:30
|
|
|
xe->type = ENTRY_TYPE_METADATA;
|
2012-09-04 14:28:19 +05:30
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
2018-07-07 15:45:00 +05:30
|
|
|
if (S_ISLNK(sb->st_mode)) {
|
2022-12-23 02:12:32 +05:30
|
|
|
char buf[PATH_MAX];
|
|
|
|
ssize_t len;
|
|
|
|
|
2012-09-05 12:30:09 +05:30
|
|
|
/*
|
|
|
|
* Symlinks.
|
|
|
|
*
|
|
|
|
* Find out target file.
|
|
|
|
*/
|
2016-03-27 07:16:42 +05:30
|
|
|
xbps_dictionary_set_cstring_nocopy(fileinfo, "type", "links");
|
2022-12-23 02:30:47 +05:30
|
|
|
xe->type = ENTRY_TYPE_LINKS;
|
2012-09-05 13:29:45 +05:30
|
|
|
|
2022-12-23 02:12:32 +05:30
|
|
|
len = readlink(fpath, buf, sizeof(buf));
|
|
|
|
if (len < 0 || len >= (int)sizeof(buf))
|
2022-12-23 02:46:47 +05:30
|
|
|
die("readlink: %s", fpath);
|
2022-12-23 02:12:32 +05:30
|
|
|
buf[len] = '\0';
|
|
|
|
|
2015-02-19 15:41:58 +05:30
|
|
|
/*
|
|
|
|
* Check if symlink is absolute or relative; on the former
|
|
|
|
* make it absolute for the target object.
|
|
|
|
*/
|
|
|
|
if (strstr(buf, "./")) {
|
|
|
|
p = realpath(fpath, NULL);
|
|
|
|
if (p == NULL) {
|
|
|
|
/*
|
|
|
|
* This symlink points to an unexistent file,
|
|
|
|
* which might be provided in another package.
|
|
|
|
* So let's use the same target.
|
|
|
|
*/
|
2019-12-28 03:35:07 +05:30
|
|
|
xe->target = xbps_sanitize_path(buf);
|
2022-12-23 02:46:47 +05:30
|
|
|
if (xe->target == NULL)
|
|
|
|
die("xbps_sanitize_path");
|
2019-12-28 03:35:07 +05:30
|
|
|
xbps_dictionary_set_cstring(fileinfo, "target", xe->target);
|
2015-02-19 15:41:58 +05:30
|
|
|
} else {
|
2019-12-28 03:39:24 +05:30
|
|
|
char *p3;
|
2015-02-19 15:41:58 +05:30
|
|
|
/*
|
|
|
|
* Sanitize destdir just in case.
|
|
|
|
*/
|
|
|
|
if ((p2 = realpath(destdir, NULL)) == NULL)
|
|
|
|
die("failed to sanitize destdir %s: %s", destdir, strerror(errno));
|
|
|
|
|
2019-12-28 03:35:07 +05:30
|
|
|
|
2019-12-28 03:39:24 +05:30
|
|
|
p3 = strdup(p+strlen(p2));
|
2022-12-23 02:46:47 +05:30
|
|
|
if (p3 == NULL)
|
|
|
|
die("strdup");
|
2019-12-28 03:39:24 +05:30
|
|
|
xe->target = xbps_sanitize_path(p3);
|
2022-12-23 02:46:47 +05:30
|
|
|
if (xe->target == NULL)
|
|
|
|
die("xbps_sanitize_path");
|
2019-12-28 03:39:24 +05:30
|
|
|
free(p3);
|
2019-12-28 03:35:07 +05:30
|
|
|
xbps_dictionary_set_cstring(fileinfo, "target", xe->target);
|
2015-02-19 15:41:58 +05:30
|
|
|
free(p);
|
2019-12-28 03:35:07 +05:30
|
|
|
free(p2);
|
2015-02-19 15:41:58 +05:30
|
|
|
}
|
|
|
|
} else if (buf[0] != '/') {
|
|
|
|
/* relative path */
|
|
|
|
p = strdup(filep);
|
2022-12-23 02:46:47 +05:30
|
|
|
if (p == NULL)
|
|
|
|
die("strdup");
|
2015-02-19 15:41:58 +05:30
|
|
|
dname = dirname(p);
|
2022-12-23 02:46:47 +05:30
|
|
|
if (dname == NULL)
|
|
|
|
die("dirname: %s", p);
|
2016-03-27 07:16:42 +05:30
|
|
|
p2 = xbps_xasprintf("%s/%s", dname, buf);
|
2022-12-23 02:46:47 +05:30
|
|
|
if (p2 == NULL)
|
|
|
|
die("xbps_xasprintf");
|
2019-12-28 03:35:07 +05:30
|
|
|
xe->target = xbps_sanitize_path(p2);
|
2022-12-23 02:46:47 +05:30
|
|
|
if (xe->target == NULL)
|
|
|
|
die("xbps_sanitize_path");
|
2019-12-28 03:35:07 +05:30
|
|
|
xbps_dictionary_set_cstring(fileinfo, "target", xe->target);
|
2016-03-27 07:16:42 +05:30
|
|
|
free(p2);
|
2015-02-19 15:41:58 +05:30
|
|
|
free(p);
|
|
|
|
} else {
|
2019-12-28 03:35:07 +05:30
|
|
|
xe->target = xbps_sanitize_path(buf);
|
2022-12-23 02:46:47 +05:30
|
|
|
if (xe->target == NULL)
|
|
|
|
die("xbps_sanitize_path");
|
2019-12-28 03:35:07 +05:30
|
|
|
xbps_dictionary_set_cstring(fileinfo, "target", xe->target);
|
2015-02-19 15:41:58 +05:30
|
|
|
}
|
2016-03-27 07:16:42 +05:30
|
|
|
assert(xbps_dictionary_get(fileinfo, "target"));
|
2018-07-07 15:45:00 +05:30
|
|
|
} else if (S_ISREG(sb->st_mode)) {
|
2018-07-06 11:37:55 +05:30
|
|
|
struct xentry *xep;
|
|
|
|
bool hlink = false;
|
2016-03-27 08:05:59 +05:30
|
|
|
xbps_object_iterator_t iter;
|
|
|
|
xbps_object_t obj;
|
|
|
|
xbps_dictionary_t linkinfo;
|
|
|
|
uint64_t inode = 0;
|
2014-11-12 17:07:35 +05:30
|
|
|
/*
|
|
|
|
* Regular files. First find out if it's a hardlink:
|
|
|
|
* - st_nlink > 1
|
|
|
|
* and then search for a stored file matching its inode.
|
|
|
|
*/
|
2018-07-06 11:37:55 +05:30
|
|
|
TAILQ_FOREACH(xep, &xentry_list, entries) {
|
|
|
|
if (sb->st_nlink > 1 && xep->inode == sb->st_ino) {
|
|
|
|
hlink = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-03-27 08:05:59 +05:30
|
|
|
iter = xbps_dictionary_iterator(all_filesd);
|
2022-12-23 02:46:47 +05:30
|
|
|
if (iter == NULL)
|
|
|
|
die("xbps_dictionary_iterator");
|
2016-03-27 08:05:59 +05:30
|
|
|
while ((obj = xbps_object_iterator_next(iter))) {
|
|
|
|
if (sb->st_nlink <= 1)
|
|
|
|
continue;
|
|
|
|
linkinfo = xbps_dictionary_get_keysym(all_filesd, obj);
|
|
|
|
xbps_dictionary_get_uint64(linkinfo, "inode", &inode);
|
|
|
|
if (inode == sb->st_ino) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2018-07-06 11:37:55 +05:30
|
|
|
if (!hlink != (inode != sb->st_ino))
|
|
|
|
die("Inconsistent results from xbps_dictionary_t and linked list!\n");
|
|
|
|
|
2016-03-27 08:05:59 +05:30
|
|
|
if (inode != sb->st_ino)
|
2014-11-12 17:07:35 +05:30
|
|
|
instsize += sb->st_size;
|
2016-03-27 08:05:59 +05:30
|
|
|
xbps_object_iterator_release(iter);
|
2014-11-12 17:07:35 +05:30
|
|
|
|
2012-09-04 14:28:19 +05:30
|
|
|
/*
|
2012-09-05 12:30:09 +05:30
|
|
|
* Find out if it's a configuration file or not
|
|
|
|
* and calculate sha256 hash.
|
2012-09-04 14:28:19 +05:30
|
|
|
*/
|
2016-03-27 07:16:42 +05:30
|
|
|
if (entry_is_conf_file(filep)) {
|
|
|
|
xbps_dictionary_set_cstring_nocopy(fileinfo, "type", "conf_files");
|
2022-12-23 02:30:47 +05:30
|
|
|
xe->type = ENTRY_TYPE_CONF_FILES;
|
2016-03-27 07:16:42 +05:30
|
|
|
} else {
|
|
|
|
xbps_dictionary_set_cstring_nocopy(fileinfo, "type", "files");
|
2022-12-23 02:30:47 +05:30
|
|
|
xe->type = ENTRY_TYPE_FILES;
|
2016-03-27 07:16:42 +05:30
|
|
|
}
|
2012-09-04 14:28:19 +05:30
|
|
|
|
2020-02-10 06:24:52 +05:30
|
|
|
if (!xbps_file_sha256(xe->sha256, sizeof sha256, fpath))
|
2022-12-23 02:46:47 +05:30
|
|
|
die("failed to process hash for: %s", fpath);
|
2020-02-10 06:24:52 +05:30
|
|
|
xbps_dictionary_set_cstring(fileinfo, "sha256", xe->sha256);
|
2012-09-05 12:30:09 +05:30
|
|
|
|
2016-03-27 07:16:42 +05:30
|
|
|
xbps_dictionary_set_uint64(fileinfo, "inode", sb->st_ino);
|
2018-07-06 11:37:55 +05:30
|
|
|
xe->inode = sb->st_ino;
|
2019-06-16 19:56:38 +05:30
|
|
|
xe->size = (uint64_t)sb->st_size;
|
2018-07-06 11:37:55 +05:30
|
|
|
|
2018-07-07 15:45:00 +05:30
|
|
|
} else if (S_ISDIR(sb->st_mode)) {
|
2012-09-04 14:28:19 +05:30
|
|
|
/* directory */
|
2016-03-27 07:16:42 +05:30
|
|
|
xbps_dictionary_set_cstring_nocopy(fileinfo, "type", "dirs");
|
2022-12-23 02:30:47 +05:30
|
|
|
xe->type = ENTRY_TYPE_DIRS;
|
2019-01-23 18:03:40 +05:30
|
|
|
} else if (S_ISFIFO(sb->st_mode)) {
|
|
|
|
errno = 0;
|
|
|
|
die("cannot package fifo %s", fpath);
|
|
|
|
} else if (S_ISSOCK(sb->st_mode)) {
|
|
|
|
errno = 0;
|
|
|
|
die("cannot package socket %s", fpath);
|
|
|
|
} else {
|
|
|
|
errno = 0;
|
|
|
|
die("cannot package %s", fpath);
|
2012-09-04 14:28:19 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
out:
|
2016-03-27 07:16:42 +05:30
|
|
|
xbps_object_release(fileinfo);
|
2018-07-06 11:37:55 +05:30
|
|
|
TAILQ_INSERT_TAIL(&xentry_list, xe, entries);
|
2012-09-04 14:28:19 +05:30
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2018-07-07 15:45:00 +05:30
|
|
|
static int
|
|
|
|
walk_dir(const char *path,
|
2018-07-07 15:53:01 +05:30
|
|
|
int (*fn) (const char *, const struct stat *sb, const struct dirent *dir))
|
|
|
|
{
|
2018-07-07 15:45:00 +05:30
|
|
|
int rv, i;
|
|
|
|
struct dirent **list;
|
|
|
|
char tmp_path[PATH_MAX] = { 0 };
|
|
|
|
struct stat sb;
|
|
|
|
|
|
|
|
rv = scandir(path, &list, NULL, alphasort);
|
2018-07-07 15:53:01 +05:30
|
|
|
for (i = rv - 1; i >= 0; i--) {
|
|
|
|
if (strcmp(list[i]->d_name, ".") == 0 || strcmp(list[i]->d_name, "..") == 0)
|
2018-07-07 15:45:00 +05:30
|
|
|
continue;
|
|
|
|
if (strlen(path) + strlen(list[i]->d_name) + 1 >= PATH_MAX - 1) {
|
|
|
|
errno = ENAMETOOLONG;
|
2018-07-07 15:53:01 +05:30
|
|
|
rv = -1;
|
2018-07-07 15:45:00 +05:30
|
|
|
break;
|
|
|
|
}
|
|
|
|
strncpy(tmp_path, path, PATH_MAX - 1);
|
|
|
|
strncat(tmp_path, "/", PATH_MAX - 1 - strlen(tmp_path));
|
|
|
|
strncat(tmp_path, list[i]->d_name, PATH_MAX - 1 - strlen(tmp_path));
|
|
|
|
if (lstat(tmp_path, &sb) < 0) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (S_ISDIR(sb.st_mode)) {
|
2018-07-07 15:53:01 +05:30
|
|
|
if (walk_dir(tmp_path, fn) < 0) {
|
2018-07-07 15:45:00 +05:30
|
|
|
rv = -1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
rv = fn(tmp_path, &sb, list[i]);
|
|
|
|
if (rv != 0) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
free(list);
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2012-09-04 14:28:19 +05:30
|
|
|
static void
|
2022-12-23 02:30:47 +05:30
|
|
|
process_xentry(enum entry_type type, const char *mutable_files)
|
2012-09-04 14:28:19 +05:30
|
|
|
{
|
2013-06-20 13:56:12 +05:30
|
|
|
xbps_array_t a;
|
2018-07-06 11:37:59 +05:30
|
|
|
xbps_dictionary_t d;
|
|
|
|
struct xentry *xe;
|
|
|
|
char *p, *saveptr, *args, *tok;
|
2012-09-08 09:46:51 +05:30
|
|
|
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();
|
2022-12-23 02:46:47 +05:30
|
|
|
if (a == NULL)
|
|
|
|
die("xbps_array_create");
|
2012-09-04 14:28:19 +05:30
|
|
|
|
2018-07-06 11:37:59 +05:30
|
|
|
TAILQ_FOREACH_REVERSE(xe, &xentry_list, xentry_head, entries) {
|
2022-12-23 02:30:47 +05:30
|
|
|
if (xe->type != type)
|
2012-09-04 14:28:19 +05:30
|
|
|
continue;
|
|
|
|
|
|
|
|
found = true;
|
2018-07-06 11:37:59 +05:30
|
|
|
d = xbps_dictionary_create();
|
2022-12-23 02:46:47 +05:30
|
|
|
if (d == NULL)
|
|
|
|
die("xbps_dictionary_create");
|
2018-07-06 11:37:59 +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))
|
2018-07-06 11:37:59 +05:30
|
|
|
xbps_dictionary_set_bool(d, "mutable", true);
|
2012-09-08 09:46:51 +05:30
|
|
|
else {
|
|
|
|
args = strdup(mutable_files);
|
2022-12-23 02:46:47 +05:30
|
|
|
if (args == NULL)
|
|
|
|
die("strdup");
|
2012-09-08 09:46:51 +05:30
|
|
|
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) {
|
2018-07-06 11:37:59 +05:30
|
|
|
xbps_dictionary_set_bool(d, "mutable",
|
2012-09-08 09:46:51 +05:30
|
|
|
true);
|
|
|
|
mutable_found = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2018-07-06 11:37:59 +05:30
|
|
|
xbps_dictionary_set_cstring(d, "file", p);
|
|
|
|
if (xe->target)
|
|
|
|
xbps_dictionary_set_cstring(d, "target", xe->target);
|
2020-02-10 06:24:52 +05:30
|
|
|
if (*xe->sha256)
|
|
|
|
xbps_dictionary_set_cstring(d, "sha256", xe->sha256);
|
2019-06-16 19:56:38 +05:30
|
|
|
if (xe->size)
|
|
|
|
xbps_dictionary_set_uint64(d, "size", xe->size);
|
2018-07-06 11:37:59 +05:30
|
|
|
|
|
|
|
xbps_array_add(a, d);
|
|
|
|
xbps_object_release(d);
|
2012-09-04 14:28:19 +05:30
|
|
|
}
|
|
|
|
if (found)
|
2022-12-23 02:30:47 +05:30
|
|
|
xbps_dictionary_set(pkg_filesd, entry_type_str(type), 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
|
|
|
{
|
2018-07-07 15:45:00 +05:30
|
|
|
if (walk_dir(".", ftw_cb) < 0)
|
2022-12-23 02:46:47 +05:30
|
|
|
die("failed to process destdir files (nftw)");
|
2012-09-04 14:28:19 +05:30
|
|
|
|
|
|
|
/* Process regular files */
|
2022-12-23 02:30:47 +05:30
|
|
|
process_xentry(ENTRY_TYPE_FILES, mutable_files);
|
2012-09-04 14:28:19 +05:30
|
|
|
|
|
|
|
/* Process configuration files */
|
2022-12-23 02:30:47 +05:30
|
|
|
process_xentry(ENTRY_TYPE_CONF_FILES, NULL);
|
2012-09-04 14:28:19 +05:30
|
|
|
|
|
|
|
/* Process symlinks */
|
2022-12-23 02:30:47 +05:30
|
|
|
process_xentry(ENTRY_TYPE_LINKS, NULL);
|
2012-09-04 14:28:19 +05:30
|
|
|
|
|
|
|
/* Process directories */
|
2022-12-23 02:30:47 +05:30
|
|
|
process_xentry(ENTRY_TYPE_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
|
|
|
{
|
2019-10-26 02:16:14 +05:30
|
|
|
const char *name, *target;
|
2016-06-17 20:40:10 +05:30
|
|
|
int fd;
|
|
|
|
char buf[65536];
|
|
|
|
ssize_t len;
|
2012-12-12 08:18:27 +05:30
|
|
|
|
2019-10-26 02:16:14 +05:30
|
|
|
if ((target = archive_entry_pathname(entry)) == NULL)
|
2012-12-12 08:18:27 +05:30
|
|
|
return;
|
|
|
|
|
2021-06-25 21:34:57 +05:30
|
|
|
if (archive_write_header(ar, entry) != ARCHIVE_OK)
|
2022-12-23 02:46:47 +05:30
|
|
|
die_archive(ar, "archive_write_header: %s", target);
|
2012-12-12 08:18:27 +05:30
|
|
|
|
|
|
|
/* Only regular files can have data. */
|
|
|
|
if (archive_entry_filetype(entry) != AE_IFREG ||
|
|
|
|
archive_entry_size(entry) == 0) {
|
|
|
|
archive_entry_free(entry);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-09-27 16:41:43 +05:30
|
|
|
name = archive_entry_sourcepath(entry);
|
2012-12-12 08:18:27 +05:30
|
|
|
|
2016-06-17 20:40:10 +05:30
|
|
|
if ((fd = open(name, O_RDONLY)) < 0)
|
2022-12-23 02:46:47 +05:30
|
|
|
die("cannot open: %s", name);
|
2016-06-17 20:40:10 +05:30
|
|
|
while ((len = read(fd, buf, sizeof(buf))) > 0)
|
2019-10-26 02:16:14 +05:30
|
|
|
if (archive_write_data(ar, buf, len) != len)
|
2022-12-23 02:46:47 +05:30
|
|
|
die_archive(ar, "archive_write_data: %s", target);
|
2016-06-17 20:40:10 +05:30
|
|
|
(void)close(fd);
|
|
|
|
|
2022-12-23 02:46:47 +05:30
|
|
|
if (len < 0)
|
|
|
|
die("cannot open: %s", name);
|
2016-06-17 20:40:10 +05:30
|
|
|
|
2012-12-12 08:18:27 +05:30
|
|
|
archive_entry_free(entry);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
process_entry_file(struct archive *ar,
|
|
|
|
struct archive_entry_linkresolver *resolver,
|
2018-07-06 11:37:58 +05:30
|
|
|
struct xentry *xe, const char *filematch)
|
2012-12-12 08:18:27 +05:30
|
|
|
{
|
|
|
|
struct archive_entry *entry, *sparse_entry;
|
|
|
|
struct stat st;
|
2022-12-23 02:12:32 +05:30
|
|
|
char path[PATH_MAX];
|
2012-09-04 14:28:19 +05:30
|
|
|
|
|
|
|
assert(ar);
|
2018-07-06 11:37:58 +05:30
|
|
|
assert(xe);
|
|
|
|
|
|
|
|
if (filematch && strcmp(xe->file, filematch))
|
|
|
|
return;
|
2012-09-04 14:28:19 +05:30
|
|
|
|
2022-12-23 02:12:32 +05:30
|
|
|
if (xbps_path_join(path, sizeof(path), destdir, xe->file, (char *)NULL) == -1)
|
2022-12-23 02:46:47 +05:30
|
|
|
die("xbps_path_join");
|
2022-12-23 02:12:32 +05:30
|
|
|
if (lstat(path, &st) == -1)
|
2022-12-23 02:46:47 +05:30
|
|
|
die("lstat: %s", xe->file);
|
2012-09-04 14:28:19 +05:30
|
|
|
|
|
|
|
entry = archive_entry_new();
|
2019-10-26 02:16:14 +05:30
|
|
|
if (entry == NULL)
|
2022-12-23 02:46:47 +05:30
|
|
|
die("archive_entry_new");
|
2019-10-26 02:16:14 +05:30
|
|
|
|
2018-07-06 11:37:58 +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);
|
2022-12-23 02:12:32 +05:30
|
|
|
archive_entry_copy_sourcepath(entry, path);
|
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)) {
|
2022-12-23 02:12:32 +05:30
|
|
|
char buf[PATH_MAX];
|
|
|
|
ssize_t len;
|
|
|
|
|
|
|
|
len = readlink(path, buf, sizeof(buf));
|
|
|
|
if (len < 0 || len >= (int)sizeof(buf))
|
2022-12-23 02:46:47 +05:30
|
|
|
die("readlink: %s", xe->file);
|
2014-10-05 12:25:32 +05:30
|
|
|
buf[len] = '\0';
|
2022-12-23 02:12:32 +05:30
|
|
|
|
2012-12-12 08:18:27 +05:30
|
|
|
archive_entry_set_symlink(entry, buf);
|
2012-09-23 18:24:04 +05:30
|
|
|
}
|
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
|
|
|
{
|
2018-07-06 11:37:58 +05:30
|
|
|
struct xentry *xe;
|
2012-09-04 14:28:19 +05:30
|
|
|
char *xml;
|
|
|
|
|
|
|
|
/* Add INSTALL/REMOVE metadata scripts first */
|
2018-07-06 11:37:58 +05:30
|
|
|
TAILQ_FOREACH(xe, &xentry_list, entries) {
|
|
|
|
process_entry_file(ar, resolver, xe, "./INSTALL");
|
|
|
|
process_entry_file(ar, resolver, xe, "./REMOVE");
|
|
|
|
}
|
2012-09-05 12:30:09 +05:30
|
|
|
/*
|
|
|
|
* Add the installed-size object.
|
|
|
|
*/
|
2014-10-05 16:03:45 +05:30
|
|
|
if (!xbps_dictionary_set_uint64(pkg_propsd, "installed_size", instsize))
|
2022-12-23 02:46:47 +05:30
|
|
|
die("xbps_dictionary_set_uint64");
|
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);
|
2022-12-23 02:46:47 +05:30
|
|
|
if (xml == NULL)
|
|
|
|
die("xbps_dictionary_externalize");
|
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);
|
2022-12-23 02:46:47 +05:30
|
|
|
if (xml == NULL)
|
|
|
|
die("xbps_dictionary_externalize");
|
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 */
|
2018-07-06 11:37:58 +05:30
|
|
|
while ((xe = TAILQ_FIRST(&xentry_list)) != NULL) {
|
|
|
|
TAILQ_REMOVE(&xentry_list, xe, entries);
|
2022-12-23 02:30:47 +05:30
|
|
|
if (xe->type == ENTRY_TYPE_METADATA || xe->type == ENTRY_TYPE_DIRS)
|
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) {
|
2018-07-06 11:37:58 +05:30
|
|
|
printf("%s: adding `%s' ...\n", pkgver, xe->file);
|
2012-09-23 05:03:51 +05:30
|
|
|
fflush(stdout);
|
|
|
|
}
|
2018-07-06 11:37:58 +05:30
|
|
|
process_entry_file(ar, resolver, xe, NULL);
|
2012-09-04 14:28:19 +05:30
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
main(int argc, char **argv)
|
|
|
|
{
|
2016-04-22 18:01:17 +05:30
|
|
|
const char *shortopts = "A:B:C:c:D:F:G:H:hl:M:m:n:P:pqr:R:S:s:t:V";
|
2012-11-02 19:33:33 +05:30
|
|
|
const struct option longopts[] = {
|
2023-02-15 22:01:44 +05:30
|
|
|
{ "alternatives", required_argument, NULL, '4' },
|
2012-09-04 14:28:19 +05:30
|
|
|
{ "architecture", required_argument, NULL, 'A' },
|
2023-02-15 22:01:44 +05:30
|
|
|
{ "build-options", required_argument, NULL, '2' },
|
2012-09-11 11:48:31 +05:30
|
|
|
{ "built-with", required_argument, NULL, 'B' },
|
2023-02-15 22:01:44 +05:30
|
|
|
{ "changelog", required_argument, NULL, 'c'},
|
|
|
|
{ "compression", required_argument, NULL, '3' },
|
|
|
|
{ "config-files", required_argument, NULL, 'F' },
|
2012-09-04 14:28:19 +05:30
|
|
|
{ "conflicts", required_argument, NULL, 'C' },
|
|
|
|
{ "dependencies", required_argument, NULL, 'D' },
|
2023-02-15 22:01:44 +05:30
|
|
|
{ "desc", required_argument, NULL, 's' },
|
2012-09-24 15:59:27 +05:30
|
|
|
{ "help", no_argument, NULL, 'h' },
|
2023-02-15 22:01:44 +05:30
|
|
|
{ "homepage", required_argument, NULL, 'H' },
|
2012-09-04 14:28:19 +05:30
|
|
|
{ "license", required_argument, NULL, 'l' },
|
2023-02-15 22:01:44 +05:30
|
|
|
{ "long-desc", required_argument, NULL, 'S' },
|
2012-09-04 14:28:19 +05:30
|
|
|
{ "maintainer", required_argument, NULL, 'm' },
|
2023-02-15 22:01:44 +05:30
|
|
|
{ "mutable-files", required_argument, NULL, 'M' },
|
2012-09-04 14:28:19 +05:30
|
|
|
{ "pkgver", required_argument, NULL, 'n' },
|
|
|
|
{ "preserve", no_argument, NULL, 'p' },
|
2023-02-15 22:01:44 +05:30
|
|
|
{ "provides", required_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' },
|
2014-09-23 00:50:38 +05:30
|
|
|
{ "reverts", required_argument, NULL, 'r' },
|
2012-12-24 15:25:17 +05:30
|
|
|
{ "shlib-provides", required_argument, NULL, '0' },
|
|
|
|
{ "shlib-requires", required_argument, NULL, '1' },
|
2023-02-15 22:01:44 +05:30
|
|
|
{ "source-revisions", required_argument, NULL, 'G' },
|
|
|
|
{ "sourcepkg", required_argument, NULL, '5'},
|
|
|
|
{ "tags", required_argument, NULL, 't' },
|
|
|
|
{ "version", no_argument, NULL, 'V' },
|
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;
|
2014-09-23 00:50:38 +05:30
|
|
|
const char *provides, *pkgver, *replaces, *reverts, *desc, *ldesc;
|
2016-04-22 18:01:17 +05:30
|
|
|
const char *arch, *config_files, *mutable_files, *version, *changelog;
|
2015-10-18 14:08:35 +05:30
|
|
|
const char *buildopts, *shlib_provides, *shlib_requires, *alternatives;
|
2023-02-15 22:01:44 +05:30
|
|
|
const char *compression, *tags = NULL, *srcrevs = NULL, *sourcepkg = NULL;
|
2020-02-09 00:01:29 +05:30
|
|
|
char pkgname[XBPS_NAME_SIZE], *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
|
|
|
|
2014-04-11 17:46:58 +05:30
|
|
|
arch = conflicts = deps = homepage = license = maint = compression = NULL;
|
2014-09-23 00:50:38 +05:30
|
|
|
provides = pkgver = replaces = reverts = desc = ldesc = bwith = NULL;
|
|
|
|
buildopts = config_files = mutable_files = shlib_provides = NULL;
|
2016-04-22 18:01:17 +05:30
|
|
|
alternatives = shlib_requires = changelog = 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;
|
2016-04-22 18:01:17 +05:30
|
|
|
case 'c':
|
|
|
|
changelog = optarg;
|
|
|
|
break;
|
2012-09-04 14:28:19 +05:30
|
|
|
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':
|
2020-04-21 00:55:14 +05:30
|
|
|
usage(false);
|
2012-09-24 15:59:27 +05:30
|
|
|
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;
|
2014-09-23 00:50:38 +05:30
|
|
|
case 'r':
|
|
|
|
reverts = optarg;
|
|
|
|
break;
|
2012-09-04 14:28:19 +05:30
|
|
|
case 'S':
|
|
|
|
ldesc = optarg;
|
|
|
|
break;
|
|
|
|
case 's':
|
|
|
|
desc = optarg;
|
|
|
|
break;
|
2014-05-29 15:06:39 +05:30
|
|
|
case 't':
|
|
|
|
tags = optarg;
|
|
|
|
break;
|
2012-09-04 14:28:19 +05:30
|
|
|
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;
|
2014-04-11 17:46:58 +05:30
|
|
|
case '3':
|
|
|
|
compression = optarg;
|
|
|
|
break;
|
2015-10-18 14:08:35 +05:30
|
|
|
case '4':
|
|
|
|
alternatives = optarg;
|
|
|
|
break;
|
2023-02-15 22:01:44 +05:30
|
|
|
case '5':
|
|
|
|
sourcepkg = optarg;
|
|
|
|
break;
|
2012-09-04 14:28:19 +05:30
|
|
|
case '?':
|
|
|
|
default:
|
2020-04-21 00:55:14 +05:30
|
|
|
usage(true);
|
|
|
|
/* NOTREACHED */
|
2012-09-04 14:28:19 +05:30
|
|
|
}
|
|
|
|
}
|
2020-04-21 00:55:14 +05:30
|
|
|
if (argc == optind) {
|
|
|
|
usage(true);
|
|
|
|
/* NOTREACHED */
|
|
|
|
}
|
2012-09-30 10:42:31 +05:30
|
|
|
|
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)
|
2022-12-23 02:46:47 +05:30
|
|
|
diex("pkgver not set!");
|
2012-09-04 14:28:19 +05:30
|
|
|
else if (desc == NULL)
|
2022-12-23 02:46:47 +05:30
|
|
|
diex("short description not set!");
|
2012-09-04 14:28:19 +05:30
|
|
|
else if (arch == NULL)
|
2022-12-23 02:46:47 +05:30
|
|
|
diex("architecture not set!");
|
2012-09-04 14:28:19 +05:30
|
|
|
/*
|
|
|
|
* Sanity check for required options.
|
|
|
|
*/
|
2020-02-09 00:01:29 +05:30
|
|
|
if (!xbps_pkg_name(pkgname, sizeof(pkgname), pkgver))
|
2022-12-23 02:46:47 +05:30
|
|
|
diex("invalid pkgver! got `%s' expected `foo-1.0_1'", pkgver);
|
2012-09-04 14:28:19 +05:30
|
|
|
version = xbps_pkg_version(pkgver);
|
|
|
|
if (version == NULL)
|
2022-12-23 02:46:47 +05:30
|
|
|
diex("invalid pkgver! got `%s' expected `foo-1.0_1'", pkgver);
|
2012-09-04 14:28:19 +05:30
|
|
|
|
|
|
|
if (stat(destdir, &st) == -1)
|
2022-12-23 02:46:47 +05:30
|
|
|
die("stat: %s", destdir);
|
2012-09-04 14:28:19 +05:30
|
|
|
if (!S_ISDIR(st.st_mode))
|
2022-12-23 02:46:47 +05:30
|
|
|
diex("destdir `%s' is not a directory!", destdir);
|
2012-09-04 14:28:19 +05:30
|
|
|
/*
|
|
|
|
* Process XBPS_PKGPROPS metadata file.
|
|
|
|
*/
|
2013-06-20 13:56:12 +05:30
|
|
|
pkg_propsd = xbps_dictionary_create();
|
2022-12-23 02:46:47 +05:30
|
|
|
if (pkg_propsd == NULL)
|
|
|
|
die("xbps_dictionary_create");
|
2012-09-04 14:28:19 +05:30
|
|
|
|
|
|
|
/* 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-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);
|
2023-02-15 22:01:44 +05:30
|
|
|
if (sourcepkg)
|
|
|
|
xbps_dictionary_set_cstring_nocopy(pkg_propsd,
|
|
|
|
"sourcepkg", sourcepkg);
|
2014-05-29 15:06:39 +05:30
|
|
|
if (tags)
|
|
|
|
xbps_dictionary_set_cstring_nocopy(pkg_propsd,
|
|
|
|
"tags", tags);
|
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);
|
2016-04-22 18:01:17 +05:30
|
|
|
if (changelog)
|
|
|
|
xbps_dictionary_set_cstring_nocopy(pkg_propsd,
|
|
|
|
"changelog", changelog);
|
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);
|
2014-09-23 00:50:38 +05:30
|
|
|
process_array("reverts", reverts);
|
2012-12-24 15:25:17 +05:30
|
|
|
process_array("shlib-provides", shlib_provides);
|
|
|
|
process_array("shlib-requires", shlib_requires);
|
2015-10-18 14:08:35 +05:30
|
|
|
process_dict_of_arrays("alternatives", alternatives);
|
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));
|
2022-12-23 02:46:47 +05:30
|
|
|
if (p == NULL)
|
|
|
|
die("getcwd");
|
2012-09-05 12:30:09 +05:30
|
|
|
|
2012-09-04 14:28:19 +05:30
|
|
|
if (chdir(destdir) == -1)
|
2022-12-23 02:46:47 +05:30
|
|
|
die("chdir: %s", destdir);
|
2014-07-27 14:54:49 +05:30
|
|
|
|
|
|
|
/* Optional INSTALL/REMOVE messages */
|
|
|
|
process_file("INSTALL.msg", "install-msg");
|
|
|
|
process_file("REMOVE.msg", "remove-msg");
|
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();
|
2022-12-23 02:46:47 +05:30
|
|
|
if (pkg_filesd == NULL)
|
|
|
|
die("xbps_dictionary_create");
|
2016-03-27 07:16:42 +05:30
|
|
|
all_filesd = xbps_dictionary_create();
|
2022-12-23 02:46:47 +05:30
|
|
|
if (all_filesd == NULL)
|
|
|
|
die("xbps_dictionary_create");
|
|
|
|
|
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)
|
2022-12-23 02:46:47 +05:30
|
|
|
die("chdir: %s", p);
|
2012-09-05 12:30:09 +05:30
|
|
|
|
|
|
|
/*
|
|
|
|
* Create a temp file to store archive data.
|
|
|
|
*/
|
2015-07-26 12:32:04 +05:30
|
|
|
tname = xbps_xasprintf(".xbps-pkg-XXXXXXXXX");
|
|
|
|
myumask = umask(S_IXUSR|S_IRWXG|S_IRWXO);
|
2012-09-05 12:30:09 +05:30
|
|
|
pkg_fd = mkstemp(tname);
|
2022-12-23 02:46:47 +05:30
|
|
|
if (pkg_fd == -1)
|
|
|
|
die("mkstemp");
|
2015-07-26 12:32:04 +05:30
|
|
|
umask(myumask);
|
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();
|
2019-10-26 02:16:14 +05:30
|
|
|
if (ar == NULL)
|
2022-12-23 02:46:47 +05:30
|
|
|
die("archive_write_new");
|
2014-04-11 17:46:58 +05:30
|
|
|
/*
|
2020-02-22 03:26:22 +05:30
|
|
|
* Set compression format, zstd by default.
|
2014-04-11 17:46:58 +05:30
|
|
|
*/
|
2020-02-22 03:26:22 +05:30
|
|
|
if (compression == NULL || strcmp(compression, "zstd") == 0) {
|
|
|
|
archive_write_add_filter_zstd(ar);
|
|
|
|
archive_write_set_options(ar, "compression-level=9");
|
|
|
|
} else if (strcmp(compression, "xz") == 0) {
|
2014-04-11 17:46:58 +05:30
|
|
|
archive_write_add_filter_xz(ar);
|
2020-02-22 03:26:22 +05:30
|
|
|
archive_write_set_options(ar, "compression-level=9");
|
2014-09-19 19:55:50 +05:30
|
|
|
} else if (strcmp(compression, "gzip") == 0) {
|
2014-04-11 17:46:58 +05:30
|
|
|
archive_write_add_filter_gzip(ar);
|
2014-09-19 19:55:50 +05:30
|
|
|
archive_write_set_options(ar, "compression-level=9");
|
|
|
|
} else if (strcmp(compression, "bzip2") == 0) {
|
2014-04-11 17:46:58 +05:30
|
|
|
archive_write_add_filter_bzip2(ar);
|
2014-09-19 19:55:50 +05:30
|
|
|
archive_write_set_options(ar, "compression-level=9");
|
2019-06-17 10:42:18 +05:30
|
|
|
} else if (strcmp(compression, "lz4") == 0) {
|
|
|
|
archive_write_add_filter_lz4(ar);
|
|
|
|
archive_write_set_options(ar, "compression-level=9");
|
2015-09-03 16:04:29 +05:30
|
|
|
} else if (strcmp(compression, "none") == 0) {
|
|
|
|
/* empty */
|
2014-09-19 19:55:50 +05:30
|
|
|
} else {
|
2022-12-23 02:46:47 +05:30
|
|
|
diex("unknown compression format %s", compression);
|
2014-09-19 19:55:50 +05:30
|
|
|
}
|
2014-04-11 17:46:58 +05:30
|
|
|
|
2012-12-12 08:18:27 +05:30
|
|
|
archive_write_set_format_pax_restricted(ar);
|
|
|
|
if ((resolver = archive_entry_linkresolver_new()) == NULL)
|
2022-12-23 02:46:47 +05:30
|
|
|
die("archive_entry_linkresolver_new");
|
2012-12-12 08:18:27 +05:30
|
|
|
archive_entry_linkresolver_set_strategy(resolver,
|
|
|
|
archive_format(ar));
|
|
|
|
|
2019-10-26 02:16:14 +05:30
|
|
|
if (archive_write_open_fd(ar, pkg_fd) != ARCHIVE_OK)
|
2022-12-23 02:46:47 +05:30
|
|
|
die("archive_write_open_fd: %s", 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);
|
2019-10-26 02:16:14 +05:30
|
|
|
|
|
|
|
if (archive_write_close(ar) != ARCHIVE_OK)
|
2022-12-23 02:46:47 +05:30
|
|
|
die_archive(ar, "archive_write_close: %s", tname);
|
2019-10-26 02:16:14 +05:30
|
|
|
if (archive_write_free(ar) != ARCHIVE_OK)
|
2022-12-23 02:46:47 +05:30
|
|
|
die_archive(ar, "archive_write_free");
|
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);
|
|
|
|
|
2016-01-26 18:51:40 +05:30
|
|
|
#ifdef HAVE_FDATASYNC
|
2015-02-27 15:34:25 +05:30
|
|
|
(void)fdatasync(pkg_fd);
|
2016-01-26 18:51:40 +05:30
|
|
|
#else
|
|
|
|
(void)fsync(pkg_fd);
|
|
|
|
#endif
|
2012-09-05 12:30:09 +05:30
|
|
|
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)
|
2022-12-23 02:46:47 +05:30
|
|
|
die("fchmod: %s", tname);
|
2012-09-05 12:30:09 +05:30
|
|
|
|
2012-12-14 16:28:30 +05:30
|
|
|
close(pkg_fd);
|
|
|
|
|
2012-09-05 12:30:09 +05:30
|
|
|
if (rename(tname, binpkg) == -1)
|
2022-12-23 02:46:47 +05:30
|
|
|
die("rename: %s to %s", tname, binpkg);
|
2012-09-05 12:30:09 +05:30
|
|
|
|
|
|
|
/* 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);
|
|
|
|
}
|