2014-04-06 15:51:24 +05:30
|
|
|
/*
|
2019-06-12 23:23:41 +05:30
|
|
|
* Copyright (c) 2014-2019 Juan Romero Pardines
|
2014-04-06 15:51:24 +05:30
|
|
|
* Copyright (c) 2012-2014 Dave Elusive <davehome@redthumb.info.tm>
|
2019-06-14 01:09:45 +05:30
|
|
|
* Copyright (c) 2019 Duncan Overbruck <mail@duncano.de>
|
2014-04-06 15:51:24 +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 <getopt.h>
|
|
|
|
#include <stdbool.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stddef.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <errno.h>
|
|
|
|
#include <ctype.h>
|
|
|
|
#include <dirent.h>
|
2019-06-14 15:59:50 +05:30
|
|
|
#include <limits.h>
|
2014-04-06 15:51:24 +05:30
|
|
|
#include <sys/stat.h>
|
2015-01-22 23:14:39 +05:30
|
|
|
#include <assert.h>
|
2014-04-06 15:51:24 +05:30
|
|
|
|
|
|
|
#include <xbps.h>
|
|
|
|
|
2015-02-16 23:23:45 +05:30
|
|
|
#define GOT_PKGNAME_VAR 0x1
|
|
|
|
#define GOT_VERSION_VAR 0x2
|
|
|
|
#define GOT_REVISION_VAR 0x4
|
|
|
|
|
2014-04-06 15:51:24 +05:30
|
|
|
typedef struct _rcv_t {
|
|
|
|
const char *prog, *fname;
|
2019-06-15 19:45:25 +05:30
|
|
|
char *xbps_conf, *rootdir, *distdir;
|
|
|
|
char *buf;
|
|
|
|
size_t bufsz;
|
2015-02-16 23:23:45 +05:30
|
|
|
size_t len;
|
2019-06-15 19:45:25 +05:30
|
|
|
char *ptr;
|
|
|
|
uint8_t have_vars;
|
2019-06-15 00:42:51 +05:30
|
|
|
xbps_dictionary_t env;
|
2014-04-06 15:51:24 +05:30
|
|
|
xbps_dictionary_t pkgd;
|
2019-06-15 00:42:51 +05:30
|
|
|
xbps_dictionary_t cache;
|
|
|
|
struct xbps_handle xhp;
|
2019-06-13 05:42:03 +05:30
|
|
|
bool show_all;
|
2014-04-06 15:51:24 +05:30
|
|
|
bool manual;
|
2014-04-07 14:09:12 +05:30
|
|
|
bool installed;
|
2019-06-14 16:29:25 +05:30
|
|
|
const char *format;
|
2019-06-15 00:42:51 +05:30
|
|
|
char *cachefile;
|
2014-04-06 15:51:24 +05:30
|
|
|
} rcv_t;
|
|
|
|
|
|
|
|
typedef int (*rcv_check_func)(rcv_t *);
|
|
|
|
typedef int (*rcv_proc_func)(rcv_t *, const char *, rcv_check_func);
|
|
|
|
|
2019-06-15 19:13:21 +05:30
|
|
|
static char *
|
|
|
|
xstrdup(const char *src)
|
|
|
|
{
|
|
|
|
char *p;
|
|
|
|
if (!(p = strdup(src))) {
|
|
|
|
fprintf(stderr, "Error: %s\n", strerror(errno));
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
return p;
|
|
|
|
}
|
|
|
|
|
2014-04-06 15:51:24 +05:30
|
|
|
static int
|
|
|
|
show_usage(const char *prog)
|
|
|
|
{
|
|
|
|
fprintf(stderr,
|
2014-04-07 14:23:32 +05:30
|
|
|
"Usage: %s [OPTIONS] [FILES...]\n\n"
|
2019-06-13 23:37:01 +05:30
|
|
|
"OPTIONS:\n"
|
|
|
|
" -h --help Show this helpful help-message for help.\n"
|
|
|
|
" -C --config <dir> Set path to xbps.d\n"
|
|
|
|
" -D --distdir <dir> Set (or override) the path to void-packages\n"
|
|
|
|
" (defaults to ~/void-packages).\n"
|
|
|
|
" -d --debug Enable debug output to stderr.\n"
|
2019-06-14 16:29:25 +05:30
|
|
|
" -f --format <fmt> Output format.\n"
|
2019-06-13 23:37:01 +05:30
|
|
|
" -I --installed Check for outdated packages in rootdir, rather\n"
|
|
|
|
" than in the XBPS repositories.\n"
|
|
|
|
" -i --ignore-conf-repos Ignore repositories defined in xbps.d.\n"
|
|
|
|
" -m --manual Only process listed files.\n"
|
|
|
|
" -R --repository=<url> Append repository to the head of repository list.\n"
|
|
|
|
" -r --rootdir <dir> Set root directory (defaults to /).\n"
|
|
|
|
" -s --show-all List all packages, in the format 'pkgname repover srcver'.\n"
|
|
|
|
"\n [FILES...] Extra packages to process with the outdated\n"
|
|
|
|
" ones (only processed if missing).\n\n",
|
2014-04-06 15:51:24 +05:30
|
|
|
prog);
|
|
|
|
return EXIT_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
rcv_init(rcv_t *rcv, const char *prog)
|
|
|
|
{
|
|
|
|
rcv->prog = prog;
|
|
|
|
rcv->have_vars = 0;
|
2019-06-15 19:45:25 +05:30
|
|
|
rcv->ptr = rcv->buf = NULL;
|
2019-06-15 00:42:51 +05:30
|
|
|
|
|
|
|
rcv->cache = xbps_dictionary_internalize_from_file(rcv->cachefile);
|
|
|
|
if (!rcv->cache)
|
|
|
|
rcv->cache = xbps_dictionary_create();
|
|
|
|
assert(rcv->cache);
|
|
|
|
|
2014-10-05 13:26:42 +05:30
|
|
|
if (rcv->xbps_conf != NULL) {
|
2014-11-06 14:28:04 +05:30
|
|
|
xbps_strlcpy(rcv->xhp.confdir, rcv->xbps_conf, sizeof(rcv->xhp.confdir));
|
2014-10-05 13:26:42 +05:30
|
|
|
}
|
2014-10-05 11:25:27 +05:30
|
|
|
if (rcv->rootdir != NULL) {
|
2014-11-06 14:28:04 +05:30
|
|
|
xbps_strlcpy(rcv->xhp.rootdir, rcv->rootdir, sizeof(rcv->xhp.rootdir));
|
2014-10-05 11:25:27 +05:30
|
|
|
}
|
2014-10-05 15:55:58 +05:30
|
|
|
if (xbps_init(&rcv->xhp) != 0)
|
|
|
|
abort();
|
2014-04-06 15:51:24 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
rcv_end(rcv_t *rcv)
|
|
|
|
{
|
2019-06-15 00:42:51 +05:30
|
|
|
xbps_dictionary_externalize_to_file(rcv->cache, rcv->cachefile);
|
|
|
|
|
2019-06-15 19:45:25 +05:30
|
|
|
if (rcv->buf != NULL) {
|
|
|
|
free(rcv->buf);
|
|
|
|
rcv->buf = NULL;
|
2014-04-06 15:51:24 +05:30
|
|
|
}
|
|
|
|
if (rcv->env != NULL) {
|
2019-06-15 00:42:51 +05:30
|
|
|
xbps_object_release(rcv->env);
|
2014-04-06 15:51:24 +05:30
|
|
|
rcv->env = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
xbps_end(&rcv->xhp);
|
|
|
|
|
|
|
|
if (rcv->xbps_conf != NULL)
|
|
|
|
free(rcv->xbps_conf);
|
|
|
|
if (rcv->distdir != NULL)
|
|
|
|
free(rcv->distdir);
|
2019-06-15 19:13:21 +05:30
|
|
|
|
2019-06-15 00:42:51 +05:30
|
|
|
free(rcv->cachefile);
|
2014-04-06 15:51:24 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
static bool
|
|
|
|
rcv_load_file(rcv_t *rcv, const char *fname)
|
|
|
|
{
|
|
|
|
FILE *file;
|
2014-10-07 11:03:28 +05:30
|
|
|
long offset;
|
2014-04-06 15:51:24 +05:30
|
|
|
rcv->fname = fname;
|
|
|
|
|
|
|
|
if ((file = fopen(rcv->fname, "r")) == NULL) {
|
|
|
|
if (!rcv->manual) {
|
|
|
|
fprintf(stderr, "FileError: can't open '%s': %s\n",
|
|
|
|
rcv->fname, strerror(errno));
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
fseek(file, 0, SEEK_END);
|
2014-10-07 11:03:28 +05:30
|
|
|
offset = ftell(file);
|
2014-04-06 15:51:24 +05:30
|
|
|
fseek(file, 0, SEEK_SET);
|
|
|
|
|
2014-10-07 11:03:28 +05:30
|
|
|
if (offset == -1) {
|
|
|
|
fclose(file);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
rcv->len = (size_t)offset;
|
|
|
|
|
2019-06-15 19:45:25 +05:30
|
|
|
if (rcv->buf == NULL) {
|
|
|
|
rcv->bufsz = rcv->len+1;
|
|
|
|
if (!(rcv->buf = calloc(rcv->bufsz, sizeof(char)))) {
|
|
|
|
fprintf(stderr, "MemError: can't allocate memory: %s\n",
|
|
|
|
strerror(errno));
|
|
|
|
fclose(file);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
} else if (rcv->bufsz <= rcv->len) {
|
|
|
|
rcv->bufsz = rcv->len+1;
|
|
|
|
if (!(rcv->buf = realloc(rcv->buf, rcv->bufsz))) {
|
|
|
|
fprintf(stderr, "MemError: can't allocate memory: %s\n",
|
|
|
|
strerror(errno));
|
|
|
|
fclose(file);
|
|
|
|
return false;
|
|
|
|
}
|
2014-04-06 15:51:24 +05:30
|
|
|
}
|
|
|
|
|
2019-06-15 19:45:25 +05:30
|
|
|
(void)fread(rcv->buf, sizeof(char), rcv->len, file);
|
|
|
|
rcv->buf[rcv->len] = '\0';
|
2014-04-06 15:51:24 +05:30
|
|
|
fclose(file);
|
2019-06-15 19:45:25 +05:30
|
|
|
rcv->ptr = rcv->buf;
|
2014-04-06 15:51:24 +05:30
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2019-06-15 00:42:51 +05:30
|
|
|
static char *
|
|
|
|
rcv_sh_substitute(rcv_t *rcv, const char *str, size_t len)
|
2014-04-06 15:51:24 +05:30
|
|
|
{
|
2019-06-14 01:09:45 +05:30
|
|
|
const char *p;
|
2019-06-15 00:42:51 +05:30
|
|
|
char *cmd, *ret;
|
|
|
|
xbps_string_t out = xbps_string_create();
|
|
|
|
char b[2] = {0};
|
2019-06-14 01:09:45 +05:30
|
|
|
|
|
|
|
for (p = str; *p && p < str+len; p++) {
|
|
|
|
switch (*p) {
|
|
|
|
case '$':
|
|
|
|
if (p+1 < str+len) {
|
2019-06-15 00:42:51 +05:30
|
|
|
char buf[1024] = {0};
|
2019-06-14 01:09:45 +05:30
|
|
|
const char *ref;
|
2019-06-15 00:42:51 +05:30
|
|
|
const char *val;
|
2019-06-14 01:09:45 +05:30
|
|
|
size_t reflen;
|
|
|
|
p++;
|
|
|
|
if (*p == '(') {
|
|
|
|
FILE *fp;
|
2019-06-18 18:33:00 +05:30
|
|
|
int c;
|
2019-06-14 01:09:45 +05:30
|
|
|
for (ref = ++p; *p && p < str+len && *p != ')'; p++)
|
|
|
|
;
|
|
|
|
if (*p != ')')
|
|
|
|
goto err1;
|
|
|
|
cmd = strndup(ref, p-ref);
|
|
|
|
if ((fp = popen(cmd, "r")) == NULL)
|
|
|
|
goto err2;
|
2019-06-15 00:42:51 +05:30
|
|
|
while ((c = fgetc(fp)) != EOF && c != '\n') {
|
|
|
|
*b = c;
|
|
|
|
xbps_string_append_cstring(out, b);
|
|
|
|
}
|
2019-06-14 01:09:45 +05:30
|
|
|
if (pclose(fp) != 0)
|
|
|
|
goto err2;
|
|
|
|
free(cmd);
|
|
|
|
cmd = NULL;
|
|
|
|
continue;
|
|
|
|
} else if (*p == '{') {
|
|
|
|
for (ref = ++p; *p && p < str+len && (isalnum(*p) || *p == '_'); p++)
|
|
|
|
;
|
|
|
|
reflen = p-ref;
|
|
|
|
switch (*p) {
|
|
|
|
case '/': /* fallthrough */
|
|
|
|
case '%': /* fallthrough */
|
|
|
|
case '#': /* fallthrough */
|
|
|
|
case ':':
|
|
|
|
for (; *p && p < str+len && *p != '}'; p++)
|
|
|
|
;
|
|
|
|
if (*p != '}')
|
|
|
|
goto err1;
|
|
|
|
break;
|
|
|
|
case '}':
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
goto err1;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
for (ref = p; *p && p < str+len && (isalnum(*p) || *p == '_'); p++)
|
|
|
|
;
|
|
|
|
reflen = p-ref;
|
2019-06-14 02:53:08 +05:30
|
|
|
p--;
|
2019-06-14 01:09:45 +05:30
|
|
|
}
|
2019-06-15 00:42:51 +05:30
|
|
|
if (reflen) {
|
|
|
|
if (reflen >= sizeof buf) {
|
|
|
|
fprintf(stderr, "out of memory\n");
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
strncpy(buf, ref, reflen);
|
|
|
|
if (xbps_dictionary_get_cstring_nocopy(rcv->env, buf, &val))
|
|
|
|
xbps_string_append_cstring(out, val);
|
|
|
|
else
|
|
|
|
xbps_string_append_cstring(out, "NULL");
|
|
|
|
break;
|
2019-06-14 01:09:45 +05:30
|
|
|
}
|
2014-04-06 15:51:24 +05:30
|
|
|
}
|
2019-06-14 01:09:45 +05:30
|
|
|
/* fallthrough */
|
|
|
|
default:
|
2019-06-15 00:42:51 +05:30
|
|
|
*b = *p;
|
|
|
|
xbps_string_append_cstring(out, b);
|
2014-04-06 15:51:24 +05:30
|
|
|
}
|
|
|
|
}
|
2019-06-15 00:42:51 +05:30
|
|
|
|
|
|
|
ret = xbps_string_cstring(out);
|
|
|
|
xbps_object_release(out);
|
|
|
|
return ret;
|
2014-04-06 15:51:24 +05:30
|
|
|
|
2019-06-14 01:09:45 +05:30
|
|
|
err1:
|
|
|
|
fprintf(stderr, "syntax error: in file '%s'\n", rcv->fname);
|
|
|
|
exit(1);
|
|
|
|
err2:
|
|
|
|
fprintf(stderr,
|
|
|
|
"Shell cmd failed: '%s' for "
|
|
|
|
"template '%s'",
|
|
|
|
cmd, rcv->fname);
|
|
|
|
if (errno > 0) {
|
|
|
|
fprintf(stderr, ": %s\n",
|
|
|
|
strerror(errno));
|
|
|
|
} else {
|
|
|
|
fputc('\n', stderr);
|
2014-04-06 15:51:24 +05:30
|
|
|
}
|
2019-06-14 01:09:45 +05:30
|
|
|
exit(1);
|
2014-04-06 15:51:24 +05:30
|
|
|
}
|
|
|
|
|
2015-02-16 23:23:45 +05:30
|
|
|
static void
|
2014-04-06 15:51:24 +05:30
|
|
|
rcv_get_pkgver(rcv_t *rcv)
|
|
|
|
{
|
|
|
|
size_t klen, vlen;
|
2019-06-15 00:42:51 +05:30
|
|
|
char c, *ptr = rcv->ptr, *e, *p, *k, *v, *comment, *d, *key, *val;
|
2015-02-16 23:23:45 +05:30
|
|
|
uint8_t vars = 0;
|
2014-04-06 15:51:24 +05:30
|
|
|
|
|
|
|
while ((c = *ptr) != '\0') {
|
2015-02-17 14:50:59 +05:30
|
|
|
if (c == '#' || c == '.') {
|
|
|
|
goto nextline;
|
2014-04-06 15:51:24 +05:30
|
|
|
}
|
|
|
|
if (c == '\n') {
|
|
|
|
ptr++;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (c == 'u' && (strncmp("unset", ptr, 5)) == 0) {
|
2015-02-17 14:50:59 +05:30
|
|
|
goto nextline;
|
2014-04-06 15:51:24 +05:30
|
|
|
}
|
2015-02-16 23:23:45 +05:30
|
|
|
if ((e = strchr(ptr, '=')) == NULL)
|
2015-02-17 14:50:59 +05:30
|
|
|
goto nextline;
|
2015-02-16 23:23:45 +05:30
|
|
|
|
|
|
|
p = strchr(ptr, '\n');
|
|
|
|
k = ptr;
|
|
|
|
v = e + 1;
|
2015-02-17 14:50:59 +05:30
|
|
|
|
|
|
|
assert(p);
|
|
|
|
assert(k);
|
|
|
|
assert(v);
|
|
|
|
|
2015-02-16 23:23:45 +05:30
|
|
|
klen = strlen(k) - strlen(e);
|
|
|
|
vlen = strlen(v) - strlen(p);
|
2015-02-17 14:50:59 +05:30
|
|
|
|
2015-02-16 23:23:45 +05:30
|
|
|
if (v[0] == '"' && vlen == 1) {
|
2015-02-17 14:50:59 +05:30
|
|
|
while (*ptr++ != '"')
|
|
|
|
;
|
|
|
|
goto nextline;
|
|
|
|
}
|
|
|
|
if (v[0] == '"') {
|
|
|
|
v++;
|
|
|
|
vlen--;
|
|
|
|
}
|
|
|
|
if (v[vlen-1] == '"') {
|
|
|
|
vlen--;
|
|
|
|
}
|
2015-10-31 22:19:55 +05:30
|
|
|
comment = strchr(v, '#');
|
2019-06-14 01:11:16 +05:30
|
|
|
if (comment && comment < p && (comment > v && comment[-1] == ' ')) {
|
2015-10-31 22:19:55 +05:30
|
|
|
while (v[vlen-1] != '#') {
|
|
|
|
vlen--;
|
|
|
|
}
|
|
|
|
vlen--;
|
|
|
|
while (isspace(v[vlen-1])) {
|
|
|
|
vlen--;
|
|
|
|
}
|
|
|
|
}
|
2015-02-17 14:50:59 +05:30
|
|
|
if (vlen == 0) {
|
|
|
|
goto nextline;
|
2015-02-16 23:23:45 +05:30
|
|
|
}
|
2019-06-15 00:42:51 +05:30
|
|
|
key = strndup(k, klen);
|
|
|
|
|
|
|
|
if ((d = strchr(v, '$')) && d < v+vlen)
|
|
|
|
val = rcv_sh_substitute(rcv, v, vlen);
|
|
|
|
else
|
|
|
|
val = strndup(v, vlen);
|
|
|
|
|
|
|
|
if (!xbps_dictionary_set(rcv->env, key,
|
|
|
|
xbps_string_create_cstring(val))) {
|
|
|
|
fprintf(stderr, "error: xbps_dictionary_set");
|
|
|
|
exit(1);
|
2015-10-31 22:19:55 +05:30
|
|
|
}
|
2019-06-15 00:42:51 +05:30
|
|
|
|
|
|
|
if (rcv->xhp.flags & XBPS_FLAG_DEBUG)
|
|
|
|
fprintf(stderr, "%s: %s %s\n", rcv->fname, key, val);
|
|
|
|
|
|
|
|
free(key);
|
|
|
|
free(val);
|
|
|
|
|
2015-02-16 23:23:45 +05:30
|
|
|
if (strncmp("pkgname", k, klen) == 0) {
|
|
|
|
rcv->have_vars |= GOT_PKGNAME_VAR;
|
|
|
|
vars++;
|
|
|
|
} else if (strncmp("version", k, klen) == 0) {
|
|
|
|
rcv->have_vars |= GOT_VERSION_VAR;
|
|
|
|
vars++;
|
|
|
|
} else if (strncmp("revision", k, klen) == 0) {
|
|
|
|
rcv->have_vars |= GOT_REVISION_VAR;
|
|
|
|
vars++;
|
|
|
|
}
|
|
|
|
if (vars > 2)
|
|
|
|
return;
|
2015-02-17 14:50:59 +05:30
|
|
|
|
|
|
|
nextline:
|
2014-04-06 15:51:24 +05:30
|
|
|
ptr = strchr(ptr, '\n') + 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
rcv_process_file(rcv_t *rcv, const char *fname, rcv_check_func check)
|
|
|
|
{
|
2019-06-15 00:42:51 +05:30
|
|
|
int rv = 0;
|
|
|
|
xbps_object_t keysym;
|
|
|
|
xbps_object_iterator_t iter;
|
|
|
|
xbps_dictionary_t d;
|
|
|
|
xbps_data_t mtime;
|
|
|
|
const char *pkgname, *version, *revision, *reverts;
|
|
|
|
struct stat st;
|
|
|
|
bool allocenv = false;
|
|
|
|
|
|
|
|
if (stat(fname, &st) == -1) {
|
|
|
|
rv = EXIT_FAILURE;
|
|
|
|
goto ret;
|
2014-10-07 11:25:54 +05:30
|
|
|
}
|
2019-06-15 00:42:51 +05:30
|
|
|
|
|
|
|
if ((d = xbps_dictionary_get(rcv->cache, fname))) {
|
|
|
|
mtime = xbps_dictionary_get(d, "mtime");
|
|
|
|
if (!xbps_data_equals_data(mtime, &st.st_mtim, sizeof st.st_mtim))
|
|
|
|
goto update;
|
|
|
|
rcv->env = d;
|
|
|
|
rcv->have_vars = GOT_PKGNAME_VAR | GOT_VERSION_VAR | GOT_REVISION_VAR;
|
2019-06-15 18:49:30 +05:30
|
|
|
rcv->fname = fname;
|
2019-06-15 00:42:51 +05:30
|
|
|
} else {
|
|
|
|
update:
|
|
|
|
if (!rcv_load_file(rcv, fname)) {
|
|
|
|
rv = EXIT_FAILURE;
|
|
|
|
goto ret;
|
|
|
|
}
|
2019-06-18 21:22:19 +05:30
|
|
|
assert(rcv);
|
|
|
|
rcv->env = xbps_dictionary_create();
|
|
|
|
assert(rcv->env);
|
2019-06-15 00:42:51 +05:30
|
|
|
allocenv = true;
|
|
|
|
rcv_get_pkgver(rcv);
|
|
|
|
|
|
|
|
if (!xbps_dictionary_get_cstring_nocopy(rcv->env, "pkgname", &pkgname) ||
|
|
|
|
!xbps_dictionary_get_cstring_nocopy(rcv->env, "version", &version) ||
|
|
|
|
!xbps_dictionary_get_cstring_nocopy(rcv->env, "revision", &revision)) {
|
|
|
|
fprintf(stderr, "ERROR: '%s':"
|
|
|
|
" missing required variable (pkgname, version or revision)!",
|
|
|
|
fname);
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
if (!d) {
|
|
|
|
d = xbps_dictionary_create();
|
|
|
|
xbps_dictionary_set(rcv->cache, fname, d);
|
|
|
|
}
|
2019-06-18 21:22:19 +05:30
|
|
|
xbps_dictionary_set_cstring(d, "pkgname", pkgname);
|
|
|
|
xbps_dictionary_set_cstring(d, "version", version);
|
|
|
|
xbps_dictionary_set_cstring(d, "revision", revision);
|
2019-06-15 00:42:51 +05:30
|
|
|
|
|
|
|
reverts = NULL;
|
|
|
|
xbps_dictionary_get_cstring_nocopy(rcv->env, "reverts", &reverts);
|
|
|
|
if (reverts)
|
2019-06-18 21:22:19 +05:30
|
|
|
xbps_dictionary_set_cstring(d, "reverts", reverts);
|
2019-06-15 00:42:51 +05:30
|
|
|
|
|
|
|
mtime = xbps_data_create_data(&st.st_mtim, sizeof st.st_mtim);
|
2019-06-18 21:22:19 +05:30
|
|
|
xbps_dictionary_set(d, "mtime", mtime);
|
2014-04-06 15:51:24 +05:30
|
|
|
}
|
2019-06-15 00:42:51 +05:30
|
|
|
|
2014-04-06 15:51:24 +05:30
|
|
|
check(rcv);
|
|
|
|
|
2019-06-15 00:42:51 +05:30
|
|
|
ret:
|
|
|
|
if (allocenv) {
|
|
|
|
iter = xbps_dictionary_iterator(rcv->env);
|
|
|
|
while ((keysym = xbps_object_iterator_next(iter)))
|
|
|
|
xbps_object_release(xbps_dictionary_get_keysym(rcv->env, keysym));
|
|
|
|
xbps_object_iterator_release(iter);
|
|
|
|
xbps_object_release(rcv->env);
|
|
|
|
}
|
|
|
|
rcv->env = NULL;
|
|
|
|
return rv;
|
2014-04-06 15:51:24 +05:30
|
|
|
}
|
|
|
|
|
2014-09-25 20:28:39 +05:30
|
|
|
static bool
|
2019-06-15 00:42:51 +05:30
|
|
|
check_reverts(const char *repover, const char *reverts)
|
2014-11-06 14:28:04 +05:30
|
|
|
{
|
2019-06-15 18:50:11 +05:30
|
|
|
const char *s, *e;
|
2019-06-15 00:42:51 +05:30
|
|
|
size_t len;
|
2014-09-25 20:28:39 +05:30
|
|
|
|
2019-06-15 00:42:51 +05:30
|
|
|
assert(reverts);
|
2014-09-25 20:28:39 +05:30
|
|
|
|
2019-06-15 18:50:11 +05:30
|
|
|
s = reverts;
|
|
|
|
if ((len = strlen(s)) == 0)
|
|
|
|
return false;
|
2014-09-25 20:28:39 +05:30
|
|
|
|
2019-06-15 18:50:11 +05:30
|
|
|
for (s = reverts; s < reverts+len; s = e+1) {
|
|
|
|
if (!(e = strchr(s, ' ')))
|
|
|
|
e = reverts+len;
|
|
|
|
if (strncmp(s, repover, e-s) == 0)
|
|
|
|
return true;
|
2014-09-25 20:28:39 +05:30
|
|
|
}
|
|
|
|
|
2019-06-15 18:50:11 +05:30
|
|
|
return false;
|
2014-09-25 20:28:39 +05:30
|
|
|
}
|
|
|
|
|
2019-06-14 16:29:25 +05:30
|
|
|
static void
|
|
|
|
rcv_printf(rcv_t *rcv, FILE *fp, const char *pkgname, const char *repover,
|
2019-06-19 16:37:42 +05:30
|
|
|
const char *srcver, const char *repourl)
|
2019-06-14 16:29:25 +05:30
|
|
|
{
|
2019-06-14 18:02:24 +05:30
|
|
|
const char *f, *p;
|
2019-06-14 16:29:25 +05:30
|
|
|
|
|
|
|
for (f = rcv->format; *f; f++) {
|
|
|
|
if (*f == '\\') {
|
|
|
|
f++;
|
|
|
|
switch (*f) {
|
|
|
|
case '\n': fputc('\n', fp); break;
|
|
|
|
case '\t': fputc('\t', fp); break;
|
|
|
|
case '\0': fputc('\0', fp); break;
|
|
|
|
default:
|
|
|
|
fputc('\\', fp);
|
|
|
|
fputc(*f, fp);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (*f != '%') {
|
|
|
|
fputc(*f, fp);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
switch (*++f) {
|
|
|
|
case '%': fputc(*f, fp); break;
|
|
|
|
case 'n': fputs(pkgname, fp); break;
|
|
|
|
case 'r': fputs(repover, fp); break;
|
2019-06-19 16:37:42 +05:30
|
|
|
case 'R': fputs(repourl, fp); break;
|
2019-06-14 16:29:25 +05:30
|
|
|
case 's': fputs(srcver, fp); break;
|
2019-06-14 16:45:53 +05:30
|
|
|
case 't':
|
2019-06-14 18:02:24 +05:30
|
|
|
p = strchr(rcv->fname, '/');
|
|
|
|
fwrite(rcv->fname, p ? (size_t)(p - rcv->fname) : strlen(rcv->fname), 1, fp);
|
2019-06-14 16:45:53 +05:30
|
|
|
break;
|
2019-06-14 16:29:25 +05:30
|
|
|
}
|
|
|
|
}
|
|
|
|
fputc('\n', fp);
|
|
|
|
}
|
|
|
|
|
2014-04-06 15:51:24 +05:30
|
|
|
static int
|
|
|
|
rcv_check_version(rcv_t *rcv)
|
|
|
|
{
|
|
|
|
const char *repover = NULL;
|
2019-03-22 20:37:43 +05:30
|
|
|
char srcver[BUFSIZ] = { '\0' };
|
2019-06-19 16:37:42 +05:30
|
|
|
const char *pkgname, *version, *revision, *reverts, *repourl;
|
2019-03-22 20:37:43 +05:30
|
|
|
int sz;
|
2014-04-06 15:51:24 +05:30
|
|
|
|
2015-02-16 23:23:45 +05:30
|
|
|
assert(rcv);
|
|
|
|
|
|
|
|
if ((rcv->have_vars & GOT_PKGNAME_VAR) == 0) {
|
|
|
|
fprintf(stderr, "ERROR: '%s': missing pkgname variable!\n", rcv->fname);
|
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
}
|
|
|
|
if ((rcv->have_vars & GOT_VERSION_VAR) == 0) {
|
|
|
|
fprintf(stderr, "ERROR: '%s': missing version variable!\n", rcv->fname);
|
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
}
|
|
|
|
if ((rcv->have_vars & GOT_REVISION_VAR) == 0) {
|
|
|
|
fprintf(stderr, "ERROR: '%s': missing revision variable!\n", rcv->fname);
|
2014-04-06 15:51:24 +05:30
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
}
|
|
|
|
|
2019-06-15 00:42:51 +05:30
|
|
|
if (!xbps_dictionary_get_cstring_nocopy(rcv->env, "pkgname", &pkgname) ||
|
|
|
|
!xbps_dictionary_get_cstring_nocopy(rcv->env, "version", &version) ||
|
|
|
|
!xbps_dictionary_get_cstring_nocopy(rcv->env, "revision", &revision)) {
|
|
|
|
fprintf(stderr, "error:\n");
|
|
|
|
exit(1);
|
|
|
|
}
|
2015-12-21 21:21:24 +05:30
|
|
|
|
2019-06-15 00:42:51 +05:30
|
|
|
reverts = NULL;
|
|
|
|
xbps_dictionary_get_cstring_nocopy(rcv->env, "reverts", &reverts);
|
2019-06-14 16:29:25 +05:30
|
|
|
|
2019-06-15 00:42:51 +05:30
|
|
|
sz = snprintf(srcver, sizeof srcver, "%s_%s", version, revision);
|
2019-03-22 20:37:43 +05:30
|
|
|
if (sz < 0 || (size_t)sz >= sizeof srcver)
|
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
|
2019-06-19 17:30:54 +05:30
|
|
|
repourl = NULL;
|
2019-06-19 16:37:42 +05:30
|
|
|
if (rcv->installed) {
|
2019-06-15 00:42:51 +05:30
|
|
|
rcv->pkgd = xbps_pkgdb_get_pkg(&rcv->xhp, pkgname);
|
2019-06-19 16:37:42 +05:30
|
|
|
} else {
|
2019-06-15 00:42:51 +05:30
|
|
|
rcv->pkgd = xbps_rpool_get_pkg(&rcv->xhp, pkgname);
|
2019-06-19 16:37:42 +05:30
|
|
|
xbps_dictionary_get_cstring_nocopy(rcv->pkgd, "repository", &repourl);
|
|
|
|
}
|
2014-04-06 15:51:24 +05:30
|
|
|
xbps_dictionary_get_cstring_nocopy(rcv->pkgd, "pkgver", &repover);
|
2019-06-15 00:42:51 +05:30
|
|
|
if (repover)
|
|
|
|
repover += strlen(pkgname)+1;
|
2015-02-17 14:50:59 +05:30
|
|
|
|
2019-06-13 16:58:48 +05:30
|
|
|
if (!repover && rcv->manual)
|
|
|
|
;
|
|
|
|
else if (rcv->show_all)
|
|
|
|
;
|
2019-06-15 00:42:51 +05:30
|
|
|
else if (repover && (xbps_cmpver(repover, srcver) < 0 ||
|
|
|
|
(reverts && check_reverts(repover, reverts))))
|
2019-06-13 16:58:48 +05:30
|
|
|
;
|
|
|
|
else
|
|
|
|
return 0;
|
2019-06-13 05:42:03 +05:30
|
|
|
|
2019-06-15 00:42:51 +05:30
|
|
|
repover = repover ? repover : "?";
|
2019-06-19 16:37:42 +05:30
|
|
|
repourl = repourl ? repourl : "?";
|
|
|
|
rcv_printf(rcv, stdout, pkgname, repover, srcver, repourl);
|
2019-06-13 05:42:03 +05:30
|
|
|
|
2014-04-06 15:51:24 +05:30
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2019-06-15 19:13:21 +05:30
|
|
|
rcv_process_dir(rcv_t *rcv, rcv_proc_func process)
|
2014-04-06 15:51:24 +05:30
|
|
|
{
|
2014-10-05 13:36:42 +05:30
|
|
|
DIR *dir = NULL;
|
2014-04-06 15:51:24 +05:30
|
|
|
struct dirent entry, *result;
|
|
|
|
struct stat st;
|
|
|
|
char filename[BUFSIZ];
|
2019-06-15 19:13:21 +05:30
|
|
|
int i, ret = 0;
|
2014-04-06 15:51:24 +05:30
|
|
|
|
2019-06-15 19:13:21 +05:30
|
|
|
if (!(dir = opendir(".")))
|
2014-04-06 15:51:24 +05:30
|
|
|
goto error;
|
2019-06-15 19:13:21 +05:30
|
|
|
|
2015-02-17 14:50:59 +05:30
|
|
|
for (;;) {
|
2014-04-06 15:51:24 +05:30
|
|
|
i = readdir_r(dir, &entry, &result);
|
2019-06-15 19:13:21 +05:30
|
|
|
if (i > 0)
|
2014-04-06 15:51:24 +05:30
|
|
|
goto error;
|
2015-02-17 14:50:59 +05:30
|
|
|
if (result == NULL)
|
|
|
|
break;
|
|
|
|
if ((strcmp(result->d_name, ".") == 0) ||
|
|
|
|
(strcmp(result->d_name, "..") == 0))
|
|
|
|
continue;
|
2019-06-15 19:13:21 +05:30
|
|
|
if ((lstat(result->d_name, &st)) != 0)
|
2014-04-06 15:51:24 +05:30
|
|
|
goto error;
|
2015-02-17 14:50:59 +05:30
|
|
|
if (S_ISLNK(st.st_mode) != 0)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
snprintf(filename, sizeof(filename), "%s/template", result->d_name);
|
2014-04-06 15:51:24 +05:30
|
|
|
ret = process(rcv, filename, rcv_check_version);
|
|
|
|
}
|
|
|
|
|
2019-06-15 19:13:21 +05:30
|
|
|
if ((closedir(dir)) != -1)
|
|
|
|
return ret;
|
|
|
|
error:
|
|
|
|
fprintf(stderr, "Error: while processing dir '%s/srcpkgs': %s\n",
|
|
|
|
rcv->distdir, strerror(errno));
|
|
|
|
exit(1);
|
2014-04-06 15:51:24 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
main(int argc, char **argv)
|
|
|
|
{
|
|
|
|
int i, c;
|
|
|
|
rcv_t rcv;
|
2019-06-14 16:29:25 +05:30
|
|
|
const char *prog = argv[0], *sopts = "hC:D:df:iImR:r:sV";
|
2014-04-06 15:51:24 +05:30
|
|
|
const struct option lopts[] = {
|
|
|
|
{ "help", no_argument, NULL, 'h' },
|
2014-04-07 17:41:47 +05:30
|
|
|
{ "config", required_argument, NULL, 'C' },
|
2014-04-17 14:01:00 +05:30
|
|
|
{ "distdir", required_argument, NULL, 'D' },
|
|
|
|
{ "debug", no_argument, NULL, 'd' },
|
2019-06-14 16:29:25 +05:30
|
|
|
{ "format", no_argument, NULL, 'f' },
|
2019-06-12 23:28:08 +05:30
|
|
|
{ "installed", no_argument, NULL, 'I' },
|
|
|
|
{ "ignore-conf-repos", no_argument, NULL, 'i' },
|
2019-06-13 16:02:49 +05:30
|
|
|
{ "manual", no_argument, NULL, 'm' },
|
2014-04-17 14:01:00 +05:30
|
|
|
{ "repository", required_argument, NULL, 'R' },
|
2014-04-07 14:09:12 +05:30
|
|
|
{ "rootdir", required_argument, NULL, 'r' },
|
2019-06-13 05:42:03 +05:30
|
|
|
{ "show-all", no_argument, NULL, 's' },
|
2014-04-07 15:48:20 +05:30
|
|
|
{ "version", no_argument, NULL, 'V' },
|
2014-04-06 15:51:24 +05:30
|
|
|
{ NULL, 0, NULL, 0 }
|
|
|
|
};
|
|
|
|
|
2015-01-22 23:14:39 +05:30
|
|
|
memset(&rcv, 0, sizeof(rcv_t));
|
2019-06-13 16:02:49 +05:30
|
|
|
rcv.manual = false;
|
2019-06-19 16:57:08 +05:30
|
|
|
rcv.format = "%n %r %s %t %R";
|
2014-04-06 15:51:24 +05:30
|
|
|
|
|
|
|
while ((c = getopt_long(argc, argv, sopts, lopts, NULL)) != -1) {
|
|
|
|
switch (c) {
|
|
|
|
case 'h':
|
|
|
|
return show_usage(prog);
|
|
|
|
case 'C':
|
2019-06-15 19:13:21 +05:30
|
|
|
rcv.xbps_conf = xstrdup(optarg);
|
2014-04-06 15:51:24 +05:30
|
|
|
break;
|
2014-04-17 14:01:00 +05:30
|
|
|
case 'D':
|
2019-06-15 19:13:21 +05:30
|
|
|
rcv.distdir = xstrdup(optarg);
|
2014-04-06 15:51:24 +05:30
|
|
|
break;
|
2014-04-17 14:01:00 +05:30
|
|
|
case 'd':
|
|
|
|
rcv.xhp.flags |= XBPS_FLAG_DEBUG;
|
|
|
|
break;
|
2019-06-14 16:29:25 +05:30
|
|
|
case 'f':
|
|
|
|
rcv.format = optarg;
|
|
|
|
break;
|
2014-04-07 14:09:12 +05:30
|
|
|
case 'i':
|
2019-06-12 23:23:41 +05:30
|
|
|
rcv.xhp.flags |= XBPS_FLAG_IGNORE_CONF_REPOS;
|
|
|
|
break;
|
|
|
|
case 'I':
|
2014-04-07 14:09:12 +05:30
|
|
|
rcv.installed = true;
|
|
|
|
break;
|
2019-06-13 16:02:49 +05:30
|
|
|
case 'm':
|
|
|
|
rcv.manual = true;
|
|
|
|
break;
|
2014-04-17 14:01:00 +05:30
|
|
|
case 'R':
|
2019-06-13 16:33:47 +05:30
|
|
|
xbps_repo_store(&rcv.xhp, optarg);
|
2014-04-17 14:01:00 +05:30
|
|
|
break;
|
2014-04-07 14:09:12 +05:30
|
|
|
case 'r':
|
2019-06-15 19:13:21 +05:30
|
|
|
rcv.rootdir = optarg;
|
2014-04-07 14:09:12 +05:30
|
|
|
break;
|
2014-04-06 15:51:24 +05:30
|
|
|
case 's':
|
2019-06-13 05:42:03 +05:30
|
|
|
rcv.show_all = true;
|
2014-04-06 15:51:24 +05:30
|
|
|
break;
|
2014-04-07 15:48:20 +05:30
|
|
|
case 'V':
|
|
|
|
printf("%s\n", XBPS_RELVER);
|
|
|
|
exit(EXIT_SUCCESS);
|
2014-04-06 15:51:24 +05:30
|
|
|
default:
|
|
|
|
return show_usage(prog);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/*
|
2014-09-26 17:54:06 +05:30
|
|
|
* If --distdir not set default to ~/void-packages.
|
2014-04-06 15:51:24 +05:30
|
|
|
*/
|
2019-06-15 19:13:21 +05:30
|
|
|
if (rcv.distdir == NULL)
|
|
|
|
rcv.distdir = xbps_xasprintf("%s/void-packages", getenv("HOME"));
|
2019-06-15 00:42:51 +05:30
|
|
|
rcv.cachefile = xbps_xasprintf("%s/.xbps-checkvers.plist", rcv.distdir);
|
2019-06-15 19:13:21 +05:30
|
|
|
|
2014-04-06 15:51:24 +05:30
|
|
|
argc -= optind;
|
|
|
|
argv += optind;
|
|
|
|
|
|
|
|
rcv_init(&rcv, prog);
|
2019-06-13 16:02:49 +05:30
|
|
|
|
2019-06-15 19:13:21 +05:30
|
|
|
if (chdir(rcv.distdir) == -1 || chdir("srcpkgs") == -1) {
|
|
|
|
fprintf(stderr, "Error: while changing directory to '%s/srcpkgs': %s\n",
|
|
|
|
rcv.distdir, strerror(errno));
|
2019-06-13 16:02:49 +05:30
|
|
|
exit(1);
|
|
|
|
}
|
2019-06-15 19:13:21 +05:30
|
|
|
|
|
|
|
if (!rcv.manual)
|
|
|
|
rcv_process_dir(&rcv, rcv_process_file);
|
|
|
|
|
2014-04-06 15:51:24 +05:30
|
|
|
rcv.manual = true;
|
2015-01-22 23:14:39 +05:30
|
|
|
for (i = 0; i < argc; i++) {
|
2019-06-15 00:42:51 +05:30
|
|
|
char tmp[PATH_MAX] = {0}, *tmpl, *p;
|
2019-06-14 15:59:50 +05:30
|
|
|
if (strncmp(argv[i], "srcpkgs/", sizeof ("srcpkgs/")-1) == 0) {
|
|
|
|
argv[i] += sizeof ("srcpkgs/")-1;
|
2014-04-06 15:51:24 +05:30
|
|
|
}
|
2019-06-14 15:59:50 +05:30
|
|
|
if ((p = strrchr(argv[i], '/')) && (strcmp(p, "/template")) == 0) {
|
|
|
|
tmpl = argv[i];
|
|
|
|
} else {
|
|
|
|
xbps_strlcat(tmp, argv[i], sizeof tmp);
|
|
|
|
xbps_strlcat(tmp, "/template", sizeof tmp);
|
|
|
|
tmpl = tmp;
|
|
|
|
}
|
|
|
|
rcv_process_file(&rcv, tmpl, rcv_check_version);
|
2014-04-06 15:51:24 +05:30
|
|
|
}
|
|
|
|
rcv_end(&rcv);
|
2015-01-22 23:14:39 +05:30
|
|
|
exit(EXIT_SUCCESS);
|
2014-04-06 15:51:24 +05:30
|
|
|
}
|