[gentoo-commits] proj/portage-utils:master commit in: libq/

2024-07-03 Thread Fabian Groffen
commit: 191fc5a7cf9cec475ab74eb42525502a27d9e586
Author: Fabian Groffen  gentoo  org>
AuthorDate: Sat Jun 29 10:41:48 2024 +
Commit: Fabian Groffen  gentoo  org>
CommitDate: Sat Jun 29 10:41:48 2024 +
URL:https://gitweb.gentoo.org/proj/portage-utils.git/commit/?id=191fc5a7

libq/Makefile: fix out-of-srcdir build

Signed-off-by: Fabian Groffen  gentoo.org>

 libq/Makefile.am | 3 ++-
 libq/Makefile.in | 3 ++-
 2 files changed, 4 insertions(+), 2 deletions(-)

diff --git a/libq/Makefile.am b/libq/Makefile.am
index e65bb47..428d012 100644
--- a/libq/Makefile.am
+++ b/libq/Makefile.am
@@ -33,4 +33,5 @@ libq_a_SOURCES = $(QFILES)
 libq_a_CPPFLAGS = \
$(OPENMP_CFLAGS) \
-I$(top_builddir)/autotools/gnulib \
-   -I$(top_srcdir)/autotools/gnulib
+   -I$(top_srcdir)/autotools/gnulib \
+   -I$(top_srcdir)

diff --git a/libq/Makefile.in b/libq/Makefile.in
index fdbfb65..6f45c93 100644
--- a/libq/Makefile.in
+++ b/libq/Makefile.in
@@ -1711,7 +1711,8 @@ libq_a_SOURCES = $(QFILES)
 libq_a_CPPFLAGS = \
$(OPENMP_CFLAGS) \
-I$(top_builddir)/autotools/gnulib \
-   -I$(top_srcdir)/autotools/gnulib
+   -I$(top_srcdir)/autotools/gnulib \
+   -I$(top_srcdir)
 
 all: all-am
 



[gentoo-commits] proj/portage-utils:master commit in: libq/, /

2024-06-27 Thread Fabian Groffen
commit: 092dbac3c93d4a5f6fc2e5d496e17a0405c950a7
Author: Fabian Groffen  gentoo  org>
AuthorDate: Thu Jun 27 19:17:23 2024 +
Commit: Fabian Groffen  gentoo  org>
CommitDate: Thu Jun 27 19:17:23 2024 +
URL:https://gitweb.gentoo.org/proj/portage-utils.git/commit/?id=092dbac3

*: remove i18n/gettext support

This looked very rudimentary, and half, there were no translations, and
not all strings were covered.  It was never enabled, so dummy for many
releases.

Signed-off-by: Fabian Groffen  gentoo.org>

 libq/i18n.h | 17 -
 main.c  | 14 +-
 main.h  |  9 -
 qcheck.c|  2 +-
 4 files changed, 10 insertions(+), 32 deletions(-)

diff --git a/libq/i18n.h b/libq/i18n.h
deleted file mode 100644
index 50f36ea..000
--- a/libq/i18n.h
+++ /dev/null
@@ -1,17 +0,0 @@
-#ifndef _I18N_H
-#define _I18N_H
-
-#if ENABLE_NLS
-# include 
-# include 
-# define _(String) gettext (String)
-# define decimal_point localeconv()->decimal_point
-#else
-# define _(String) (String)
-# define setlocale(x,y)
-# define bindtextdomain(x,y)
-# define textdomain(x)
-# define decimal_point "."
-#endif
-
-#endif

diff --git a/main.c b/main.c
index 7225eed..5d7c97d 100644
--- a/main.c
+++ b/main.c
@@ -1,5 +1,5 @@
 /*
- * Copyright 2005-2023 Gentoo Foundation
+ * Copyright 2005-2024 Gentoo Foundation
  * Distributed under the terms of the GNU General Public License v2
  *
  * Copyright 2005-2008 Ned Ludd- 
@@ -106,13 +106,13 @@ usage(int status, const char *flags, struct option const 
opts[],
fprintf(fp, " %s%9s%s %s%-16s%s%s:%s %s\n",
YELLOW, applets[i].name, NORM,
DKBLUE, applets[i].opts, NORM,
-   RED, NORM, _(applets[i].desc));
+   RED, NORM, applets[i].desc);
} else if (blabber > 0) {
fprintf(fp, "%susage:%s %s%s%s [opts] %s%s%s %s:%s %s\n",
GREEN, NORM,
YELLOW, applets[blabber].name, NORM,
DKBLUE, applets[blabber].opts, NORM,
-   RED, NORM, _(applets[blabber].desc));
+   RED, NORM, applets[blabber].desc);
if (desc)
fprintf(fp, "\n%s\n", desc);
}
@@ -154,10 +154,10 @@ usage(int status, const char *flags, struct option const 
opts[],
/* then wrap the help text, if necessary */
prefixlen = 6 + 2 + optlen + 1 + 1 + 1;
if ((size_t)twidth < prefixlen + 10) {
-   fprintf(fp, "%s\n", _(help[i]));
+   fprintf(fp, "%s\n", help[i]);
} else {
const char *t;
-   hstr = _(help[i]);
+   hstr = help[i];
l = strlen(hstr);
while (twidth - prefixlen < l) {
/* search backwards for a space */
@@ -1240,10 +1240,6 @@ int main(int argc, char **argv)
IF_DEBUG(init_coredumps());
argv0 = argv[0];
 
-   setlocale(LC_ALL, "");
-   bindtextdomain(argv0, CONFIG_EPREFIX "usr/share/locale");
-   textdomain(argv0);
-
/* note: setting nocolor here is pointless, since
 * initialize_portage_env is going to re-init nocolor, so make
 * sure we modify the default instead. */

diff --git a/main.h b/main.h
index a1b2afc..c3139b0 100644
--- a/main.h
+++ b/main.h
@@ -1,5 +1,5 @@
 /*
- * Copyright 2005-2021 Gentoo Foundation
+ * Copyright 2005-2024 Gentoo Foundation
  * Distributed under the terms of the GNU General Public License v2
  *
  * Copyright 2005-2010 Ned Ludd- 
@@ -23,7 +23,6 @@
 #include 
 
 #include "colors.h"
-#include "i18n.h"
 #include "set.h"
 
 extern const char *argv0;
@@ -87,8 +86,8 @@ extern const char *argv0;
 #define likely(x) __builtin_expect((x), 1)
 #define unlikely(x) __builtin_expect((x), 0)
 
-#define qfprintf(stream, fmt, args...) do { if (!quiet) fprintf(stream, _( fmt 
), ## args); } while (0)
-#define qprintf(fmt, args...) qfprintf(stdout, _( fmt ), ## args)
+#define qfprintf(stream, fmt, args...) do { if (!quiet) fprintf(stream, fmt, 
## args); } while (0)
+#define qprintf(fmt, args...) qfprintf(stdout, fmt, ## args)
 
 #define _q_unused_ __attribute__((__unused__))
 
@@ -125,7 +124,7 @@ extern FILE *warnout;
 #define warn(fmt, args...)
 #else
 #define warn(fmt, args...) \
-   fprintf(warnout, _("%s%s%s: " fmt "\n"), RED, argv0, NORM , ## args)
+   fprintf(warnout, "%s%s%s: " fmt "\n", RED, argv0, NORM , ## args)
 #endif
 #define warnf(fmt, args...) warn("%s%s()%s: " fmt, YELLOW, __func__, NORM , ## 
args)
 #define warnl(fmt, args...) warn("%s%i()%s: " fmt, YELLOW, __LINE__, NORM , ## 
args)

diff --git a/qcheck.c b/qcheck.c
index 7c1fd0e..b6d5671 100644
--- a/qcheck.c
+++ b/qcheck.c
@@ -55,7 +55,7 

[gentoo-commits] proj/portage-utils:master commit in: libq/

2024-04-08 Thread Fabian Groffen
commit: 9594126239e0d21b88c3b8c535b6635b4a8b8892
Author: Boris Staletic  protonmail  com>
AuthorDate: Fri Mar 29 17:30:05 2024 +
Commit: Fabian Groffen  gentoo  org>
CommitDate: Mon Apr  8 19:26:59 2024 +
URL:https://gitweb.gentoo.org/proj/portage-utils.git/commit/?id=95941262

libq/xarray: Handle NULL arrays in xarraysort()

Some invocations of `q` may try to call `xarraysort(NULL, 0)`.
One example is `qlop -a foo` where `foo` was never unmerged.

Instead of requiring every call of `xarraysort()` to take care of `NULL`
arguments, `xarraysort()` now exits early if `arr->eles == NULL`.

Closes: https://github.com/gentoo/portage-utils/pull/28
Signed-off-by: Boris Staletic  protonmail.com>
Signed-off-by: Fabian Groffen  gentoo.org>

 libq/xarray.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/libq/xarray.c b/libq/xarray.c
index 49b478b..3251a12 100644
--- a/libq/xarray.c
+++ b/libq/xarray.c
@@ -1,5 +1,5 @@
 /*
- * Copyright 2003-2019 Gentoo Foundation
+ * Copyright 2003-2024 Gentoo Foundation
  * Distributed under the terms of the GNU General Public License v2
  *
  * Copyright 2003-2007 Ned Ludd- 
@@ -46,7 +46,8 @@ void *xarraypush(array_t *arr, const void *ele, size_t 
ele_len)
 
 void xarraysort(array_t *arr, int (*compar)(const void *, const void *))
 {
-   qsort(arr->eles, arr->num, sizeof(void *), compar);
+   if (arr->num > 1)
+   qsort(arr->eles, arr->num, sizeof(void *), compar);
 }
 
 void xarraydelete_ptr(array_t *arr, size_t elem)



[gentoo-commits] proj/portage-utils:master commit in: libq/, /

2024-03-29 Thread Fabian Groffen
commit: 268c2076b5276fbce37df3f751619646c4b8d7a4
Author: Boris Staletic  protonmail  com>
AuthorDate: Thu Mar 28 18:08:00 2024 +
Commit: Fabian Groffen  gentoo  org>
CommitDate: Fri Mar 29 10:57:17 2024 +
URL:https://gitweb.gentoo.org/proj/portage-utils.git/commit/?id=268c2076

qlop: Properly handle atom_compar_cb when called from qsort

`qsort` passes pointers to elements ("iterators" in C++ lingo) to the
callback, not elements directly.
Hence `l` and `r` in `atom_compar_cb` actually receives `depend_atom**`,
but only when called from `qsort`. The other two call sites
(`tree_pkg_compar` and `pkg_sort_cb`) actually apssed `depend_atom*`.

This leads to type casting confusion and undefined behaviour for any
invocation of `qlop -p`.

First discovered by SEGFAULT-ing with the following invocation:

qlop -p `cat /var/lib/portage/world`

Valgrind and ASAN made triggering the SEGFAULT easier - any invocation
with two or more atoms triggered a NULL dereference.

This commit addresses the above problem:

1. Expect that `atom_compar_cb` is actually called with two
   `depend_atom**`.
2. Make `tree_pkg_compar` and `pkg_sort_cb` comply with the above
   change, by passing  `` and ``, instead of `al` and `ar`.

Signed-off-by: Fabian Groffen  gentoo.org>

 libq/atom.c | 4 ++--
 libq/tree.c | 2 +-
 qlop.c  | 2 +-
 3 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/libq/atom.c b/libq/atom.c
index b1a150a..3cc2100 100644
--- a/libq/atom.c
+++ b/libq/atom.c
@@ -1242,8 +1242,8 @@ atom_format(const char *format, const depend_atom *atom)
 inline int
 atom_compar_cb(const void *l, const void *r)
 {
-   const depend_atom *al = l;
-   const depend_atom *ar = r;
+   const depend_atom *al = *(const depend_atom**)l;
+   const depend_atom *ar = *(const depend_atom**)r;
 
switch (atom_compare(al, ar)) {
case EQUAL:  return  0;

diff --git a/libq/tree.c b/libq/tree.c
index 4678634..335ac79 100644
--- a/libq/tree.c
+++ b/libq/tree.c
@@ -463,7 +463,7 @@ tree_pkg_compar(const void *l, const void *r)
depend_atom *al = tree_get_atom(pl, false);
depend_atom *ar = tree_get_atom(pr, false);
 
-   return atom_compar_cb(al, ar);
+   return atom_compar_cb(, );
 }
 
 static tree_pkg_ctx *

diff --git a/qlop.c b/qlop.c
index 3e6db53..cfad246 100644
--- a/qlop.c
+++ b/qlop.c
@@ -309,7 +309,7 @@ pkg_sort_cb(const void *l, const void *r)
depend_atom *al = pl->atom;
depend_atom *ar = pr->atom;
 
-   return atom_compar_cb(al, ar);
+   return atom_compar_cb(, );
 }
 
 /* The format of the sync log has changed over time.



[gentoo-commits] proj/portage-utils:master commit in: libq/

2024-02-01 Thread Fabian Groffen
commit: b4ace2f3443e6746a54eb14c7f50aa719540181c
Author: Fabian Groffen  gentoo  org>
AuthorDate: Thu Feb  1 08:19:01 2024 +
Commit: Fabian Groffen  gentoo  org>
CommitDate: Thu Feb  1 08:19:01 2024 +
URL:https://gitweb.gentoo.org/proj/portage-utils.git/commit/?id=b4ace2f3

libq/contents: fix invalid access problem pointed out by valgrind

len represents the entire string length, but we start scanning after the
line identifier, so substract that size from len, such that we don't
start scanning after the end of the input string.

Signed-off-by: Fabian Groffen  gentoo.org>

 libq/contents.c | 4 
 1 file changed, 4 insertions(+)

diff --git a/libq/contents.c b/libq/contents.c
index feb1c0b..6ec4491 100644
--- a/libq/contents.c
+++ b/libq/contents.c
@@ -34,6 +34,9 @@ contents_parse_line_len(char *line, size_t len)
len--;
}
 
+   if (len <= 4)  /* minimal: "dir /" */
+   return NULL;
+
memset(, 0x00, sizeof(e));
e._data = line;
 
@@ -47,6 +50,7 @@ contents_parse_line_len(char *line, size_t len)
return NULL;
 
e.name = e._data + 4;
+   len   -= 4;
 
switch (e.type) {
/* dir /bin */



[gentoo-commits] proj/portage-utils:master commit in: libq/

2024-02-01 Thread Fabian Groffen
commit: 13b0eecccaeae428c5fcd58b9c7edf9854e154a3
Author: Fabian Groffen  gentoo  org>
AuthorDate: Thu Feb  1 08:20:42 2024 +
Commit: Fabian Groffen  gentoo  org>
CommitDate: Thu Feb  1 08:20:42 2024 +
URL:https://gitweb.gentoo.org/proj/portage-utils.git/commit/?id=13b0eecc

libq/tree: handle hypothetical fail in tree_pkg_meta_get_int

When we cannot read all bytes from a file, return an empty string, not
partial garbage.

Signed-off-by: Fabian Groffen  gentoo.org>

 libq/tree.c | 6 ++
 1 file changed, 6 insertions(+)

diff --git a/libq/tree.c b/libq/tree.c
index 15d8267..4678634 100644
--- a/libq/tree.c
+++ b/libq/tree.c
@@ -1233,6 +1233,12 @@ tree_pkg_meta_get_int(tree_pkg_ctx *pkg_ctx, size_t 
offset, const char *keyn)
p[--s.st_size] = '\0';
m->storage->pos += s.st_size + 1;
}
+   else
+   {
+   /* hmmm, couldn't read the whole file?!? */
+   p[0] = '\0';
+   m->storage->pos++;
+   }
close(fd);
}
} else {



[gentoo-commits] proj/portage-utils:master commit in: libq/

2024-01-31 Thread Fabian Groffen
commit: 17e518250d3cabfec9ecc417275a42858b590297
Author: Fabian Groffen  gentoo  org>
AuthorDate: Wed Jan 31 20:39:24 2024 +
Commit: Fabian Groffen  gentoo  org>
CommitDate: Wed Jan 31 20:39:24 2024 +
URL:https://gitweb.gentoo.org/proj/portage-utils.git/commit/?id=17e51825

libq/contents: add variant specifying buffer length

This seems necessary for PR #21, but keep the original code structure
largely in-tact.

Signed-off-by: Fabian Groffen  gentoo.org>

 libq/contents.c | 53 +++--
 libq/contents.h |  5 +++--
 2 files changed, 38 insertions(+), 20 deletions(-)

diff --git a/libq/contents.c b/libq/contents.c
index 7f4351d..feb1c0b 100644
--- a/libq/contents.c
+++ b/libq/contents.c
@@ -1,5 +1,5 @@
 /*
- * Copyright 2005-2020 Gentoo Foundation
+ * Copyright 2005-2024 Gentoo Foundation
  * Distributed under the terms of the GNU General Public License v2
  *
  * Copyright 2005-2008 Ned Ludd- 
@@ -19,18 +19,20 @@
  * Parse a line of CONTENTS file and provide access to the individual fields
  */
 contents_entry *
-contents_parse_line(char *line)
+contents_parse_line_len(char *line, size_t len)
 {
static contents_entry e;
char *p;
 
-   if (line == NULL || *line == '\0' || *line == '\n')
+   if (len == 0 || line == NULL || *line == '\0' || *line == '\n')
return NULL;
 
/* chop trailing newline */
-   p = [strlen(line) - 1];
-   if (*p == '\n')
+   p = [len - 1];
+   if (*p == '\n') {
*p = '\0';
+   len--;
+   }
 
memset(, 0x00, sizeof(e));
e._data = line;
@@ -53,23 +55,38 @@ contents_parse_line(char *line)
 
/* obj /bin/bash 62ed51c8b23866777552643ec57614b0 1120707577 */
case CONTENTS_OBJ:
-   if ((e.mtime_str = strrchr(e.name, ' ')) == NULL)
-   return NULL;
-   *e.mtime_str++ = '\0';
-   if ((e.digest = strrchr(e.name, ' ')) == NULL)
-   return NULL;
-   *e.digest++ = '\0';
+   for (p = [len - 1]; p >= e.name; p--) {
+   if (*p == ' ') {
+   if (e.mtime_str == NULL)
+   e.mtime_str = p + 1;
+   else if (e.digest == NULL)
+   e.digest = p + 1;
+   *p = '\0';
+
+   if (e.digest != NULL)
+   break;
+   }
+   }
break;
 
/* sym /bin/sh -> bash 1120707577 */
case CONTENTS_SYM:
-   if ((e.mtime_str = strrchr(e.name, ' ')) == NULL)
-   return NULL;
-   *e.mtime_str++ = '\0';
-   if ((e.sym_target = strstr(e.name, " -> ")) == NULL)
-   return NULL;
-   *e.sym_target = '\0';
-   e.sym_target += 4;
+   for (p = [len - 1]; p >= e.name; p--) {
+   if (*p == ' ') {
+   if (e.mtime_str == NULL) {
+   e.mtime_str = p + 1;
+   } else if (e.sym_target == NULL) {
+   if (strncmp(p, " -> ", sizeof(" 
-> ") - 1) == 0)
+   e.sym_target = p + 
sizeof(" -> ") - 1;
+   else
+   continue;
+   }
+   *p = '\0';
+
+   if (e.sym_target != NULL)
+   break;
+   }
+   }
break;
}
 

diff --git a/libq/contents.h b/libq/contents.h
index c766827..a0a5a63 100644
--- a/libq/contents.h
+++ b/libq/contents.h
@@ -1,5 +1,5 @@
 /*
- * Copyright 2005-2019 Gentoo Foundation
+ * Copyright 2005-2024 Gentoo Foundation
  * Distributed under the terms of the GNU General Public License v2
  *
  * Copyright 2005-2008 Ned Ludd- 
@@ -24,6 +24,7 @@ typedef struct {
long mtime;
 } contents_entry;
 
-contents_entry *contents_parse_line(char *line);
+contents_entry *contents_parse_line_len(char *line, size_t len);
+#define contents_parse_line(L) contents_parse_line_len(L, strlen(L))
 
 #endif



[gentoo-commits] proj/portage-utils:master commit in: libq/

2024-01-31 Thread Fabian Groffen
commit: 014a97249e20e77f3e0ba5b9def194682ef8ecbd
Author: Fabian Groffen  gentoo  org>
AuthorDate: Wed Jan 31 19:30:24 2024 +
Commit: Fabian Groffen  gentoo  org>
CommitDate: Wed Jan 31 19:30:24 2024 +
URL:https://gitweb.gentoo.org/proj/portage-utils.git/commit/?id=014a9724

libq/hash.h: update copyright for previous commit

Signed-off-by: Fabian Groffen  gentoo.org>

 libq/hash.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libq/hash.h b/libq/hash.h
index ffbd2ef..bc72e52 100644
--- a/libq/hash.h
+++ b/libq/hash.h
@@ -1,5 +1,5 @@
 /*
- * Copyright 2018-2020 Gentoo Foundation
+ * Copyright 2018-2024 Gentoo Foundation
  * Distributed under the terms of the GNU General Public License v2
  *
  * Copyright 2018- Fabian Groffen  - 



[gentoo-commits] proj/portage-utils:master commit in: libq/

2024-01-31 Thread Fabian Groffen
commit: bc4321f30bb95ab1c2112f045a4cde811045ed59
Author: Fabian Groffen  gentoo  org>
AuthorDate: Wed Jan 31 19:24:41 2024 +
Commit: Fabian Groffen  gentoo  org>
CommitDate: Wed Jan 31 19:24:41 2024 +
URL:https://gitweb.gentoo.org/proj/portage-utils.git/commit/?id=bc4321f3

libq/hash: add hash_string function

Alternative to the implementation in PR #21, so as to reuse the same
hashing code.

We could add the interface to compute multiple hashes from the same
string when that's actually necessary.

Signed-off-by: Fabian Groffen  gentoo.org>

 libq/hash.c | 137 +---
 libq/hash.h |   1 +
 2 files changed, 114 insertions(+), 24 deletions(-)

diff --git a/libq/hash.c b/libq/hash.c
index 9b36bb9..f3a440f 100644
--- a/libq/hash.c
+++ b/libq/hash.c
@@ -98,29 +98,54 @@ hash_hex(char *out, const unsigned char *buf, const int 
length)
}
 }
 
-/**
- * Computes the hashes for file fname and writes the hex-representation
- * for those hashes into the address space pointed to by the return
- * pointers for these hashes.  The caller should ensure enough space is
- * available.  Only those hashes which are in the global hashes variable
- * are computed, the address space pointed to for non-used hashes are
- * left untouched, e.g. they can be NULL.  The number of bytes read from
- * the file pointed to by fname is returned in the flen argument.
- */
-int
-hash_multiple_file_fd(
-   int fd,
-   char *md5,
-   char *sha1,
-   char *sha256,
-   char *sha512,
-   char *blak2b,
+/* len func(dest,destlen,cbctx) */
+typedef size_t (*read_cb)(char *,size_t,void *);
+
+static size_t read_stdio(char *dest, size_t destlen, void *ctx)
+{
+   FILE *io = ctx;
+
+   return fread(dest, 1, destlen, io);
+}
+
+struct bufctx {
+   const char *buf;
+   size_t  buflen;
+};
+
+static size_t read_buffer(char *dest, size_t destlen, void *ctx)
+{
+   struct bufctx *membuf = ctx;
+   size_t readlen;
+
+   readlen = destlen;
+   if (readlen > membuf->buflen)
+   readlen = membuf->buflen;
+
+   memcpy(dest, membuf->buf, readlen);
+
+   /* update buffer to the remainder */
+   membuf->buf+= readlen;
+   membuf->buflen -= readlen;
+
+   return readlen;
+}
+
+static int
+hash_multiple_internal(
+   read_cb rcb,
+   void   *ctx,
+   char   *md5,
+   char   *sha1,
+   char   *sha256,
+   char   *sha512,
+   char   *blak2b,
size_t *flen,
-   int hashes)
+   int hashes)
 {
-   FILE *f;
-   char  data[8192];
size_tlen;
+   char  data[8192];
+
struct md5_ctxm5;
struct sha1_ctx   s1;
struct sha256_ctx s256;
@@ -132,8 +157,6 @@ hash_multiple_file_fd(
 #endif
 
*flen = 0;
-   if ((f = fdopen(fd, "r")) == NULL)
-   return -1;
 
md5_init_ctx();
sha1_init_ctx();
@@ -143,7 +166,7 @@ hash_multiple_file_fd(
blake2b_init(, BLAKE2B_OUTBYTES);
 #endif
 
-   while ((len = fread(data, 1, sizeof(data), f)) > 0) {
+   while ((len = rcb(data, sizeof(data), ctx)) > 0) {
*flen += len;
 #pragma omp parallel sections
{
@@ -176,7 +199,6 @@ hash_multiple_file_fd(
 #endif
}
}
-   fclose(f);
 
 #pragma omp parallel sections
{
@@ -227,6 +249,41 @@ hash_multiple_file_fd(
return 0;
 }
 
+/**
+ * Computes the hashes for file fname and writes the hex-representation
+ * for those hashes into the address space pointed to by the return
+ * pointers for these hashes.  The caller should ensure enough space is
+ * available.  Only those hashes which are in the global hashes variable
+ * are computed, the address space pointed to for non-used hashes are
+ * left untouched, e.g. they can be NULL.  The number of bytes read from
+ * the file pointed to by fname is returned in the flen argument.
+ */
+int
+hash_multiple_file_fd(
+   int fd,
+   char *md5,
+   char *sha1,
+   char *sha256,
+   char *sha512,
+   char *blak2b,
+   size_t *flen,
+   int hashes)
+{
+   FILE *f;
+   int   ret;
+
+   if ((f = fdopen(fd, "r")) == NULL)
+   return -1;
+
+   ret = hash_multiple_internal(read_stdio, f,
+md5, sha1, 
sha256, sha512, blak2b,
+flen, hashes);
+
+   fclose(f);
+
+   return ret;
+}
+
 int
 hash_multiple_file_at_cb(
int pfd,
@@ -285,3 +342,35 @@ hash_file_at_cb(int pfd, const char *fname, int hash, 
hash_cb_t cb)
 
return 

[gentoo-commits] proj/portage-utils:master commit in: libq/

2024-01-27 Thread Fabian Groffen
commit: e05b6baf296397bc2a10dad728f2840ab242b833
Author: Pavel Kalugin  pavelthebest  me>
AuthorDate: Tue Dec 12 19:32:35 2023 +
Commit: Fabian Groffen  gentoo  org>
CommitDate: Sat Jan 27 13:27:30 2024 +
URL:https://gitweb.gentoo.org/proj/portage-utils.git/commit/?id=e05b6baf

libq/atom: fix atom comparison bug

qlop SEGFAULTed when predict on a package without category was called

Closes: https://github.com/gentoo/portage-utils/pull/24
Signed-off-by: Pavel Kalugin  pavelthebest.me>
Signed-off-by: Fabian Groffen  gentoo.org>

 libq/atom.c | 10 +-
 1 file changed, 9 insertions(+), 1 deletion(-)

diff --git a/libq/atom.c b/libq/atom.c
index 31299f1..b1a150a 100644
--- a/libq/atom.c
+++ b/libq/atom.c
@@ -1252,7 +1252,15 @@ atom_compar_cb(const void *l, const void *r)
default:
{
int ret;
-   ret = strcmp(al->CATEGORY, ar->CATEGORY);
+   if (!al->CATEGORY && !ar->CATEGORY) {
+   ret = 0;
+   } else if (!al->CATEGORY) {
+   ret = -1;
+   } else if (!ar->CATEGORY) {
+   ret = 1;
+   } else {
+   ret = strcmp(al->CATEGORY, ar->CATEGORY);
+   }
if (ret == 0)
ret = strcasecmp(al->PN, ar->PN);
return ret;



[gentoo-commits] proj/portage-utils:master commit in: /, libq/

2024-01-01 Thread Fabian Groffen
commit: 5b790bbd7eb6e02702e422d9bdcb640b10a3e447
Author: Fabian Groffen  gentoo  org>
AuthorDate: Tue Jan  2 07:50:51 2024 +
Commit: Fabian Groffen  gentoo  org>
CommitDate: Tue Jan  2 07:50:51 2024 +
URL:https://gitweb.gentoo.org/proj/portage-utils.git/commit/?id=5b790bbd

libq/hash: switch from OpenSSL/custom to gnulib-based hash impls

OpenSSL deprecated most (if not all) of the hashes we use from it, and
we don't have our own implementations for e.g. SHA512, so switch to
gnulib's versions, which makes this all simpler.

Signed-off-by: Fabian Groffen  gentoo.org>

 autogen.sh   |   4 +
 libq/Makefile.am |   6 -
 libq/hash.c  | 123 +++-
 libq/hash_md5_sha1.c | 770 ---
 libq/hash_md5_sha1.h |  35 ---
 5 files changed, 41 insertions(+), 897 deletions(-)

diff --git a/autogen.sh b/autogen.sh
index df6e574..dc41d69 100755
--- a/autogen.sh
+++ b/autogen.sh
@@ -28,6 +28,10 @@ done
 # reload the gnulib code
 PATH=/usr/local/src/gnu/gnulib:${PATH}
 mods="
+   crypto/md5-buffer
+   crypto/sha1-buffer
+   crypto/sha256-buffer
+   crypto/sha512-buffer
dirent
faccessat
fdopendir

diff --git a/libq/Makefile.am b/libq/Makefile.am
index 879d4a7..e65bb47 100644
--- a/libq/Makefile.am
+++ b/libq/Makefile.am
@@ -28,12 +28,6 @@ QFILES = \
xsystem.c xsystem.h \
$(NULL)
 
-if !QMANIFEST_ENABLED
-if !QTEGRITY_ENABLED
-QFILES += hash_md5_sha1.c hash_md5_sha1.h
-endif
-endif
-
 noinst_LIBRARIES = libq.a
 libq_a_SOURCES = $(QFILES)
 libq_a_CPPFLAGS = \

diff --git a/libq/hash.c b/libq/hash.c
index 4a1202a..9b36bb9 100644
--- a/libq/hash.c
+++ b/libq/hash.c
@@ -12,24 +12,22 @@
 
 #include "main.h"
 
-#ifdef HAVE_SSL
-# include 
-# include 
-#else
-# include "hash_md5_sha1.h"
-#endif
 #ifdef HAVE_BLAKE2B
 # include 
 #endif
 
+#include "md5.h"
+#include "sha1.h"
+#include "sha256.h"
+#include "sha512.h"
+
 #include "hash.h"
 
 void
 hash_hex(char *out, const unsigned char *buf, const int length)
 {
switch (length) {
-   /* MD5_DIGEST_LENGTH */
-   case 16:
+   case 16: /* MD5_DIGEST_SIZE */
snprintf(out, 32 + 1,

"%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x"
"%02x%02x%02x%02x%02x%02x",
@@ -39,8 +37,7 @@ hash_hex(char *out, const unsigned char *buf, const int 
length)
buf[15]
);
break;
-   /* SHA1_DIGEST_LENGTH */
-   case 20:
+   case 20: /* SHA1_DIGEST_SIZE */
snprintf(out, 40 + 1,

"%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x"

"%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x",
@@ -50,8 +47,7 @@ hash_hex(char *out, const unsigned char *buf, const int 
length)
buf[15], buf[16], buf[17], buf[18], 
buf[19]
);
break;
-   /* SHA256_DIGEST_LENGTH */
-   case 32:
+   case 32: /* SHA256_DIGEST_SIZE */
snprintf(out, 64 + 1,

"%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x"

"%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x"
@@ -66,8 +62,7 @@ hash_hex(char *out, const unsigned char *buf, const int 
length)
buf[30], buf[31]
);
break;
-   /* SHA512_DIGEST_LENGTH, WHIRLPOOL_DIGEST_LENGTH, 
BLAKE2B_OUTBYTES */
-   case 64:
+   case 64: /* SHA512_DIGEST_SIZE, BLAKE2B_OUTBYTES */
snprintf(out, 128 + 1,

"%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x"

"%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x"
@@ -123,22 +118,15 @@ hash_multiple_file_fd(
size_t *flen,
int hashes)
 {
-   FILE *f;
-   char data[8192];
-   size_t len;
-#ifdef HAVE_SSL
-   MD5_CTX m5;
-   SHA_CTX s1;
-   SHA256_CTX s256;
-   SHA512_CTX s512;
-#else
-   struct md5_ctx_t m5;
-   struct sha1_ctx_t s1;
-   (void)sha256;
-   (void)sha512;
-#endif
+   FILE *f;
+   char  data[8192];
+   size_tlen;
+   struct md5_ctxm5;
+   struct sha1_ctx   s1;
+   struct sha256_ctx s256;
+   struct sha512_ctx s512;
 #ifdef HAVE_BLAKE2B
-   blake2b_state bl2b;
+   blake2b_state bl2b;
 #else
(void)blak2b;
 #endif
@@ -147,15 +135,10 @@ hash_multiple_file_fd(
if ((f = fdopen(fd, "r")) == NULL)
return -1;
 
-#ifdef HAVE_SSL
-   

[gentoo-commits] proj/portage-utils:master commit in: libq/, /

2024-01-01 Thread Fabian Groffen
commit: 92920dd0b9efed3e7467b4b18b68df86f9eee9d8
Author: Fabian Groffen  gentoo  org>
AuthorDate: Mon Jan  1 13:17:56 2024 +
Commit: Fabian Groffen  gentoo  org>
CommitDate: Mon Jan  1 13:17:56 2024 +
URL:https://gitweb.gentoo.org/proj/portage-utils.git/commit/?id=92920dd0

*: remove WHIRLPOOL hash support

WHIRLPOOL has not been in use since mid 2017, and its support is bound
to be removed from OpenSSL.

Signed-off-by: Fabian Groffen  gentoo.org>

 libq/hash.c | 26 +++---
 libq/hash.h | 14 +++---
 libq/tree.c |  2 +-
 qcheck.c|  2 +-
 qmanifest.c | 31 +--
 qmerge.c|  4 ++--
 qpkg.c  |  2 +-
 qtegrity.c  |  4 ++--
 8 files changed, 26 insertions(+), 59 deletions(-)

diff --git a/libq/hash.c b/libq/hash.c
index b5aec46..4a1202a 100644
--- a/libq/hash.c
+++ b/libq/hash.c
@@ -1,5 +1,5 @@
 /*
- * Copyright 2018-2020 Gentoo Foundation
+ * Copyright 2018-2024 Gentoo Foundation
  * Distributed under the terms of the GNU General Public License v2
  *
  * Copyright 2018- Fabian Groffen  - 
@@ -15,7 +15,6 @@
 #ifdef HAVE_SSL
 # include 
 # include 
-# include 
 #else
 # include "hash_md5_sha1.h"
 #endif
@@ -120,7 +119,6 @@ hash_multiple_file_fd(
char *sha1,
char *sha256,
char *sha512,
-   char *whrlpl,
char *blak2b,
size_t *flen,
int hashes)
@@ -133,13 +131,11 @@ hash_multiple_file_fd(
SHA_CTX s1;
SHA256_CTX s256;
SHA512_CTX s512;
-   WHIRLPOOL_CTX whrl;
 #else
struct md5_ctx_t m5;
struct sha1_ctx_t s1;
(void)sha256;
(void)sha512;
-   (void)whrlpl;
 #endif
 #ifdef HAVE_BLAKE2B
blake2b_state bl2b;
@@ -156,7 +152,6 @@ hash_multiple_file_fd(
SHA1_Init();
SHA256_Init();
SHA512_Init();
-   WHIRLPOOL_Init();
 #else
md5_begin();
sha1_begin();
@@ -190,11 +185,6 @@ hash_multiple_file_fd(
if (hashes & HASH_SHA512)
SHA512_Update(, data, len);
}
-#pragma omp section
-   {
-   if (hashes & HASH_WHIRLPOOL)
-   WHIRLPOOL_Update(, data, len);
-   }
 #else
 #pragma omp section
{
@@ -253,14 +243,6 @@ hash_multiple_file_fd(
hash_hex(sha512, sha512buf, 
SHA512_DIGEST_LENGTH);
}
}
-#pragma omp section
-   {
-   if (hashes & HASH_WHIRLPOOL) {
-   unsigned char 
whrlplbuf[WHIRLPOOL_DIGEST_LENGTH];
-   WHIRLPOOL_Final(whrlplbuf, );
-   hash_hex(whrlpl, whrlplbuf, 
WHIRLPOOL_DIGEST_LENGTH);
-   }
-   }
 #else
 #pragma omp section
{
@@ -303,7 +285,6 @@ hash_multiple_file_at_cb(
char *sha1,
char *sha256,
char *sha512,
-   char *whrlpl,
char *blak2b,
size_t *flen,
int hashes)
@@ -321,7 +302,7 @@ hash_multiple_file_at_cb(
}
 
ret = hash_multiple_file_fd(fd, md5, sha1, sha256, sha512,
-   whrlpl, blak2b, flen, hashes);
+   blak2b, flen, hashes);
 
if (ret != 0)
close(fd);
@@ -340,11 +321,10 @@ hash_file_at_cb(int pfd, const char *fname, int hash, 
hash_cb_t cb)
case HASH_SHA1:
case HASH_SHA256:
case HASH_SHA512:
-   case HASH_WHIRLPOOL:
case HASH_BLAKE2B:
if (hash_multiple_file_at_cb(pfd, fname, cb,
_hash_file_buf, _hash_file_buf, 
_hash_file_buf,
-   _hash_file_buf, _hash_file_buf, 
_hash_file_buf,
+   _hash_file_buf, _hash_file_buf,
, hash) != 0)
return NULL;
break;

diff --git a/libq/hash.h b/libq/hash.h
index f85080d..fb4ab5f 100644
--- a/libq/hash.h
+++ b/libq/hash.h
@@ -18,7 +18,7 @@ enum hash_impls {
HASH_SHA1  = 1<<1,
HASH_SHA256= 1<<2,
HASH_SHA512= 1<<3,
-   HASH_WHIRLPOOL = 1<<4,
+   HASH_WHIRLPOOL = 1<<4,  /* removed */
HASH_BLAKE2B   = 1<<5
 };
 
@@ -32,15 +32,15 @@ typedef int (*hash_cb_t) (int, const char *);
 void hash_hex(char *out, const unsigned char *buf, const int length);
 int hash_multiple_file_fd(
int fd, char *md5, char *sha1, char *sha256, char *sha512,
-   char *whrlpl, char *blak2b, size_t *flen, int hashes);
+   char *blak2b, size_t *flen, int hashes);
 int 

[gentoo-commits] proj/portage-utils:master commit in: libq/

2023-04-21 Thread Fabian Groffen
commit: e322a78cbfd6d51aefe26425dff1cb99c3d307bc
Author: Fabian Groffen  gentoo  org>
AuthorDate: Fri Apr 21 19:09:05 2023 +
Commit: Fabian Groffen  gentoo  org>
CommitDate: Fri Apr 21 19:09:05 2023 +
URL:https://gitweb.gentoo.org/proj/portage-utils.git/commit/?id=e322a78c

libq/tree: add commetns on file checks (research for bug #898194)

Signed-off-by: Fabian Groffen  gentoo.org>

 libq/tree.c | 9 +
 1 file changed, 9 insertions(+)

diff --git a/libq/tree.c b/libq/tree.c
index f308c8d..1922b7d 100644
--- a/libq/tree.c
+++ b/libq/tree.c
@@ -1109,8 +1109,17 @@ tree_pkg_read(tree_pkg_ctx *pkg_ctx)
 
if (ctx->cachetype == CACHE_METADATA_MD5) {
ret = tree_read_file_md5(pkg_ctx);
+   /* md5-cache, is sort of documented in egencache man-page
+* key-points are that an md5 is provided for the ebuild itself,
+* and if it includes eclasses, the md5s for each eclass.  These
+* are available as _md5_ and _eclasses_ keys.  The latter uses
+* tab-separation of form \t\t... */
} else if (ctx->cachetype == CACHE_METADATA_PMS) {
ret = tree_read_file_pms(pkg_ctx);
+   /* PMS implies to do an mtime and existence check (the cache may
+* contain extra stuff) but since this form of metadata in fact
+* is extinct, because these checks are insufficient and
+* impossible on e.g. a git-based tree. */
} else if (ctx->cachetype == CACHE_EBUILD) {
ret = tree_read_file_ebuild(pkg_ctx);
} else if (ctx->cachetype == CACHE_BINPKGS) {



[gentoo-commits] proj/portage-utils:master commit in: libq/, /

2023-02-07 Thread Fabian Groffen
commit: 067af6b9098858e786e71ef20cb91ad75c6e4ba4
Author: Fabian Groffen  gentoo  org>
AuthorDate: Tue Feb  7 08:24:21 2023 +
Commit: Fabian Groffen  gentoo  org>
CommitDate: Tue Feb  7 08:24:21 2023 +
URL:https://gitweb.gentoo.org/proj/portage-utils.git/commit/?id=067af6b9

set: try to silence Coverity

Now add_set_value can allocate a new set, Coverity thinks this will
actually happen, despite in these cases the input set not being NULL.
Help Coverity by adding a redundant if.

Signed-off-by: Fabian Groffen  gentoo.org>

 libq/tree.c |  3 ++-
 main.c  | 12 +---
 2 files changed, 11 insertions(+), 4 deletions(-)

diff --git a/libq/tree.c b/libq/tree.c
index a05a86e..f308c8d 100644
--- a/libq/tree.c
+++ b/libq/tree.c
@@ -1709,7 +1709,8 @@ tree_match_atom_cache_populate_cb(tree_pkg_ctx *ctx, void 
*priv)
cat_ctx = get_set(atom->CATEGORY, cache);
if (cat_ctx == NULL) {
cat_ctx = tree_open_cat(tctx, ".");
-   cache = add_set_value(atom->CATEGORY, cat_ctx, NULL, cache);
+   if (cache != NULL)  /* for static code analysers */
+   add_set_value(atom->CATEGORY, cat_ctx, NULL, cache);
/* get a pointer from the set */
cat_ctx->name = contains_set(atom->CATEGORY, cache);
}

diff --git a/main.c b/main.c
index c5b27fe..884d6da 100644
--- a/main.c
+++ b/main.c
@@ -585,9 +585,15 @@ read_portage_file(const char *file, enum portage_file_type 
type, void *data)
snprintf(npath, sizeof(npath), "%s:%zu:%zu-%zu",
file, line, cbeg, cend);
p = xstrdup(npath);
-   masks = add_set_value(buf, p, , masks);
-   if (e != NULL)
-   free(p);
+   /* if not necessary, but do it for static code 
analysers
+* which take into accound that add_set_value 
might
+* allocate a new set when masks would be NULL 
-- a case
+* which would never happen */
+   if (masks != NULL) {
+   add_set_value(buf, p, , masks);
+   if (e != NULL)
+   free(p);
+   }
}
}
}



[gentoo-commits] proj/portage-utils:master commit in: libq/, /

2023-02-07 Thread Fabian Groffen
commit: e2ebb44db31d4e0e9bfc0a9974d36eff63c8b2b1
Author: Fabian Groffen  gentoo  org>
AuthorDate: Tue Feb  7 08:08:13 2023 +
Commit: Fabian Groffen  gentoo  org>
CommitDate: Tue Feb  7 08:08:13 2023 +
URL:https://gitweb.gentoo.org/proj/portage-utils.git/commit/?id=e2ebb44d

set: ensure NULL is empty behaviour is retained throughout

Not all set functions respected NULL is empty behaviour, changed
add_set_value signature to return a set instead so it can conform.

Bug: https://bugs.gentoo.org/893424
Signed-off-by: Fabian Groffen  gentoo.org>

 libq/set.c  | 47 +++
 libq/set.h  |  4 ++--
 libq/tree.c |  5 +++--
 main.c  |  6 --
 qkeyword.c  |  6 +++---
 qlop.c  | 12 
 6 files changed, 59 insertions(+), 21 deletions(-)

diff --git a/libq/set.c b/libq/set.c
index 6c9fae0..fa485c7 100644
--- a/libq/set.c
+++ b/libq/set.c
@@ -1,5 +1,5 @@
 /*
- * Copyright 2005-2019 Gentoo Foundation
+ * Copyright 2005-2023 Gentoo Foundation
  * Distributed under the terms of the GNU General Public License v2
  *
  * Copyright 2005-2010 Ned Ludd- 
@@ -112,17 +112,22 @@ add_set_unique(const char *name, set *q, bool *unique)
 
 /* add ptr to set with name as key, return existing value when key
  * already exists or NULL otherwise */
-void *
-add_set_value(const char *name, void *ptr, set *q)
+set *
+add_set_value(const char *name, void *ptr, void **prevptr, set *q)
 {
unsigned int hash;
int pos;
set_elem *ll;
set_elem *w;
 
+   if (q == NULL)
+   q = create_set();
+
hash = fnv1a32(name);
pos = hash % _SET_HASH_SIZE;
 
+   if (prevptr != NULL)
+   *prevptr = NULL;
if (q->buckets[pos] == NULL) {
q->buckets[pos] = ll = xmalloc(sizeof(*ll));
ll->next = NULL;
@@ -132,8 +137,11 @@ add_set_value(const char *name, void *ptr, set *q)
} else {
ll = NULL;
for (w = q->buckets[pos]; w != NULL; ll = w, w = w->next) {
-   if (w->hash == hash && strcmp(w->name, name) == 0)
-   return w->val;
+   if (w->hash == hash && strcmp(w->name, name) == 0) {
+   if (prevptr != NULL)
+   *prevptr = w->val;
+   return q;
+   }
}
if (w == NULL) {
ll = ll->next = xmalloc(sizeof(*ll));
@@ -145,7 +153,7 @@ add_set_value(const char *name, void *ptr, set *q)
}
 
q->len++;
-   return NULL;
+   return q;
 }
 
 /* returns whether name is in set, and if so, the set-internal key
@@ -158,6 +166,9 @@ contains_set(const char *name, set *q)
set_elem *w;
const char *found;
 
+   if (q == NULL)
+   return NULL;
+
hash = fnv1a32(name);
pos = hash % _SET_HASH_SIZE;
 
@@ -183,6 +194,9 @@ get_set(const char *name, set *q)
int pos;
set_elem *w;
 
+   if (q == NULL)
+   return NULL;
+
hash = fnv1a32(name);
pos = hash % _SET_HASH_SIZE;
 
@@ -211,6 +225,12 @@ del_set(const char *s, set *q, bool *removed)
void *ret;
bool rmd;
 
+   if (q == NULL) {
+   if (removed != NULL)
+   *removed = false;
+   return NULL;
+   }
+
hash = fnv1a32(s);
pos = hash % _SET_HASH_SIZE;
 
@@ -252,8 +272,8 @@ list_set(set *q, char ***l)
set_elem *w;
char **ret;
 
-   ret = *l = xmalloc(sizeof(char *) * (q->len + 1));
-   for (i = 0; i < _SET_HASH_SIZE; i++) {
+   ret = *l = xmalloc(sizeof(char *) * (cnt_set(q) + 1));
+   for (i = 0; q != NULL && i < _SET_HASH_SIZE; i++) {
for (w = q->buckets[i]; w != NULL; w = w->next) {
*ret = w->name;
ret++;
@@ -292,6 +312,11 @@ values_set(set *q, array_t *ret)
array_t blank = array_init_decl;
 
*ret = blank;
+
+   /* allow using empty set */
+   if (q == NULL)
+   return 0;
+
for (i = 0; i < _SET_HASH_SIZE; i++) {
for (w = q->buckets[i]; w != NULL; w = w->next)
xarraypush_ptr(ret, w->val);
@@ -314,6 +339,9 @@ clear_set(set *q)
set_elem *w;
set_elem *e;
 
+   if (q == NULL)
+   return;
+
for (i = 0; i < _SET_HASH_SIZE; i++) {
for (w = q->buckets[i]; w != NULL; w = e) {
e = w->next;
@@ -329,6 +357,9 @@ clear_set(set *q)
 void
 free_set(set *q)
 {
+   if (q == NULL)
+   return;
+
clear_set(q);
free(q);
 }

diff --git a/libq/set.h b/libq/set.h
index 5d53f95..219602e 100644
--- a/libq/set.h
+++ b/libq/set.h
@@ -1,5 +1,5 @@
 /*
- * Copyright 2005-2019 Gentoo Foundation
+ * Copyright 2005-2023 Gentoo 

[gentoo-commits] proj/portage-utils:master commit in: libq/

2023-01-30 Thread Fabian Groffen
commit: 933b7cdbd8e15c6b120aec9cb5bec3ec36a27485
Author: Fabian Groffen  gentoo  org>
AuthorDate: Mon Jan 30 14:08:37 2023 +
Commit: Fabian Groffen  gentoo  org>
CommitDate: Mon Jan 30 14:08:37 2023 +
URL:https://gitweb.gentoo.org/proj/portage-utils.git/commit/?id=933b7cdb

libq/tree: add support IDEPEND

Bug: https://bugs.gentoo.org/892533
Signed-off-by: Fabian Groffen  gentoo.org>

 libq/tree.c | 6 +-
 libq/tree.h | 5 +++--
 2 files changed, 8 insertions(+), 3 deletions(-)

diff --git a/libq/tree.c b/libq/tree.c
index 2a457ce..76190ed 100644
--- a/libq/tree.c
+++ b/libq/tree.c
@@ -1,5 +1,5 @@
 /*
- * Copyright 2005-2022 Gentoo Foundation
+ * Copyright 2005-2023 Gentoo Foundation
  * Distributed under the terms of the GNU General Public License v2
  *
  * Copyright 2005-2008 Ned Ludd- 
@@ -824,6 +824,7 @@ tree_read_file_md5(tree_pkg_ctx *pkg_ctx)
assign_var(DEFINED_PHASES);
assign_var(REQUIRED_USE);
assign_var(BDEPEND);
+   assign_var(IDEPEND);
assign_var(EPREFIX);
assign_var(_eclasses_);
assign_var(_md5_);
@@ -901,6 +902,7 @@ tree_read_file_ebuild(tree_pkg_ctx *pkg_ctx)
match_key(EAPI);
match_key(REQUIRED_USE);
match_key(BDEPEND);
+   match_key(IDEPEND);
 #undef match_key
}
 
@@ -1004,6 +1006,7 @@ tree_read_file_binpkg_xpak_cb(
match_path(DEFINED_PHASES);
match_path(REQUIRED_USE);
match_path(BDEPEND);
+   match_path(IDEPEND);
match_path(CONTENTS);
match_path(USE);
match_path(EPREFIX);
@@ -1513,6 +1516,7 @@ tree_foreach_packages(tree_ctx *ctx, tree_pkg_cb 
callback, void *priv)
match_key2(REPO, repository);
match_key(SIZE);
match_key(BDEPEND);
+   match_key(IDEPEND);
match_key(PATH);
match_key2(BUILD_ID, BUILDID);
 #undef match_key

diff --git a/libq/tree.h b/libq/tree.h
index 2f2c81f..efafe73 100644
--- a/libq/tree.h
+++ b/libq/tree.h
@@ -1,5 +1,5 @@
 /*
- * Copyright 2005-2022 Gentoo Foundation
+ * Copyright 2005-2023 Gentoo Foundation
  * Distributed under the terms of the GNU General Public License v2
  */
 
@@ -96,8 +96,9 @@ struct tree_pkg_meta {
char *Q_PDEPEND;
char *Q_PROVIDE;   /* line 14 */
char *Q_EAPI;
-   char *Q_PROPERTIES;
+   char *Q_PROPERTIES;/* last line from metadata */
char *Q_BDEPEND;
+   char *Q_IDEPEND;
/* binpkgs/vdb */
char *Q_DEFINED_PHASES;
char *Q_REQUIRED_USE;



[gentoo-commits] proj/portage-utils:master commit in: libq/

2022-05-26 Thread Fabian Groffen
commit: 84804b1dfcf6e5f3b7a7cca2212c8b2d5a7e4f4b
Author: Fabian Groffen  gentoo  org>
AuthorDate: Thu May 26 09:30:28 2022 +
Commit: Fabian Groffen  gentoo  org>
CommitDate: Thu May 26 09:30:28 2022 +
URL:https://gitweb.gentoo.org/proj/portage-utils.git/commit/?id=84804b1d

libq/dep: allow resolving multiple times (e.g. for overlays)

Signed-off-by: Fabian Groffen  gentoo.org>

 libq/dep.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libq/dep.c b/libq/dep.c
index 4138a1c..389e506 100644
--- a/libq/dep.c
+++ b/libq/dep.c
@@ -355,7 +355,7 @@ void
 dep_resolve_tree(dep_node *root, tree_ctx *t)
 {
if (root->type != DEP_NULL) {
-   if (root->type == DEP_NORM && root->atom) {
+   if (root->type == DEP_NORM && root->atom && 
!root->atom_resolved) {
depend_atom*d = root->atom;
tree_match_ctx *r = tree_match_atom(t, d,

TREE_MATCH_DEFAULT |



[gentoo-commits] proj/portage-utils:master commit in: libq/

2022-05-26 Thread Fabian Groffen
commit: 8ca9d1625448544f72aa0d45a1cbbdfa8dcfb22e
Author: Fabian Groffen  gentoo  org>
AuthorDate: Thu May 26 09:27:11 2022 +
Commit: Fabian Groffen  gentoo  org>
CommitDate: Thu May 26 09:27:11 2022 +
URL:https://gitweb.gentoo.org/proj/portage-utils.git/commit/?id=8ca9d162

libq/dep: add dep_resolve_tree function

allow resolving a dep-specification to atoms found in a tree, e.g. see
what would get selected

Signed-off-by: Fabian Groffen  gentoo.org>

 libq/dep.c | 77 +++---
 libq/dep.h | 12 ++
 2 files changed, 56 insertions(+), 33 deletions(-)

diff --git a/libq/dep.c b/libq/dep.c
index 99629e7..4138a1c 100644
--- a/libq/dep.c
+++ b/libq/dep.c
@@ -1,5 +1,5 @@
 /*
- * Copyright 2005-2019 Gentoo Foundation
+ * Copyright 2005-2022 Gentoo Foundation
  * Distributed under the terms of the GNU General Public License v2
  *
  * Copyright 2005-2010 Ned Ludd- 
@@ -20,6 +20,7 @@
 #include "atom.h"
 #include "dep.h"
 #include "set.h"
+#include "tree.h"
 #include "xarray.h"
 #include "xasprintf.h"
 
@@ -62,8 +63,6 @@ static void
 _dep_burn_node(dep_node *node)
 {
assert(node);
-   if (node->info_on_heap)
-   free(node->info);
if (node->atom)
atom_implode(node->atom);
free(node);
@@ -237,7 +236,6 @@ dep_print_tree(
 {
size_t s;
int indent = 4;  /* Gentoo 4-wide indent standard */
-   depend_atom *d = NULL;
bool singlechild = false;
bool nonewline = false;
 
@@ -260,33 +258,31 @@ dep_print_tree(
if (root->type == DEP_OR)
fprintf(fp, "|| (");
if (root->info) {
-   if (hlatoms != NULL && array_cnt(hlatoms) > 0 &&
-   root->type == DEP_NORM)
-   {
-   size_t i;
-   depend_atom *m;
-   char *oslot;
-
-   d = root->atom;
-   d->pfx_op = d->sfx_op = ATOM_OP_NONE;
-
-   array_for_each(hlatoms, i, m) {
-   oslot = d->SLOT;
-   if (m->SLOT == NULL)
-   d->SLOT = NULL;
-
-   if (atom_compare(m, d) == EQUAL) {
-   m = NULL;
-   break;
+   if (root->type == DEP_NORM) {
+   bool dohl = false;
+
+   if (hlatoms != NULL && array_cnt(hlatoms) > 0)
+   {
+   size_t   i;
+   depend_atom *m;
+
+   array_for_each(hlatoms, i, m) {
+   /* make m query, such that any 
specifics (SLOT,
+* pfx/sfx) from the depstring are 
ignored while
+* highlighting */
+   if (atom_compare(root->atom, m) == 
EQUAL) {
+   dohl = true;
+   break;
+   }
}
-   d->SLOT = oslot;
}
 
-   if (m == NULL) { /* match found */
-   fprintf(fp, "%s%s%s", hlcolor, root->info, 
NORM);
-   } else {
-   fprintf(fp, "%s", root->info);
-   }
+   fprintf(fp, "%s%s%s",
+   dohl ? hlcolor : "",
+   atom_to_string(root->atom),
+   dohl ? NORM : "");
+   if (root->atom_resolved && verbose > 0)
+   fprintf(fp, "  # %s", root->info);
} else {
fprintf(fp, "%s", root->info);
}
@@ -355,6 +351,31 @@ dep_prune_use(dep_node *root, set *use)
dep_prune_use(root->children, use);
 }
 
+void
+dep_resolve_tree(dep_node *root, tree_ctx *t)
+{
+   if (root->type != DEP_NULL) {
+   if (root->type == DEP_NORM && root->atom) {
+   depend_atom*d = root->atom;
+   tree_match_ctx *r = tree_match_atom(t, d,
+   
TREE_MATCH_DEFAULT |
+   
TREE_MATCH_LATEST);
+   if (r != NULL) {
+   atom_implode(d);
+   root->atom = atom_clone(r->atom);
+   root->atom_resolved = 1;
+   tree_match_close(r);
+  

[gentoo-commits] proj/portage-utils:master commit in: libq/

2022-05-20 Thread Fabian Groffen
commit: e1a3cb832e35df4656e64b3385823d1ffd8ab848
Author: Fabian Groffen  gentoo  org>
AuthorDate: Fri May 20 17:14:54 2022 +
Commit: Fabian Groffen  gentoo  org>
CommitDate: Fri May 20 17:14:54 2022 +
URL:https://gitweb.gentoo.org/proj/portage-utils.git/commit/?id=e1a3cb83

libq/atom: make atom_to_string_r produce BUILD_ID when set

Signed-off-by: Fabian Groffen  gentoo.org>

 libq/atom.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/libq/atom.c b/libq/atom.c
index 3d9d31f..50e9520 100644
--- a/libq/atom.c
+++ b/libq/atom.c
@@ -1015,6 +1015,8 @@ atom_to_string_r(char *buf, size_t buflen, depend_atom *a)
off += snprintf(buf + off, buflen - off, "-%s", a->PV);
if (a->PR_int > 0)
off += snprintf(buf + off, buflen - off, "-r%d", a->PR_int);
+   if (a->BUILDID > 0)
+   off += snprintf(buf + off, buflen - off, "~%u", a->BUILDID);
off += snprintf(buf + off, buflen - off, "%s", atom_op_str[a->sfx_op]);
if (a->SLOT != NULL || a->slotdep != ATOM_SD_NONE)
off += snprintf(buf + off, buflen - off, ":%s%s%s%s",



[gentoo-commits] proj/portage-utils:master commit in: libq/

2022-05-20 Thread Fabian Groffen
commit: b868d22a6c731449ccfec344508458cf9f7a5abf
Author: Fabian Groffen  gentoo  org>
AuthorDate: Fri May 20 17:02:56 2022 +
Commit: Fabian Groffen  gentoo  org>
CommitDate: Fri May 20 17:02:56 2022 +
URL:https://gitweb.gentoo.org/proj/portage-utils.git/commit/?id=b868d22a

libq/tree: support FEATURES=binpkg-multi-instance Packages file

Based on the work of genbtc in GitHub PR #16

Add BUILD_ID to atom when parsing and use PATH to get the appropriate
location.

Closes: https://github.com/gentoo/portage-utils/pull/16
Signed-off-by: Fabian Groffen  gentoo.org>

 libq/tree.c | 23 ++-
 libq/tree.h |  4 +++-
 2 files changed, 21 insertions(+), 6 deletions(-)

diff --git a/libq/tree.c b/libq/tree.c
index d71ee74..2a457ce 100644
--- a/libq/tree.c
+++ b/libq/tree.c
@@ -1440,6 +1440,8 @@ tree_foreach_packages(tree_ctx *ctx, tree_pkg_cb 
callback, void *priv)
}
cat->pkg_ctxs = (tree_pkg_ctx **)atom;  
/* for name */
}
+   if (meta.Q_BUILDID != NULL)
+   atom->BUILDID = atoi(meta.Q_BUILDID);
pkgnamelen = snprintf(pkgname, sizeof(pkgname),
"%s.tbz2", atom->PF);
pkgname[pkgnamelen - (sizeof(".tbz2") - 1)] = 
'\0';
@@ -1510,6 +1512,9 @@ tree_foreach_packages(tree_ctx *ctx, tree_pkg_cb 
callback, void *priv)
match_key(PDEPEND);
match_key2(REPO, repository);
match_key(SIZE);
+   match_key(BDEPEND);
+   match_key(PATH);
+   match_key2(BUILD_ID, BUILDID);
 #undef match_key
 #undef match_key2
}
@@ -1812,11 +1817,19 @@ tree_match_atom(tree_ctx *ctx, const depend_atom 
*query, int flags)
n = xzalloc(sizeof(tree_match_ctx)); \
n->atom = atom; \
n->pkg = pkg_ctx; \
-   snprintf(n->path, sizeof(n->path), "%s/%s/%s%s", \
-   (char *)C->ctx->path, C->name, 
pkg_ctx->name, \
-   C->ctx->cachetype == CACHE_EBUILD ? 
".ebuild" : \
-   C->ctx->cachetype == CACHE_BINPKGS ? 
".tbz2" : \
-   C->ctx->cachetype == CACHE_PACKAGES ? 
".tbz2" : ""); \
+   if (C->ctx->cachetype == CACHE_PACKAGES && \
+   pkg_ctx->meta->Q_PATH != NULL) \
+   { \
+   /* binpkg-multi-instance has a PATH ready for 
us */ \
+   snprintf(n->path, sizeof(n->path), "%s/%s", \
+(char *)C->ctx->path, 
pkg_ctx->meta->Q_PATH); \
+   } else { \
+   snprintf(n->path, sizeof(n->path), 
"%s/%s/%s%s", \
+(char *)C->ctx->path, C->name, 
pkg_ctx->name, \
+C->ctx->cachetype == 
CACHE_EBUILD   ? ".ebuild" : \
+C->ctx->cachetype == 
CACHE_BINPKGS  ? ".tbz2" : \
+C->ctx->cachetype == 
CACHE_PACKAGES ? ".tbz2" : ""); \
+   } \
if (flags & TREE_MATCH_METADATA) \
n->meta = tree_pkg_read(pkg_ctx); \
if (C->ctx->cachetype == CACHE_BINPKGS || \

diff --git a/libq/tree.h b/libq/tree.h
index 8279281..2f2c81f 100644
--- a/libq/tree.h
+++ b/libq/tree.h
@@ -1,5 +1,5 @@
 /*
- * Copyright 2005-2021 Gentoo Foundation
+ * Copyright 2005-2022 Gentoo Foundation
  * Distributed under the terms of the GNU General Public License v2
  */
 
@@ -104,6 +104,8 @@ struct tree_pkg_meta {
char *Q_CONTENTS;
char *Q_USE;
char *Q_EPREFIX;
+   char *Q_PATH; /* binpkg-multi-instance */
+   char *Q_BUILDID;  /* binpkg-multi-instance */
char *Q_repository;
char *Q_MD5;
char *Q_SHA1;



[gentoo-commits] proj/portage-utils:master commit in: libq/

2022-05-19 Thread Fabian Groffen
commit: 566c8b8db5bc0f7ae4636a1d3387ddb6de41692f
Author: Fabian Groffen  gentoo  org>
AuthorDate: Thu May 19 08:31:40 2022 +
Commit: Fabian Groffen  gentoo  org>
CommitDate: Thu May 19 08:31:40 2022 +
URL:https://gitweb.gentoo.org/proj/portage-utils.git/commit/?id=566c8b8d

libq/atom: allow including BUILDID in atom_format

Signed-off-by: Fabian Groffen  gentoo.org>

 libq/atom.c | 15 +++
 1 file changed, 15 insertions(+)

diff --git a/libq/atom.c b/libq/atom.c
index 6f88698..3d9d31f 100644
--- a/libq/atom.c
+++ b/libq/atom.c
@@ -1045,6 +1045,7 @@ atom_to_string_r(char *buf, size_t buflen, depend_atom *a)
  *- any prefix of these (e.g. CAT, CA, C) will match as well
  *  pfx - the version qualifier if set (e.g. > < = !)
  *  sfx - the version qualifier if set (e.g. *)
+ *  BUILDID - the binpkg-multi-instance id
  */
 char *
 atom_format_r(
@@ -1174,6 +1175,20 @@ atom_format_r(
append_buf(buf, 
buflen, "%s", "]");
}
}
+   } else if (strncmp("BUILDID", fmt, len) == 0) {
+   if (showit || atom->BUILDID > 0) {
+   /* this is really shitty, '-' 
is not feasible,
+* but used by Portage
+* 
https://archives.gentoo.org/gentoo-portage-dev/message/054f5f1f334b60bdb1b7f80ff4755bd4
+* using this we cannot parse 
what we would
+* produce, but look more like 
the original
+* since it's not clear this is 
necessary at
+* all, I decided to avoid any 
confusion and use
+* '~' so we can see this is 
not a version bit */
+   append_buf(buf, buflen, 
"%s%s%u%s",
+  RED, 
connected ? "~" : "",
+  
atom->BUILDID, NORM);
+   }
} else
append_buf(buf, buflen, "", 
(int)len, fmt);
p++;



[gentoo-commits] proj/portage-utils:master commit in: libq/

2022-05-19 Thread Fabian Groffen
commit: be7090b77585c7c4af0d46ca0cde805d370c6cc0
Author: Fabian Groffen  gentoo  org>
AuthorDate: Thu May 19 08:15:34 2022 +
Commit: Fabian Groffen  gentoo  org>
CommitDate: Thu May 19 08:15:34 2022 +
URL:https://gitweb.gentoo.org/proj/portage-utils.git/commit/?id=be7090b7

libq/atom: make atom_compare consider BUILDID

PR: https://github.com/gentoo/portage-utils/pull/16
Signed-off-by: Fabian Groffen  gentoo.org>

 libq/atom.c | 18 +-
 1 file changed, 13 insertions(+), 5 deletions(-)

diff --git a/libq/atom.c b/libq/atom.c
index d1eb9a4..6f88698 100644
--- a/libq/atom.c
+++ b/libq/atom.c
@@ -954,16 +954,24 @@ atom_compare_flg(const depend_atom *data, const 
depend_atom *query, int flags)
 * 6:return  A < B
 * 7:  end if
 */
-   /* Make sure the -r# is the same. 3.7 */
+   /* first handle wildcarding cases */
if ((sfx_op == ATOM_OP_STAR && query->PR_int == 0) ||
pfx_op == ATOM_OP_PV_EQUAL ||
-   flags & ATOM_COMP_NOREV ||
-   data->PR_int == query->PR_int)
+   flags & ATOM_COMP_NOREV)
return _atom_compare_match(EQUAL, pfx_op);
-   else if (data->PR_int < query->PR_int)
+   /* Make sure the -r# is the same. 3.7 */
+   if (data->PR_int < query->PR_int)
+   return _atom_compare_match(OLDER, pfx_op);
+   else if (data->PR_int > query->PR_int)
+   return _atom_compare_match(NEWER, pfx_op);
+
+   /* binpkg-multi-instance support */
+   if (data->BUILDID < query->BUILDID)
return _atom_compare_match(OLDER, pfx_op);
-   else
+   if (data->BUILDID > query->BUILDID)
return _atom_compare_match(NEWER, pfx_op);
+
+   return _atom_compare_match(EQUAL, pfx_op);
 }
 
 atom_equality



[gentoo-commits] proj/portage-utils:master commit in: libq/

2022-05-19 Thread Fabian Groffen
commit: 74aaef62c0bfad13cf528497faf4b12cbe3d52a5
Author: Fabian Groffen  gentoo  org>
AuthorDate: Thu May 19 07:43:08 2022 +
Commit: Fabian Groffen  gentoo  org>
CommitDate: Thu May 19 07:43:08 2022 +
URL:https://gitweb.gentoo.org/proj/portage-utils.git/commit/?id=74aaef62

libq/atom.h: add BUILDID to atom for binpkg-multi-instance support

References: https://github.com/gentoo/portage-utils/pull/16
Signed-off-by: Fabian Groffen  gentoo.org>

 libq/atom.h | 33 +
 1 file changed, 17 insertions(+), 16 deletions(-)

diff --git a/libq/atom.h b/libq/atom.h
index 8291daf..fcfa0bd 100644
--- a/libq/atom.h
+++ b/libq/atom.h
@@ -1,5 +1,5 @@
 /*
- * Copyright 2005-2021 Gentoo Foundation
+ * Copyright 2005-2022 Gentoo Foundation
  * Distributed under the terms of the GNU General Public License v2
  *
  * Copyright 2005-2008 Ned Ludd- 
@@ -68,23 +68,24 @@ typedef struct _atom_usedep {
 } atom_usedep;
 
 typedef struct {
-   atom_blocker blocker;
+   atom_blocker  blocker;
atom_operator pfx_op;
atom_operator sfx_op;
-   char *CATEGORY;
-   char *PN;
-   char *PV;
-   char *PF;
-   unsigned int PR_int;
-   char letter;
-   atom_suffix *suffixes;
-   char *PVR;
-   char *P;
-   atom_usedep *usedeps;
-   char *SLOT;
-   char *SUBSLOT;
-   atom_slotdep slotdep;
-   char *REPO;
+   char *CATEGORY;
+   char *PN;
+   char *PV;
+   char *PF;
+   unsigned int  PR_int;
+   char  letter;
+   atom_suffix  *suffixes;
+   char *PVR;
+   char *P;
+   atom_usedep  *usedeps;
+   char *SLOT;
+   char *SUBSLOT;
+   atom_slotdep  slotdep;
+   char *REPO;
+   unsigned int  BUILDID;
 } depend_atom;
 
 extern const char * const booga[];



[gentoo-commits] proj/portage-utils:master commit in: libq/, tests/qdepends/

2022-04-07 Thread Fabian Groffen
commit: 82f8dc2ee9ba0ff97924df0dcc3feba3935b979c
Author: Fabian Groffen  gentoo  org>
AuthorDate: Thu Apr  7 17:14:08 2022 +
Commit: Fabian Groffen  gentoo  org>
CommitDate: Thu Apr  7 17:14:08 2022 +
URL:https://gitweb.gentoo.org/proj/portage-utils.git/commit/?id=82f8dc2e

libq/dep: print single nodes on a single line

condense conditional and use-deps to a single line when there's a single
target, e.g.:

use? ( cat/pkg )

instead of

use? (
cat/pkg
)

Signed-off-by: Fabian Groffen  gentoo.org>

 libq/dep.c | 34 +-
 tests/qdepends/list03.good |  4 +---
 tests/qdepends/list04.good |  4 +---
 tests/qdepends/list05.good |  4 +---
 4 files changed, 32 insertions(+), 14 deletions(-)

diff --git a/libq/dep.c b/libq/dep.c
index d431367..99629e7 100644
--- a/libq/dep.c
+++ b/libq/dep.c
@@ -238,6 +238,13 @@ dep_print_tree(
size_t s;
int indent = 4;  /* Gentoo 4-wide indent standard */
depend_atom *d = NULL;
+   bool singlechild = false;
+   bool nonewline = false;
+
+   if (verbose < 0) {
+   nonewline = true;
+   verbose = -verbose - 1;
+   }
 
assert(root);
if (root->type == DEP_NULL)
@@ -248,7 +255,8 @@ dep_print_tree(
 
if (verbose > 0)
fprintf(fp, "Node [%s]: ", _dep_names[root->type]);
-   /*printf("Node %p [%s] %p %p %p: ", root, _dep_names[root->type], 
root->parent, root->neighbor, root->children);*/
+   /*printf("Node %p [%s] %p %p %p: ", root, _dep_names[root->type],
+*   root->parent, root->neighbor, root->children);*/
if (root->type == DEP_OR)
fprintf(fp, "|| (");
if (root->info) {
@@ -286,14 +294,30 @@ dep_print_tree(
if (root->type == DEP_USE)
fprintf(fp, "? (");
}
-   fprintf(fp, "\n");
+
+   if (root->children &&
+   root->children->children == NULL &&
+   root->children->neighbor == NULL)
+   {
+   singlechild = true;
+   }
+
+   if (singlechild)
+   fprintf(fp, " ");
+   else if (!nonewline)
+   fprintf(fp, "\n");
 
if (root->children)
-   dep_print_tree(fp, root->children, space+1, hlatoms, hlcolor, 
verbose);
+   dep_print_tree(fp, root->children,
+  singlechild ? 0 : space + 1,
+  hlatoms, hlcolor, singlechild ? 
-verbose - 1 : verbose);
 
if (root->type == DEP_OR || root->type == DEP_USE) {
-   for (s = space; s; --s)
-   fprintf(fp, "%*s", indent, "");
+   if (singlechild)
+   fprintf(fp, " ");
+   else
+   for (s = space; s; --s)
+   fprintf(fp, "%*s", indent, "");
fprintf(fp, ")\n");
}
  this_node_sucks:

diff --git a/tests/qdepends/list03.good b/tests/qdepends/list03.good
index f66b636..d0eb5d2 100644
--- a/tests/qdepends/list03.good
+++ b/tests/qdepends/list03.good
@@ -1,5 +1,3 @@
 DEPEND="
-foo? (
-a/b
-)
+foo? ( a/b )
 "

diff --git a/tests/qdepends/list04.good b/tests/qdepends/list04.good
index 2457caf..7f0887a 100644
--- a/tests/qdepends/list04.good
+++ b/tests/qdepends/list04.good
@@ -1,5 +1,3 @@
 DEPEND="
-|| (
-a/b
-)
+|| ( a/b )
 "

diff --git a/tests/qdepends/list05.good b/tests/qdepends/list05.good
index 0b7d420..868efae 100644
--- a/tests/qdepends/list05.good
+++ b/tests/qdepends/list05.good
@@ -1,9 +1,7 @@
 DEPEND="
 || (
 || (
-|| (
-x
-)
+|| ( x )
 a
 )
 )



[gentoo-commits] proj/portage-utils:master commit in: libq/

2022-02-12 Thread Fabian Groffen
commit: d314b816ef29bf1948cd9f747a22c2565e88bf76
Author: Fabian Groffen  gentoo  org>
AuthorDate: Sat Feb 12 17:03:56 2022 +
Commit: Fabian Groffen  gentoo  org>
CommitDate: Sat Feb 12 17:03:56 2022 +
URL:https://gitweb.gentoo.org/proj/portage-utils.git/commit/?id=d314b816

libq/tree: fix Coverity uninitialised memory use CID 248874

tree_read_file_pms was using buf, which was never initialised after
some changes from the past

remove entire buf, and use the paths from pkg and cat ctxs in the
printfs directly

Signed-off-by: Fabian Groffen  gentoo.org>

 libq/tree.c | 8 
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/libq/tree.c b/libq/tree.c
index 1e0e623..d71ee74 100644
--- a/libq/tree.c
+++ b/libq/tree.c
@@ -676,7 +676,6 @@ tree_read_file_pms(tree_pkg_ctx *pkg_ctx)
FILE *f;
tree_pkg_meta *ret = NULL;
size_t len;
-   char buf[_Q_PATH_MAX];
 
if ((f = fdopen(pkg_ctx->fd, "r")) == NULL)
goto err;
@@ -695,7 +694,8 @@ tree_read_file_pms(tree_pkg_ctx *pkg_ctx)
ret->Q_DEPEND = ptr;
 #define next_line(curr, next) \
if ((ptr = strchr(ret->Q_##curr, '\n')) == NULL) { \
-   warn("Invalid cache file for '%s'", buf); \
+   warn("Invalid cache file for '%s/%s'", \
+pkg_ctx->cat_ctx->name, pkg_ctx->name); \
goto err; \
} \
ret->Q_##next = ptr+1; \
@@ -718,8 +718,8 @@ tree_read_file_pms(tree_pkg_ctx *pkg_ctx)
 #undef next_line
ptr = strchr(ptr+1, '\n');
if (ptr == NULL) {
-   warn("Invalid cache file for '%s' - could not find end of cache 
data",
-   buf);
+   warn("Invalid cache file for '%s/%s' - could not find end of 
cache data",
+pkg_ctx->cat_ctx->name, pkg_ctx->name);
goto err;
}
*ptr = '\0';



[gentoo-commits] proj/portage-utils:master commit in: libq/

2022-02-12 Thread Fabian Groffen
commit: 4b8b0aa52cac041938a08a310f40b6de16b8c3b0
Author: Fabian Groffen  gentoo  org>
AuthorDate: Sat Feb 12 17:12:02 2022 +
Commit: Fabian Groffen  gentoo  org>
CommitDate: Sat Feb 12 17:12:02 2022 +
URL:https://gitweb.gentoo.org/proj/portage-utils.git/commit/?id=4b8b0aa5

libq/move_file: fix Coverity uninitialised use CID 248870

Coverity correctly deduced here, that if we used cached stat, we didn't
use the cache, but a bogus memory struct instead.  Ensure we always use
a populated stat value.

Signed-off-by: Fabian Groffen  gentoo.org>

 libq/move_file.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/libq/move_file.c b/libq/move_file.c
index b98c8e2..104ca25 100644
--- a/libq/move_file.c
+++ b/libq/move_file.c
@@ -1,5 +1,5 @@
 /*
- * Copyright 2005-2021 Gentoo Authors
+ * Copyright 2005-2022 Gentoo Authors
  * Distributed under the terms of the GNU General Public License v2
  *
  * Copyright 2005-2010 Ned Ludd- 
@@ -86,8 +86,8 @@ move_file(int rootfd_src, const char *name_src,
}
 
/* preserve the file times */
-   times[0] = get_stat_atime();
-   times[1] = get_stat_mtime();
+   times[0] = get_stat_atime(stat_src);
+   times[1] = get_stat_mtime(stat_src);
futimens(fd_dst, times);
 
close(fd_src);



[gentoo-commits] proj/portage-utils:master commit in: libq/

2022-02-06 Thread Fabian Groffen
commit: 42a04c468aff667e0dbaf69aef07c9f679176470
Author: Fabian Groffen  gentoo  org>
AuthorDate: Sun Feb  6 14:51:14 2022 +
Commit: Fabian Groffen  gentoo  org>
CommitDate: Sun Feb  6 14:51:14 2022 +
URL:https://gitweb.gentoo.org/proj/portage-utils.git/commit/?id=42a04c46

libq/tree: plug leak in tree_match_atom

Signed-off-by: Fabian Groffen  gentoo.org>

 libq/tree.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/libq/tree.c b/libq/tree.c
index 7285cd7..1e0e623 100644
--- a/libq/tree.c
+++ b/libq/tree.c
@@ -1778,6 +1778,7 @@ tree_match_atom(tree_ctx *ctx, const depend_atom *query, 
int flags)
sizeof(*cat_ctx->pkg_ctxs), 
tree_pkg_compar);
}
}
+   xarrayfree_int(cats);
}
 
/* activate cache for future lookups, tree_match_atom relies on



[gentoo-commits] proj/portage-utils:master commit in: libq/

2022-02-06 Thread Fabian Groffen
commit: 43ad7423ae06e9bcad672a21131f14e3ce790204
Author: Fabian Groffen  gentoo  org>
AuthorDate: Sun Feb  6 14:20:35 2022 +
Commit: Fabian Groffen  gentoo  org>
CommitDate: Sun Feb  6 14:20:35 2022 +
URL:https://gitweb.gentoo.org/proj/portage-utils.git/commit/?id=43ad7423

libq/xsystem: cleanup/reuse same codepath, allow passing vector

Signed-off-by: Fabian Groffen  gentoo.org>

 libq/xsystem.c | 96 --
 libq/xsystem.h |  8 +++--
 2 files changed, 65 insertions(+), 39 deletions(-)

diff --git a/libq/xsystem.c b/libq/xsystem.c
index e2dbc5e..05743ce 100644
--- a/libq/xsystem.c
+++ b/libq/xsystem.c
@@ -17,49 +17,73 @@
 #include "xasprintf.h"
 #include "xsystem.h"
 
-void xsystem(const char *command)
-{
-   if (unlikely(system(command)))
-   errp("system(%s) failed", command);
-}
-
-void xsystembash(const char *command, int cwd)
+void xsystembash(const char *command, const char **argv, int cwd)
 {
pid_t p = fork();
int status;
 
switch (p) {
-   case 0: /* child */
-   if (cwd != AT_FDCWD)
-   if (fchdir(cwd)) {
-   /* fchdir works with O_PATH starting 
w/linux-3.5 */
-   if (errno == EBADF) {
-   char *path;
-   xasprintf(, "/proc/self/fd/%i", 
cwd);
-   if (chdir(path))
-   errp("chdir(%s) failed", path);
-   } else
-   errp("fchdir(%i) failed", cwd);
+   case 0: /* child */
+   if (cwd != AT_FDCWD) {
+   if (fchdir(cwd)) {
+   /* fchdir works with O_PATH starting 
w/linux-3.5 */
+   if (errno == EBADF) {
+   char *path;
+   xasprintf(, 
"/proc/self/fd/%i", cwd);
+   if (chdir(path))
+   errp("chdir(%s) 
failed", path);
+   } else {
+   errp("fchdir(%i) failed", cwd);
+   }
+   }
+   }
+   if (argv == NULL) {
+   execl(CONFIG_EPREFIX "bin/bash", "bash",
+ "--norc", "--noprofile", "-c", 
command, (char *)NULL);
+   /* Hrm, still here ?  Maybe no bash ... */
+   _exit(execl("/bin/sh", "sh", "-c", command, 
(char *)NULL));
+   } else {
+   int  argc = 0;
+   const char  *a;
+   const char **newargv;
+
+   /* count existing args */
+   for (a = argv[0]; a != NULL; a++, argc++)
+   ;
+   argc += 1 + 1 + 1 + 1;
+   newargv = xmalloc(sizeof(newargv[0]) * (argc + 
1));
+   argc = 0;
+   newargv[argc++] = "bash";
+   newargv[argc++] = "--norc";
+   newargv[argc++] = "--noprofile";
+   newargv[argc++] = "-c";
+   for (a = argv[0]; a != NULL; a++)
+   newargv[argc++] = a;
+   newargv[argc] = NULL;
+
+   execv(CONFIG_EPREFIX "bin/bash", (char *const 
*)newargv);
+
+   /* Hrm, still here ?  Maybe no bash ... */
+   newargv = [2];  /* shift, two args less 
*/
+   argc = 0;
+   newargv[argc++] = "sh";
+   _exit(execv("/bin/sh", (char *const *)newargv));
}
-   execl(CONFIG_EPREFIX "bin/bash", "bash",
-   "--norc", "--noprofile", "-c", command, (char 
*)NULL);
-   /* Hrm, still here ?  Maybe no bash ... */
-   _exit(execl("/bin/sh", "sh", "-c", command, (char *)NULL));
 
-   default: /* parent */
-   waitpid(p, , 0);
-   if (WIFSIGNALED(status)) {
-   err("phase crashed with signal %i: %s", 
WTERMSIG(status),
-   strsignal(WTERMSIG(status)));
-   } else if (WIFEXITED(status)) {
-   if (WEXITSTATUS(status) == 0)
-   return;

[gentoo-commits] proj/portage-utils:master commit in: libq/

2022-02-06 Thread Fabian Groffen
commit: d0767ea8eab387c65a90445bfd5d8e6e196c30d6
Author: Fabian Groffen  gentoo  org>
AuthorDate: Sun Feb  6 13:24:54 2022 +
Commit: Fabian Groffen  gentoo  org>
CommitDate: Sun Feb  6 13:24:54 2022 +
URL:https://gitweb.gentoo.org/proj/portage-utils.git/commit/?id=d0767ea8

libq/tree: ensure we free cache.store (for Packages file)

Signed-off-by: Fabian Groffen  gentoo.org>

 libq/tree.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/libq/tree.c b/libq/tree.c
index 114541d..db0d2d2 100644
--- a/libq/tree.c
+++ b/libq/tree.c
@@ -1,5 +1,5 @@
 /*
- * Copyright 2005-2021 Gentoo Foundation
+ * Copyright 2005-2022 Gentoo Foundation
  * Distributed under the terms of the GNU General Public License v2
  *
  * Copyright 2005-2008 Ned Ludd- 
@@ -194,6 +194,8 @@ tree_close(tree_ctx *ctx)
 
xarrayfree_int(t);
}
+   if (ctx->cache.store != NULL)
+   free(ctx->cache.store);
 
closedir(ctx->dir);
/* closedir() above does this for us: */



[gentoo-commits] proj/portage-utils:master commit in: libq/

2022-02-06 Thread Fabian Groffen
commit: 0541387d790d9e9c0e0033492bdbdb5c6d6d2f59
Author: Fabian Groffen  gentoo  org>
AuthorDate: Sun Feb  6 13:27:22 2022 +
Commit: Fabian Groffen  gentoo  org>
CommitDate: Sun Feb  6 13:27:22 2022 +
URL:https://gitweb.gentoo.org/proj/portage-utils.git/commit/?id=0541387d

libq/tree: allocate enough space in tree_clone_meta

Signed-off-by: Fabian Groffen  gentoo.org>

 libq/tree.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libq/tree.c b/libq/tree.c
index db0d2d2..7285cd7 100644
--- a/libq/tree.c
+++ b/libq/tree.c
@@ -1135,7 +1135,7 @@ tree_clone_meta(tree_pkg_meta *m)
len = sizeof(*ret);
for (ptr = >Q__data; ptr <= >Q__last; ptr++)
if (*ptr != NULL)
-   len += strlen(*ptr);
+   len += strlen(*ptr) + 1;
 
/* malloc and copy */
ret = xzalloc(len);



[gentoo-commits] proj/portage-utils:master commit in: libq/

2022-02-06 Thread Fabian Groffen
commit: 8468afb97a92adb0c49aaff461bafc7fc0f72992
Author: Fabian Groffen  gentoo  org>
AuthorDate: Sun Feb  6 12:21:53 2022 +
Commit: Fabian Groffen  gentoo  org>
CommitDate: Sun Feb  6 12:21:53 2022 +
URL:https://gitweb.gentoo.org/proj/portage-utils.git/commit/?id=8468afb9

libq/xsystem: avoid using obsolete vfork()

Signed-off-by: Fabian Groffen  gentoo.org>

 libq/xsystem.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/libq/xsystem.c b/libq/xsystem.c
index e11172e..e2dbc5e 100644
--- a/libq/xsystem.c
+++ b/libq/xsystem.c
@@ -1,8 +1,9 @@
 /*
- * Copyright 2010-2019 Gentoo Foundation
+ * Copyright 2010-2022 Gentoo Foundation
  * Distributed under the terms of the GNU General Public License v2
  *
  * Copyright 2010-2016 Mike Frysinger  - 
+ * Copyright 2022- Fabian Groffen  - 
  */
 
 #include "main.h"
@@ -24,7 +25,7 @@ void xsystem(const char *command)
 
 void xsystembash(const char *command, int cwd)
 {
-   pid_t p = vfork();
+   pid_t p = fork();
int status;
 
switch (p) {



[gentoo-commits] proj/portage-utils:master commit in: libq/

2021-12-29 Thread Fabian Groffen
commit: cea99ce1b9b6d0c9ebb496dcd2f1e77ab9ab1dcd
Author: Fabian Groffen  gentoo  org>
AuthorDate: Wed Dec 29 12:17:32 2021 +
Commit: Fabian Groffen  gentoo  org>
CommitDate: Wed Dec 29 12:17:32 2021 +
URL:https://gitweb.gentoo.org/proj/portage-utils.git/commit/?id=cea99ce1

libq/tree: avoid nasty realloc magic on tree_pkg_meta

doing reallocs possibly (hight probability) invalidates previously
retrieved pointers, which is really nasty to work with, and error prone,
so instead allocate incremental slabs where necessary

Signed-off-by: Fabian Groffen  gentoo.org>

 libq/tree.c | 206 +++-
 libq/tree.h |  11 +++-
 2 files changed, 116 insertions(+), 101 deletions(-)

diff --git a/libq/tree.c b/libq/tree.c
index 87df175..114541d 100644
--- a/libq/tree.c
+++ b/libq/tree.c
@@ -651,6 +651,21 @@ tree_pkg_vdb_eat(
return ret;
 }
 
+#define tree_meta_alloc_storage(M,SIZ) { \
+   struct tree_pkg_meta_ll *blk; \
+   size_t   newlen; \
+\
+   /* calculate new block size, ensuring it covers whatever we \
+* need to write this iteration */ \
+   newlen = SIZ) + 1) / BUFSIZ) + 1) * BUFSIZ; \
+   blk= xmalloc(sizeof(*blk) + newlen); \
+   memset(blk, 0, sizeof(*blk)); \
+   blk->next  = M->storage; \
+   blk->ptr   = (char *)blk + sizeof(*blk); \
+   blk->len   = newlen; \
+   M->storage = blk; \
+}
+
 static tree_pkg_meta *
 tree_read_file_pms(tree_pkg_ctx *pkg_ctx)
 {
@@ -668,8 +683,9 @@ tree_read_file_pms(tree_pkg_ctx *pkg_ctx)
goto err;
 
len = sizeof(*ret) + s.st_size + 1;
-   ret = xzalloc(len);
-   ptr = (char*)ret + sizeof(*ret);
+   ret = xmalloc(len);
+   memset(ret, 0, sizeof(*ret));
+   ptr = (char *)ret + sizeof(*ret);
if ((off_t)fread(ptr, 1, s.st_size, f) != s.st_size)
goto err;
ptr[s.st_size] = '\0';
@@ -954,15 +970,15 @@ static void
 tree_read_file_binpkg_xpak_cb(
void *ctx,
char *pathname,
-   int pathname_len,
-   int data_offset,
-   int data_len,
+   int   pathname_len,
+   int   data_offset,
+   int   data_len,
char *data)
 {
tree_pkg_meta *m = (tree_pkg_meta *)ctx;
-   char **key;
-   size_t pos;
-   size_t len;
+   char **key;
+   size_t pos;
+   size_t len;
 
 #define match_path(K) \
else if (pathname_len == (sizeof(#K) - 1) && strcmp(pathname, #K) == 0) 
\
@@ -994,37 +1010,28 @@ tree_read_file_binpkg_xpak_cb(
return;
 #undef match_path
 
-   /* hijack unused members */
-   pos = (size_t)m->Q__eclasses_;
-   len = (size_t)m->Q__md5_;
+   /* get current storage block */
+   if (m->storage != NULL) {
+   pos = m->storage->pos;
+   len = m->storage->len;
+   } else {
+   pos = 0;
+   len = 0;
+   }
 
/* trim whitespace (mostly trailing newline) */
while (isspace((int)data[data_offset + data_len - 1]))
data_len--;
 
if (len - pos < (size_t)(data_len + 1)) {
-   char *old_data = m->Q__data;
-   len += (((data_len + 1 - (len - pos)) / BUFSIZ) + 1) * BUFSIZ;
-   m->Q__data = xrealloc(m->Q__data, len);
-
-   /* re-position existing keys */
-   if (old_data != NULL && m->Q__data != old_data) {
-   char **newdata = (char **)m;
-   int elems = sizeof(tree_pkg_meta) / sizeof(char *);
-   while (elems-- > 1)  /* skip Q__data itself */
-   if (newdata[elems] != NULL)
-   newdata[elems] = m->Q__data + 
(newdata[elems] - old_data);
-   }
-
-   /* set after repositioning! */
-   m->Q__md5_ = (char *)len;
-   m->Q__eclasses_ = (char *)pos;
+   tree_meta_alloc_storage(m, data_len + 1);
+   len = m->storage->len;
+   pos = m->storage->pos;
}
 
-   *key = m->Q__data + pos;
+   *key = m->storage->ptr + pos;
snprintf(*key, len - pos, "%.*s", data_len, data + data_offset);
-   pos += data_len + 1;
-   m->Q__eclasses_ = (char *)pos;
+   m->storage->pos += data_len + 1;
 }
 
 static tree_pkg_meta *
@@ -1042,33 +1049,23 @@ tree_read_file_binpkg(tree_pkg_ctx *pkg_ctx)
if (newfd != -1) {
size_t fsize;
size_t needlen = 40 + 1 + 19 + 1;
-   size_t pos = (size_t)m->Q__eclasses_;
-   size_t len = (size_t)m->Q__md5_;
+   size_t pos = 0;
+   size_t len = 0;
 
-   if (len - pos < needlen) {
-   char *old_data = m->Q__data;
-   len += (((needlen - (len - pos)) / BUFSIZ) + 1) * 
BUFSIZ;
-   

[gentoo-commits] proj/portage-utils:master commit in: libq/

2021-12-26 Thread Fabian Groffen
commit: 117869a1b0d19c5e3a6b59e9e43e6849ed92efd4
Author: Fabian Groffen  gentoo  org>
AuthorDate: Sun Dec 26 13:48:49 2021 +
Commit: Fabian Groffen  gentoo  org>
CommitDate: Sun Dec 26 13:48:49 2021 +
URL:https://gitweb.gentoo.org/proj/portage-utils.git/commit/?id=117869a1

libq/move_file: code to move a file or copy+remove it

This code originated from qmerge.c, it was adapted to be more generic in
a function.

Signed-off-by: Fabian Groffen  gentoo.org>

 libq/Makefile.am |   1 +
 libq/move_file.c | 105 +++
 libq/move_file.h |  21 +++
 3 files changed, 127 insertions(+)

diff --git a/libq/Makefile.am b/libq/Makefile.am
index da100b6..c0402a4 100644
--- a/libq/Makefile.am
+++ b/libq/Makefile.am
@@ -11,6 +11,7 @@ QFILES = \
hash.c hash.h \
human_readable.c human_readable.h \
i18n.h \
+   move_file.c move_file.h \
prelink.c prelink.h \
profile.c profile.h \
rmspace.c rmspace.h \

diff --git a/libq/move_file.c b/libq/move_file.c
new file mode 100644
index 000..07cf69f
--- /dev/null
+++ b/libq/move_file.c
@@ -0,0 +1,105 @@
+/*
+ * Copyright 2005-2021 Gentoo Authors
+ * Distributed under the terms of the GNU General Public License v2
+ *
+ * Copyright 2005-2010 Ned Ludd- 
+ * Copyright 2005-2014 Mike Frysinger  - 
+ * Copyright 2018- Fabian Groffen  - 
+ */
+
+#include "main.h"
+
+#include 
+#include 
+#include 
+#include 
+#include "stat-time.h"
+
+#include "copy_file.h"
+#include "move_file.h"
+
+int
+move_file(int rootfd_src, const char *name_src,
+ int rootfd_dst, const char *name_dst,
+ struct stat *stat_src)
+{
+   /* first try fast path -- src/dst are same device, else
+* fall back to slow path -- manual read/write */
+   if (renameat(rootfd_src, name_src, rootfd_dst, name_dst) != 0) {
+   int fd_src;
+   int fd_dst;
+   chartmpname_dst[_Q_PATH_MAX];
+   struct stat st;
+   struct timespec times[2];
+
+   fd_src = openat(rootfd_src, name_src, O_RDONLY|O_CLOEXEC);
+   if (fd_src < 0) {
+   warnp("could not read source file %s", name_src);
+   return fd_src;
+   }
+
+   if (stat_src == NULL) {
+   if (fstat(fd_src, ) != 0) {
+   warnp("could not stat source file %s", 
name_src);
+   return -1;
+   }
+
+   stat_src = 
+   }
+
+   /* do not write the file in place ...
+* will fail with files that are in use
+* plus it isn't atomic, so we could leave a mess */
+   snprintf(tmpname_dst, sizeof(tmpname_dst), ".%u.%s",
+getpid(), name_dst);
+   fd_dst = openat(rootfd_dst, tmpname_dst,
+   
O_WRONLY|O_CLOEXEC|O_CREAT|O_TRUNC,
+   stat_src->st_mode);
+   if (fd_dst < 0) {
+   warnp("could not open destination file %s (for %s)",
+ tmpname_dst, name_dst);
+   close(fd_src);
+   return fd_dst;
+   }
+
+   /* make sure owner/mode is sane before we write out data */
+   if (fchown(fd_dst, stat_src->st_uid, stat_src->st_gid) != 0) {
+   warnp("could not set ownership (%zu/%zu) for %s",
+ (size_t)stat_src->st_uid, 
(size_t)stat_src->st_gid, name_dst);
+   return -1;
+   }
+   if (fchmod(fd_dst, stat_src->st_mode) != 0) {
+   warnp("could not set permission (%u) for %s",
+ (int)stat_src->st_mode, name_dst);
+   return -1;
+   }
+
+   /* do the actual data copy */
+   if (copy_file_fd(fd_src, fd_dst)) {
+   warnp("could not write to file %s", name_dst);
+   if (unlinkat(rootfd_dst, tmpname_dst, 0) != 0) {
+   /* don't care */;
+   }
+   close(fd_src);
+   close(fd_dst);
+   return -1;
+   }
+
+   /* Preserve the file times */
+   times[0] = get_stat_atime();
+   times[1] = get_stat_mtime();
+   futimens(fd_dst, times);
+
+   close(fd_src);
+   close(fd_dst);
+
+   /* finally move the new tmp dst file to the right place, which
+* should be on the same FS/device now */
+   if (renameat(rootfd_dst, tmpname_dst, rootfd_dst, 

[gentoo-commits] proj/portage-utils:master commit in: libq/

2021-12-26 Thread Fabian Groffen
commit: 19df31a23a3a5ab08abde6cea7f4b8bfd44fd07c
Author: Fabian Groffen  gentoo  org>
AuthorDate: Sun Dec 26 13:48:12 2021 +
Commit: Fabian Groffen  gentoo  org>
CommitDate: Sun Dec 26 13:48:12 2021 +
URL:https://gitweb.gentoo.org/proj/portage-utils.git/commit/?id=19df31a2

libq/scandirat: add filter_self_parent func

Signed-off-by: Fabian Groffen  gentoo.org>

 libq/scandirat.c | 18 +++---
 libq/scandirat.h |  9 +++--
 2 files changed, 22 insertions(+), 5 deletions(-)

diff --git a/libq/scandirat.c b/libq/scandirat.c
index f28ba0d..ec4b691 100644
--- a/libq/scandirat.c
+++ b/libq/scandirat.c
@@ -1,5 +1,5 @@
 /*
- * Copyright 2005-2019 Gentoo Foundation
+ * Copyright 2005-2021 Gentoo Foundation
  * Distributed under the terms of the GNU General Public License v2
  *
  * Copyright 2005-2010 Ned Ludd- 
@@ -87,9 +87,21 @@ scandir_free(struct dirent **de, int cnt)
 }
 
 int
-filter_hidden(const struct dirent *dentry)
+filter_hidden(const struct dirent *de)
 {
-   if (dentry->d_name[0] == '.')
+   if (de->d_name[0] == '.')
return 0;
return 1;
 }
+
+int
+filter_self_parent(const struct dirent *de)
+{
+   if (de->d_name[0] == '.' &&
+   (de->d_name[1] == '\0' ||
+(de->d_name[1] == '.' &&
+ de->d_name[2] == '\0')))
+   return 0;
+
+   return 1;
+}

diff --git a/libq/scandirat.h b/libq/scandirat.h
index 950cbb1..1ac2b50 100644
--- a/libq/scandirat.h
+++ b/libq/scandirat.h
@@ -1,6 +1,10 @@
 /*
- * Copyright 2005-2019 Gentoo Foundation
+ * Copyright 2005-2021 Gentoo Foundation
  * Distributed under the terms of the GNU General Public License v2
+ *
+ * Copyright 2005-2010 Ned Ludd- 
+ * Copyright 2005-2014 Mike Frysinger  - 
+ * Copyright 2021- Fabian Groffen  - 
  */
 
 #ifndef _SCANDIRAT_H
@@ -19,6 +23,7 @@ int scandirat(
 #endif
 
 void scandir_free(struct dirent **de, int cnt);
-int filter_hidden(const struct dirent *dentry);
+int filter_hidden(const struct dirent *de);
+int filter_self_parent(const struct dirent *de);
 
 #endif



[gentoo-commits] proj/portage-utils:master commit in: libq/

2021-12-26 Thread Fabian Groffen
commit: 226ee978a882ad95515fb289027646cdbb230515
Author: Fabian Groffen  gentoo  org>
AuthorDate: Sun Dec 26 13:50:38 2021 +
Commit: Fabian Groffen  gentoo  org>
CommitDate: Sun Dec 26 13:50:38 2021 +
URL:https://gitweb.gentoo.org/proj/portage-utils.git/commit/?id=226ee978

buildsys: regenerate

Signed-off-by: Fabian Groffen  gentoo.org>

 libq/Makefile.in | 44 
 1 file changed, 28 insertions(+), 16 deletions(-)

diff --git a/libq/Makefile.in b/libq/Makefile.in
index a695113..aa116de 100644
--- a/libq/Makefile.in
+++ b/libq/Makefile.in
@@ -246,21 +246,21 @@ libq_la_LIBADD =
 am__libq_la_SOURCES_DIST = atom.c atom.h basename.c basename.h \
busybox.h colors.c colors.h contents.c contents.h copy_file.c \
copy_file.h dep.c dep.h eat_file.c eat_file.h hash.c hash.h \
-   human_readable.c human_readable.h i18n.h prelink.c prelink.h \
-   profile.c profile.h rmspace.c rmspace.h safe_io.c safe_io.h \
-   scandirat.c scandirat.h set.c set.h tree.c tree.h xarray.c \
-   xarray.h xasprintf.h xchdir.c xchdir.h xmkdir.c xmkdir.h \
-   xpak.c xpak.h xregex.c xregex.h xsystem.c xsystem.h \
-   hash_md5_sha1.c hash_md5_sha1.h
+   human_readable.c human_readable.h i18n.h move_file.c \
+   move_file.h prelink.c prelink.h profile.c profile.h rmspace.c \
+   rmspace.h safe_io.c safe_io.h scandirat.c scandirat.h set.c \
+   set.h tree.c tree.h xarray.c xarray.h xasprintf.h xchdir.c \
+   xchdir.h xmkdir.c xmkdir.h xpak.c xpak.h xregex.c xregex.h \
+   xsystem.c xsystem.h hash_md5_sha1.c hash_md5_sha1.h
 @QMANIFEST_ENABLED_FALSE@@QTEGRITY_ENABLED_FALSE@am__objects_1 = 
libq_la-hash_md5_sha1.lo
 am__objects_2 = libq_la-atom.lo libq_la-basename.lo libq_la-colors.lo \
libq_la-contents.lo libq_la-copy_file.lo libq_la-dep.lo \
libq_la-eat_file.lo libq_la-hash.lo libq_la-human_readable.lo \
-   libq_la-prelink.lo libq_la-profile.lo libq_la-rmspace.lo \
-   libq_la-safe_io.lo libq_la-scandirat.lo libq_la-set.lo \
-   libq_la-tree.lo libq_la-xarray.lo libq_la-xchdir.lo \
-   libq_la-xmkdir.lo libq_la-xpak.lo libq_la-xregex.lo \
-   libq_la-xsystem.lo $(am__objects_1)
+   libq_la-move_file.lo libq_la-prelink.lo libq_la-profile.lo \
+   libq_la-rmspace.lo libq_la-safe_io.lo libq_la-scandirat.lo \
+   libq_la-set.lo libq_la-tree.lo libq_la-xarray.lo \
+   libq_la-xchdir.lo libq_la-xmkdir.lo libq_la-xpak.lo \
+   libq_la-xregex.lo libq_la-xsystem.lo $(am__objects_1)
 am_libq_la_OBJECTS = $(am__objects_2)
 libq_la_OBJECTS = $(am_libq_la_OBJECTS)
 AM_V_lt = $(am__v_lt_@AM_V@)
@@ -290,6 +290,7 @@ am__depfiles_remade = ./$(DEPDIR)/libq_la-atom.Plo \
./$(DEPDIR)/libq_la-eat_file.Plo ./$(DEPDIR)/libq_la-hash.Plo \
./$(DEPDIR)/libq_la-hash_md5_sha1.Plo \
./$(DEPDIR)/libq_la-human_readable.Plo \
+   ./$(DEPDIR)/libq_la-move_file.Plo \
./$(DEPDIR)/libq_la-prelink.Plo \
./$(DEPDIR)/libq_la-profile.Plo \
./$(DEPDIR)/libq_la-rmspace.Plo \
@@ -1485,11 +1486,12 @@ top_srcdir = @top_srcdir@
 QFILES = atom.c atom.h basename.c basename.h busybox.h colors.c \
colors.h contents.c contents.h copy_file.c copy_file.h dep.c \
dep.h eat_file.c eat_file.h hash.c hash.h human_readable.c \
-   human_readable.h i18n.h prelink.c prelink.h profile.c \
-   profile.h rmspace.c rmspace.h safe_io.c safe_io.h scandirat.c \
-   scandirat.h set.c set.h tree.c tree.h xarray.c xarray.h \
-   xasprintf.h xchdir.c xchdir.h xmkdir.c xmkdir.h xpak.c xpak.h \
-   xregex.c xregex.h xsystem.c xsystem.h $(NULL) $(am__append_1)
+   human_readable.h i18n.h move_file.c move_file.h prelink.c \
+   prelink.h profile.c profile.h rmspace.c rmspace.h safe_io.c \
+   safe_io.h scandirat.c scandirat.h set.c set.h tree.c tree.h \
+   xarray.c xarray.h xasprintf.h xchdir.c xchdir.h xmkdir.c \
+   xmkdir.h xpak.c xpak.h xregex.c xregex.h xsystem.c xsystem.h \
+   $(NULL) $(am__append_1)
 noinst_LTLIBRARIES = libq.la
 libq_la_SOURCES = $(QFILES)
 libq_la_CPPFLAGS = \
@@ -1561,6 +1563,7 @@ distclean-compile:
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libq_la-hash.Plo@am__quote@ # 
am--include-marker
 @AMDEP_TRUE@@am__include@ 
@am__quote@./$(DEPDIR)/libq_la-hash_md5_sha1.Plo@am__quote@ # am--include-marker
 @AMDEP_TRUE@@am__include@ 
@am__quote@./$(DEPDIR)/libq_la-human_readable.Plo@am__quote@ # 
am--include-marker
+@AMDEP_TRUE@@am__include@ 
@am__quote@./$(DEPDIR)/libq_la-move_file.Plo@am__quote@ # am--include-marker
 @AMDEP_TRUE@@am__include@ 
@am__quote@./$(DEPDIR)/libq_la-prelink.Plo@am__quote@ # am--include-marker
 @AMDEP_TRUE@@am__include@ 
@am__quote@./$(DEPDIR)/libq_la-profile.Plo@am__quote@ # am--include-marker
 @AMDEP_TRUE@@am__include@ 
@am__quote@./$(DEPDIR)/libq_la-rmspace.Plo@am__quote@ # am--include-marker
@@ -1665,6 +1668,13 @@ libq_la-human_readable.lo: human_readable.c
 

[gentoo-commits] proj/portage-utils:master commit in: libq/

2021-12-26 Thread Fabian Groffen
commit: 8165933c5b9986b536cf91b8ba82f7e76c9cc758
Author: Fabian Groffen  gentoo  org>
AuthorDate: Sun Dec 26 13:54:21 2021 +
Commit: Fabian Groffen  gentoo  org>
CommitDate: Sun Dec 26 13:54:21 2021 +
URL:https://gitweb.gentoo.org/proj/portage-utils.git/commit/?id=8165933c

libq/move_file: remove source file when done

move suggests the source is gone, so make sure it is :)

Signed-off-by: Fabian Groffen  gentoo.org>

 libq/move_file.c | 7 +--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/libq/move_file.c b/libq/move_file.c
index 07cf69f..b98c8e2 100644
--- a/libq/move_file.c
+++ b/libq/move_file.c
@@ -85,7 +85,7 @@ move_file(int rootfd_src, const char *name_src,
return -1;
}
 
-   /* Preserve the file times */
+   /* preserve the file times */
times[0] = get_stat_atime();
times[1] = get_stat_mtime();
futimens(fd_dst, times);
@@ -93,12 +93,15 @@ move_file(int rootfd_src, const char *name_src,
close(fd_src);
close(fd_dst);
 
-   /* finally move the new tmp dst file to the right place, which
+   /* move the new tmp dst file to the right place, which
 * should be on the same FS/device now */
if (renameat(rootfd_dst, tmpname_dst, rootfd_dst, name_dst)) {
warnp("could not rename %s to %s", tmpname_dst, 
name_dst);
return -1;
}
+
+   /* finally remove the source file */
+   return unlinkat(rootfd_src, name_src, 0);
}
 
return 0;



[gentoo-commits] proj/portage-utils:master commit in: libq/

2021-12-13 Thread Fabian Groffen
commit: 53d7d24872527a69501f4c74a44e16e29aa3bb4a
Author: Fabian Groffen  gentoo  org>
AuthorDate: Mon Dec 13 07:17:04 2021 +
Commit: Fabian Groffen  gentoo  org>
CommitDate: Mon Dec 13 07:17:04 2021 +
URL:https://gitweb.gentoo.org/proj/portage-utils.git/commit/?id=53d7d248

libq/copy_file: employ sendfile() if possible

Signed-off-by: Fabian Groffen  gentoo.org>

 libq/copy_file.c | 78 
 1 file changed, 67 insertions(+), 11 deletions(-)

diff --git a/libq/copy_file.c b/libq/copy_file.c
index e4619ce..955fd78 100644
--- a/libq/copy_file.c
+++ b/libq/copy_file.c
@@ -1,29 +1,85 @@
 /*
- * Copyright 2005-2019 Gentoo Foundation
+ * Copyright 2005-2021 Gentoo Foundation
  * Distributed under the terms of the GNU General Public License v2
  *
  * Copyright 2011-2016 Mike Frysinger  - 
+ * Copyright 2021- Fabian Groffen  - 
  */
 
 #include "main.h"
 #include "safe_io.h"
 #include "copy_file.h"
 
+/* includes for when sendfile is available */
+#include 
+#include 
+#include 
+#include 
+#if defined(HAVE_SENDFILE4_SUPPORT)
+/* Linux/Solaris */
+# include 
+#elif defined(HAVE_SENDFILE6_SUPPORT) || defined(HAVE_SENDFILE7_SUPPORT)
+/* macOS (since Darwin 9) + FreeBSD */
+# include 
+# include 
+#endif
+
 int copy_file_fd(int fd_src, int fd_dst)
 {
-   ssize_t rcnt, wcnt;
-   char buf[64 * 1024];
+#if defined(HAVE_SENDFILE4_SUPPORT) || \
+   defined(HAVE_SENDFILE6_SUPPORT) || \
+   defined(HAVE_SENDFILE7_SUPPORT)
+   struct stat stat_buf;
+   ssize_t ret;
+   size_t  len;
+   off_t   offset = 0;
 
-   while (1) {
-   rcnt = safe_read(fd_src, buf, sizeof(buf));
-   if (rcnt < 0)
-   return -1;
-   else if (rcnt == 0)
+   if (fstat(fd_src, _buf) != -1) {
+   len = (size_t)stat_buf.st_size;
+
+#if defined(HAVE_SENDFILE4_SUPPORT)
+   /* Linux/Solaris */
+   ret = sendfile(fd_dst, fd_src, , len);
+   /* everything looks fine, return success */
+   if (ret == (ssize_t)len)
return 0;
+#elif defined(HAVE_SENDFILE6_SUPPORT)
+   /* macOS (since Darwin 9) */
+   offset = len;
+   ret = (ssize_t)sendfile(fd_src, fd_dst, 0, , NULL, 0);
+   /* everything looks fine, return success */
+   if (offset == (off_t)len)
+   return 0;
+#elif defined(HAVE_SENDFILE7_SUPPORT)
+   /* FreeBSD */
+   ret = (ssize_t)sendfile(fd_src, fd_dst, offset, len, NULL, 
, 0);
+   /* everything looks fine, return success */
+   if (offset == (off_t)len)
+   return 0;
+#endif
 
-   wcnt = safe_write(fd_dst, buf, rcnt);
-   if (wcnt == -1)
-   return -1;
+   /* fall back to read/write, rewind the fd */
+   lseek(fd_src, 0, SEEK_SET);
+   }
+#endif /* HAVE_SENDFILE */
+
+   /* fallback, keep in its own scope, so we avoid 64K stack alloc if
+* sendfile works properly */
+   {
+   ssize_t rcnt, wcnt;
+   char buf[64 * 1024];
+
+   while (1) {
+   rcnt = safe_read(fd_src, buf, sizeof(buf));
+   if (rcnt < 0)
+   return -1;
+   else if (rcnt == 0)
+   return 0;
+
+   wcnt = safe_write(fd_dst, buf, rcnt);
+   if (wcnt == -1)
+   return -1;
+   }
}
 }
 



[gentoo-commits] proj/portage-utils:master commit in: libq/

2021-12-13 Thread Fabian Groffen
commit: 83eaa405a97e45e8cdbf20ad1bb30e82c902d7e2
Author: Fabian Groffen  gentoo  org>
AuthorDate: Mon Dec 13 07:22:30 2021 +
Commit: Fabian Groffen  gentoo  org>
CommitDate: Mon Dec 13 07:22:30 2021 +
URL:https://gitweb.gentoo.org/proj/portage-utils.git/commit/?id=83eaa405

libq/set: allow array_set to be used with an empty set

Signed-off-by: Fabian Groffen  gentoo.org>

 libq/set.c | 5 +
 1 file changed, 5 insertions(+)

diff --git a/libq/set.c b/libq/set.c
index 88b5876..6c9fae0 100644
--- a/libq/set.c
+++ b/libq/set.c
@@ -271,6 +271,11 @@ array_set(set *q, array_t *ret)
array_t blank = array_init_decl;
 
*ret = blank;
+
+   /* allow using empty set */
+   if (q == NULL)
+   return 0;
+
for (i = 0; i < _SET_HASH_SIZE; i++) {
for (w = q->buckets[i]; w != NULL; w = w->next)
xarraypush_ptr(ret, w->name);



[gentoo-commits] proj/portage-utils:master commit in: libq/

2021-11-13 Thread Fabian Groffen
commit: a9872a3fc8b489e5dd96bcaaa57d02738bf6e077
Author: Fabian Groffen  gentoo  org>
AuthorDate: Sat Nov 13 14:26:00 2021 +
Commit: Fabian Groffen  gentoo  org>
CommitDate: Sat Nov 13 14:26:00 2021 +
URL:https://gitweb.gentoo.org/proj/portage-utils.git/commit/?id=a9872a3f

libq/dep: fix inversed logic in dep_prune_use

Signed-off-by: Fabian Groffen  gentoo.org>

 libq/dep.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/libq/dep.c b/libq/dep.c
index 3667ae5..d431367 100644
--- a/libq/dep.c
+++ b/libq/dep.c
@@ -319,7 +319,8 @@ dep_prune_use(dep_node *root, set *use)
dep_prune_use(root->neighbor, use);
if (root->type == DEP_USE) {
bool invert = (root->info[0] == '!' ? 1 : 0);
-   bool notfound = contains_set(root->info + (invert ? 1 : 0), 
use);
+   bool notfound =
+   contains_set(root->info + (invert ? 1 : 0), use) == 
NULL;
 
if (notfound ^ invert) {
root->type = DEP_NULL;



[gentoo-commits] proj/portage-utils:master commit in: libq/

2021-10-09 Thread Fabian Groffen
commit: 023d4496ef445a2f6f05b9c288e9816695d6daf4
Author: Fabian Groffen  gentoo  org>
AuthorDate: Sat Oct  9 12:12:11 2021 +
Commit: Fabian Groffen  gentoo  org>
CommitDate: Sat Oct  9 12:12:11 2021 +
URL:https://gitweb.gentoo.org/proj/portage-utils.git/commit/?id=023d4496

libq/atom: perform correct SUBSLOT matching in compare

fixup after ef14d5f7bb09b8a90e827262798ebd1fde58913a
now SUBSLOT is never NULL, ensure we check it was explicitly set or not,
which is what used to be NULL.

Signed-off-by: Fabian Groffen  gentoo.org>

 libq/atom.c | 10 ++
 1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/libq/atom.c b/libq/atom.c
index 9a51e22..0b5fcdd 100644
--- a/libq/atom.c
+++ b/libq/atom.c
@@ -572,7 +572,9 @@ atom_compare_flg(const depend_atom *data, const depend_atom 
*query, int flags)
if (query->SLOT == NULL && data->SLOT == NULL)
return NOT_EQUAL;
if (query->SLOT != NULL) {
-   if (query->SUBSLOT == NULL || flags & 
ATOM_COMP_NOSUBSLOT) {
+   if (query->SUBSLOT == query->SLOT ||
+   flags & ATOM_COMP_NOSUBSLOT)
+   {
/* ^perl:0 -> match different SLOT */
if (data->SLOT == NULL ||
strcmp(query->SLOT, 
data->SLOT) == 0)
@@ -583,7 +585,7 @@ atom_compare_flg(const depend_atom *data, const depend_atom 
*query, int flags)
strcmp(query->SLOT, 
data->SLOT) != 0)
return NOT_EQUAL;
if (!(flags & ATOM_COMP_NOSUBSLOT))
-   if (data->SUBSLOT == NULL ||
+   if (data->SUBSLOT == 
query->SLOT ||

strcmp(query->SUBSLOT, data->SUBSLOT) == 0)
return NOT_EQUAL;
}
@@ -601,8 +603,8 @@ atom_compare_flg(const depend_atom *data, const depend_atom 
*query, int flags)
if (bl_op == ATOM_BL_NONE)
return NOT_EQUAL;
} else if (!(flags & ATOM_COMP_NOSUBSLOT)) {
-   if (query->SUBSLOT != NULL) {
-   if (data->SUBSLOT == NULL) {
+   if (query->SUBSLOT != query->SLOT) {
+   if (data->SUBSLOT == data->SLOT) {
if (bl_op == ATOM_BL_NONE)
return NOT_EQUAL;
} else {



[gentoo-commits] proj/portage-utils:master commit in: libq/

2021-10-04 Thread Fabian Groffen
commit: 48ca7946e74ed6c1c065589c50327948a41c25b7
Author: Barnabás Virágh  gmail  com>
AuthorDate: Mon Oct  4 06:09:12 2021 +
Commit: Fabian Groffen  gentoo  org>
CommitDate: Mon Oct  4 06:09:12 2021 +
URL:https://gitweb.gentoo.org/proj/portage-utils.git/commit/?id=48ca7946

libq/tree: properly set SUBSLOT value when absent (PMS 7.2)

Bug: https://bugs.gentoo.org/816060
Signed-off-by: Fabian Groffen  gentoo.org>

 libq/tree.c | 7 ++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/libq/tree.c b/libq/tree.c
index 847a343..87df175 100644
--- a/libq/tree.c
+++ b/libq/tree.c
@@ -1613,8 +1613,13 @@ tree_get_atom(tree_pkg_ctx *pkg_ctx, bool complete)
char *ptr;
if ((ptr = strchr(pkg_ctx->atom->SLOT, '/')) != NULL) {
*ptr++ = '\0';
-   pkg_ctx->atom->SUBSLOT = ptr;
+   } else {
+   /* PMS 7.2: When the sub-slot part is omitted 
from the
+* SLOT definition, the package is considered 
to have an
+* implicit sub-slot which is equal to the 
regular slot. */
+   ptr = pkg_ctx->atom->SLOT;
}
+   pkg_ctx->atom->SUBSLOT = ptr;
}
}
 



[gentoo-commits] proj/portage-utils:master commit in: libq/

2021-10-04 Thread Fabian Groffen
commit: ef14d5f7bb09b8a90e827262798ebd1fde58913a
Author: Fabian Groffen  gentoo  org>
AuthorDate: Mon Oct  4 06:28:02 2021 +
Commit: Fabian Groffen  gentoo  org>
CommitDate: Mon Oct  4 06:28:02 2021 +
URL:https://gitweb.gentoo.org/proj/portage-utils.git/commit/?id=ef14d5f7

libq/atom: parse/set SUBSLOT when absent to SLOT (PMS 7.2)

Signed-off-by: Fabian Groffen  gentoo.org>

 libq/atom.c | 22 --
 1 file changed, 16 insertions(+), 6 deletions(-)

diff --git a/libq/atom.c b/libq/atom.c
index d210ed6..9a51e22 100644
--- a/libq/atom.c
+++ b/libq/atom.c
@@ -218,6 +218,10 @@ atom_explode_cat(const char *atom, const char *cat)
/* set to NULL if there's nothing */
if (ret->SLOT[0] == '\0')
ret->SLOT = NULL;
+
+   /* PMS 7.2: SUBSLOT defaults to SLOT when unset */
+   if (ret->SUBSLOT == NULL)
+   ret->SUBSLOT = ret->SLOT;
}
 
/* see if we have any suffix operators */
@@ -380,7 +384,7 @@ atom_clone(depend_atom *atom)
rlen = strlen(atom->REPO) + 1;
if (atom->SLOT != NULL)
slen = strlen(atom->SLOT) + 1;
-   if (atom->SUBSLOT != NULL)
+   if (atom->SUBSLOT != NULL && atom->SUBSLOT != atom->SLOT)
sslen = strlen(atom->SUBSLOT) + 1;
if (atom->CATEGORY != NULL)
clen = strlen(atom->CATEGORY) + 1;
@@ -427,9 +431,13 @@ atom_clone(depend_atom *atom)
p += slen;
}
if (atom->SUBSLOT != NULL) {
-   ret->SUBSLOT = p;
-   memcpy(ret->SUBSLOT, atom->SUBSLOT, sslen);
-   p += sslen;
+   if (atom->SUBSLOT == atom->SLOT) {  /* PMS 7.2 */
+   ret->SUBSLOT = ret->SLOT;
+   } else {
+   ret->SUBSLOT = p;
+   memcpy(ret->SUBSLOT, atom->SUBSLOT, sslen);
+   p += sslen;
+   }
}
if (atom->REPO != NULL) {
ret->REPO = p;
@@ -820,7 +828,8 @@ atom_to_string_r(char *buf, size_t buflen, depend_atom *a)
if (a->SLOT != NULL || a->slotdep != ATOM_SD_NONE)
off += snprintf(buf + off, buflen - off, ":%s%s%s%s",
a->SLOT ? a->SLOT : "",
-   a->SUBSLOT ? "/" : "", a->SUBSLOT ? a->SUBSLOT 
: "",
+   a->SUBSLOT && a->SUBSLOT != a->SLOT ?  "/" : "",
+   a->SUBSLOT && a->SUBSLOT != a->SLOT ? 
a->SUBSLOT : "",
atom_slotdep_str[a->slotdep]);
for (ud = a->usedeps; ud != NULL; ud = ud->next)
off += snprintf(buf + off, buflen - off, "%s%s%s%s%s",
@@ -933,7 +942,8 @@ atom_format_r(
HN(atom->SLOT),
NORM);
} else if (!strncmp("SUBSLOT", fmt, len)) {
-   if (showit || atom->SUBSLOT)
+   if (showit ||
+   (atom->SUBSLOT && 
atom->SUBSLOT != atom->SLOT))
append_buf(buf, buflen, 
"%s%s%s%s%s",
YELLOW,
connected ? "/" 
: "",



[gentoo-commits] proj/portage-utils:master commit in: libq/

2021-10-03 Thread Fabian Groffen
commit: c7e750202c5e17bc8089a8777c4d433b2f63e531
Author: Barnabás Virágh  gmail  com>
AuthorDate: Sun Oct  3 10:47:50 2021 +
Commit: Fabian Groffen  gentoo  org>
CommitDate: Sun Oct  3 10:47:50 2021 +
URL:https://gitweb.gentoo.org/proj/portage-utils.git/commit/?id=c7e75020

libq/atom: fix atom_clone wrt SUBSLOT

A thinko that assumed SUBSLOT was stored in SLOT (which it usually is)
caused it to never be copied, since obviously SLOT is terminated, so
SUBSLOT, even when originally part of SLOT, would never be contained
within SLOT.

Just copy it separately, which has the additional bonus of being less
obscure.

Signed-off-by: Fabian Groffen  gentoo.org>

 libq/atom.c | 12 +---
 1 file changed, 9 insertions(+), 3 deletions(-)

diff --git a/libq/atom.c b/libq/atom.c
index 0959be5..d210ed6 100644
--- a/libq/atom.c
+++ b/libq/atom.c
@@ -373,12 +373,15 @@ atom_clone(depend_atom *atom)
size_t plen = 0;
size_t nlen = 0;
size_t slen = 0;
+   size_t sslen = 0;
size_t rlen = 0;
 
if (atom->REPO != NULL)
rlen = strlen(atom->REPO) + 1;
if (atom->SLOT != NULL)
slen = strlen(atom->SLOT) + 1;
+   if (atom->SUBSLOT != NULL)
+   sslen = strlen(atom->SUBSLOT) + 1;
if (atom->CATEGORY != NULL)
clen = strlen(atom->CATEGORY) + 1;
if (atom->PF != NULL)
@@ -388,7 +391,7 @@ atom_clone(depend_atom *atom)
if (atom->PN != NULL)
nlen = strlen(atom->PN) + 1;
 
-   alen = sizeof(*ret) + clen + flen + plen + nlen + rlen + slen;
+   alen = sizeof(*ret) + clen + flen + plen + nlen + rlen + slen + sslen;
ret = xmalloc(alen);
memset(ret, '\0', sizeof(*ret));
 
@@ -423,8 +426,11 @@ atom_clone(depend_atom *atom)
memcpy(ret->SLOT, atom->SLOT, slen);
p += slen;
}
-   if (atom->SUBSLOT > atom->SLOT && atom->SUBSLOT < (atom->SLOT + slen))
-   ret->SUBSLOT = ret->SLOT + (atom->SUBSLOT - atom->SLOT);
+   if (atom->SUBSLOT != NULL) {
+   ret->SUBSLOT = p;
+   memcpy(ret->SUBSLOT, atom->SUBSLOT, sslen);
+   p += sslen;
+   }
if (atom->REPO != NULL) {
ret->REPO = p;
memcpy(ret->REPO, atom->REPO, rlen);



[gentoo-commits] proj/portage-utils:master commit in: libq/, /

2021-08-16 Thread Fabian Groffen
commit: 18c65792094cb90b6876940b86a35e21e3da488c
Author: Fabian Groffen  gentoo  org>
AuthorDate: Mon Aug 16 13:21:57 2021 +
Commit: Fabian Groffen  gentoo  org>
CommitDate: Mon Aug 16 13:21:57 2021 +
URL:https://gitweb.gentoo.org/proj/portage-utils.git/commit/?id=18c65792

libq/atom: introduce atom_compare_flg

atom_compare_flg allows to give match behaviour flags, such that often
used exceptions can now be handled without having to modify the input
atoms.

atom_compare is now a macro calling atom_compare_flg with
flags=ATOM_COMP_DEFAULT.

Updated all callers that can use this feature.

Signed-off-by: Fabian Groffen  gentoo.org>

 libq/atom.c | 50 --
 libq/atom.h | 10 +-
 qlop.c  | 19 +--
 qmerge.c| 17 +++--
 quse.c  |  8 +++-
 5 files changed, 52 insertions(+), 52 deletions(-)

diff --git a/libq/atom.c b/libq/atom.c
index f4c7c1e..0959be5 100644
--- a/libq/atom.c
+++ b/libq/atom.c
@@ -514,7 +514,7 @@ _atom_compare_match(int ret, atom_operator op)
  * foo-1  bar-1
  */
 atom_equality
-atom_compare(const depend_atom *data, const depend_atom *query)
+atom_compare_flg(const depend_atom *data, const depend_atom *query, int flags)
 {
atom_operator pfx_op;
atom_operator sfx_op;
@@ -551,27 +551,32 @@ atom_compare(const depend_atom *data, const depend_atom 
*query)
 */
bl_op = query->blocker;
if (bl_op == ATOM_BL_ANTISLOT) {
-   /* ^perl -> match anything with a SLOT */
-   if (query->SLOT == NULL && data->SLOT == NULL)
-   return NOT_EQUAL;
-   if (query->SLOT != NULL) {
-   if (query->SUBSLOT == NULL) {
-   /* ^perl:0 -> match different SLOT */
-   if (data->SLOT == NULL ||
-   strcmp(query->SLOT, data->SLOT) 
== 0)
-   return NOT_EQUAL;
-   } else {
-   /* ^perl:0/5.28 -> match SLOT, but different 
SUBSLOT */
-   if (data->SLOT == NULL ||
-   strcmp(query->SLOT, data->SLOT) 
!= 0)
-   return NOT_EQUAL;
-   if (data->SUBSLOT == NULL ||
-   strcmp(query->SUBSLOT, 
data->SUBSLOT) == 0)
-   return NOT_EQUAL;
+   /* just disable/ignore antislot op when SLOT is supposed to be
+* ignored */
+   if (!(flags & ATOM_COMP_NOSLOT)) {
+   /* ^perl -> match anything with a SLOT */
+   if (query->SLOT == NULL && data->SLOT == NULL)
+   return NOT_EQUAL;
+   if (query->SLOT != NULL) {
+   if (query->SUBSLOT == NULL || flags & 
ATOM_COMP_NOSUBSLOT) {
+   /* ^perl:0 -> match different SLOT */
+   if (data->SLOT == NULL ||
+   strcmp(query->SLOT, 
data->SLOT) == 0)
+   return NOT_EQUAL;
+   } else {
+   /* ^perl:0/5.28 -> match SLOT, but 
different SUBSLOT */
+   if (data->SLOT == NULL ||
+   strcmp(query->SLOT, 
data->SLOT) != 0)
+   return NOT_EQUAL;
+   if (!(flags & ATOM_COMP_NOSUBSLOT))
+   if (data->SUBSLOT == NULL ||
+   
strcmp(query->SUBSLOT, data->SUBSLOT) == 0)
+   return NOT_EQUAL;
+   }
}
}
bl_op = ATOM_BL_NONE;  /* ease work below */
-   } else if (query->SLOT != NULL) {
+   } else if (query->SLOT != NULL && !(flags & ATOM_COMP_NOSLOT)) {
/* check SLOT only when query side has it */
if (data->SLOT == NULL) {
if (bl_op == ATOM_BL_NONE)
@@ -581,7 +586,7 @@ atom_compare(const depend_atom *data, const depend_atom 
*query)
/* slot has differs */
if (bl_op == ATOM_BL_NONE)
return NOT_EQUAL;
-   } else {
+   } else if (!(flags & ATOM_COMP_NOSUBSLOT)) {
if (query->SUBSLOT != NULL) {
if (data->SUBSLOT == NULL) {
 

[gentoo-commits] proj/portage-utils:master commit in: libq/

2021-06-23 Thread Fabian Groffen
commit: e0639a1f8654092654520762b58a122506a1fa72
Author: Fabian Groffen  gentoo  org>
AuthorDate: Wed Jun 23 07:12:20 2021 +
Commit: Fabian Groffen  gentoo  org>
CommitDate: Wed Jun 23 07:12:20 2021 +
URL:https://gitweb.gentoo.org/proj/portage-utils.git/commit/?id=e0639a1f

libq/tree: correct macro for tree_foreach_pkg

drop the trailing ; to allow the call to be embedded

Signed-off-by: Fabian Groffen  gentoo.org>

 libq/tree.h | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/libq/tree.h b/libq/tree.h
index 0aa534d..052715b 100644
--- a/libq/tree.h
+++ b/libq/tree.h
@@ -154,9 +154,9 @@ void tree_close_pkg(tree_pkg_ctx *pkg_ctx);
 int tree_foreach_pkg(tree_ctx *ctx, tree_pkg_cb callback, void *priv,
bool sort, const depend_atom *query);
 #define tree_foreach_pkg_fast(ctx, cb, priv, query) \
-   tree_foreach_pkg(ctx, cb, priv, false, query);
+   tree_foreach_pkg(ctx, cb, priv, false, query)
 #define tree_foreach_pkg_sorted(ctx, cb, priv, query) \
-   tree_foreach_pkg(ctx, cb, priv, true, query);
+   tree_foreach_pkg(ctx, cb, priv, true, query)
 set *tree_get_atoms(tree_ctx *ctx, bool fullcpv, set *satoms);
 depend_atom *tree_get_atom(tree_pkg_ctx *pkg_ctx, bool complete);
 tree_match_ctx *tree_match_atom(tree_ctx *t, const depend_atom *q, int flags);



[gentoo-commits] proj/portage-utils:master commit in: libq/

2021-06-14 Thread Fabian Groffen
commit: 493ec668848a3f7dc74001454957205ff9017879
Author: Fabian Groffen  gentoo  org>
AuthorDate: Sat Jun 12 13:56:20 2021 +
Commit: Fabian Groffen  gentoo  org>
CommitDate: Sat Jun 12 13:56:20 2021 +
URL:https://gitweb.gentoo.org/proj/portage-utils.git/commit/?id=493ec668

libq/tree: better tree_match interaction with binpkgs

Signed-off-by: Fabian Groffen  gentoo.org>

 libq/tree.c | 41 -
 1 file changed, 32 insertions(+), 9 deletions(-)

diff --git a/libq/tree.c b/libq/tree.c
index d7ec882..2180867 100644
--- a/libq/tree.c
+++ b/libq/tree.c
@@ -1080,6 +1080,10 @@ static tree_pkg_meta *
 tree_pkg_read(tree_pkg_ctx *pkg_ctx)
 {
tree_ctx *ctx = pkg_ctx->cat_ctx->ctx;
+   tree_pkg_meta *ret = NULL;
+
+   if (pkg_ctx->meta != NULL)
+   return pkg_ctx->meta;
 
if (pkg_ctx->fd == -1) {
if (ctx->cachetype == CACHE_EBUILD || ctx->cachetype == 
CACHE_BINPKGS) {
@@ -1098,19 +1102,22 @@ tree_pkg_read(tree_pkg_ctx *pkg_ctx)
}
 
if (ctx->cachetype == CACHE_METADATA_MD5) {
-   return tree_read_file_md5(pkg_ctx);
+   ret = tree_read_file_md5(pkg_ctx);
} else if (ctx->cachetype == CACHE_METADATA_PMS) {
-   return tree_read_file_pms(pkg_ctx);
+   ret = tree_read_file_pms(pkg_ctx);
} else if (ctx->cachetype == CACHE_EBUILD) {
-   return tree_read_file_ebuild(pkg_ctx);
+   ret = tree_read_file_ebuild(pkg_ctx);
} else if (ctx->cachetype == CACHE_BINPKGS) {
-   return tree_read_file_binpkg(pkg_ctx);
+   ret = tree_read_file_binpkg(pkg_ctx);
} else if (ctx->cachetype == CACHE_PACKAGES) {
-   return (tree_pkg_meta *)pkg_ctx->cat_ctx->ctx->pkgs;
+   ret = (tree_pkg_meta *)pkg_ctx->cat_ctx->ctx->pkgs;
}
 
-   warn("Unknown/unsupported metadata cache type!");
-   return NULL;
+   pkg_ctx->meta = ret;
+
+   if (ret == NULL)
+   warn("Unknown/unsupported metadata cache type!");
+   return ret;
 }
 
 static void
@@ -1204,6 +1211,12 @@ tree_pkg_meta_get_int(tree_pkg_ctx *pkg_ctx, size_t 
offset, const char *keyn)
if (*key == NULL && ctx->cachetype == CACHE_PACKAGES) {
ctx->cachetype = CACHE_BINPKGS;
pkg_ctx->fd = -1;
+
+   /* trigger tree_pkg_read to do something */
+   if ((void *)pkg_ctx->meta != (void 
*)pkg_ctx->cat_ctx->ctx->pkgs)
+   free(pkg_ctx->meta);
+   pkg_ctx->meta = NULL;
+
pkg_ctx->meta = tree_pkg_read(pkg_ctx);
ctx->cachetype = CACHE_PACKAGES;
if (pkg_ctx->meta == NULL) {
@@ -1653,6 +1666,7 @@ tree_match_atom_cache_populate_cb(tree_pkg_ctx *ctx, void 
*priv)
tree_pkg_ctx *pkg;
tree_ctx *tctx = ctx->cat_ctx->ctx;
depend_atom *atom = tree_get_atom(ctx, true);
+   tree_pkg_meta *meta = tree_pkg_read(ctx);
 
(void)priv;
 
@@ -1671,7 +1685,15 @@ tree_match_atom_cache_populate_cb(tree_pkg_ctx *ctx, 
void *priv)
cat_ctx->pkg_ctxs[cat_ctx->pkg_cnt - 1] =
pkg = tree_open_pkg(cat_ctx, atom->PF);
pkg->atom = atom_clone(atom);
-   pkg->name = pkg->atom->PF;
+   pkg->name = xstrdup(pkg->atom->PF);
+   pkg->repo = tctx->repo != NULL ? xstrdup(tctx->repo) : NULL;
+   if (meta != NULL) {
+   pkg->meta = xmalloc(sizeof(*pkg->meta));
+   memcpy(pkg->meta, meta, sizeof(*pkg->meta));
+   pkg->fd = 0;  /* don't try to read, we already got it */
+   } else {
+   pkg->meta = NULL;
+   }
 
return 0;
 }
@@ -1761,7 +1783,8 @@ tree_match_atom(tree_ctx *ctx, depend_atom *query, int 
flags)
snprintf(n->path, sizeof(n->path), "%s/%s/%s%s", \
(char *)C->ctx->path, C->name, 
pkg_ctx->name, \
C->ctx->cachetype == CACHE_EBUILD ? 
".ebuild" : \
-   C->ctx->cachetype == CACHE_BINPKGS ? 
".tbz2" : ""); \
+   C->ctx->cachetype == CACHE_BINPKGS ? 
".tbz2" : \
+   C->ctx->cachetype == CACHE_PACKAGES ? 
".tbz2" : ""); \
if (flags & TREE_MATCH_METADATA) \
n->meta = tree_pkg_read(pkg_ctx); \
n->next = ret; \



[gentoo-commits] proj/portage-utils:master commit in: libq/

2021-06-14 Thread Fabian Groffen
commit: 90fe066073722807b6a48f391e6500b28398830b
Author: Fabian Groffen  gentoo  org>
AuthorDate: Mon Jun 14 09:30:23 2021 +
Commit: Fabian Groffen  gentoo  org>
CommitDate: Mon Jun 14 09:30:23 2021 +
URL:https://gitweb.gentoo.org/proj/portage-utils.git/commit/?id=90fe0660

libq/tree: make tree_match_atom produce valid meta for binpkgs

copy meta appropriately in populate_cb when we deal with binpkgs
directly

Signed-off-by: Fabian Groffen  gentoo.org>

 libq/tree.c | 54 --
 1 file changed, 36 insertions(+), 18 deletions(-)

diff --git a/libq/tree.c b/libq/tree.c
index 5a505f2..847a343 100644
--- a/libq/tree.c
+++ b/libq/tree.c
@@ -546,7 +546,10 @@ tree_next_pkg(tree_cat_ctx *cat_ctx)
tree_ctx *ctx = cat_ctx->ctx;
tree_pkg_ctx *ret = NULL;
 
-   if (ctx->cachetype == CACHE_EBUILD) {
+   if (ctx->do_sort && cat_ctx->pkg_ctxs != NULL) {
+   /* bypass to use the cache if it exists */
+   ret = tree_next_pkg_int(cat_ctx);
+   } else if (ctx->cachetype == CACHE_EBUILD) {
char *p;
 
/* serve *.ebuild files each as separate pkg_ctx with name set
@@ -1600,9 +1603,6 @@ tree_get_atom(tree_pkg_ctx *pkg_ctx, bool complete)
}
pkg_ctx->atom->REPO = pkg_ctx->repo;
}
-
-   if (meta != NULL)
-   tree_close_meta(meta);
}
 
/* this is a bit atom territory, but since we pulled in SLOT we
@@ -1659,12 +1659,12 @@ tree_get_atoms(tree_ctx *ctx, bool fullcpv, set *satoms)
 static int
 tree_match_atom_cache_populate_cb(tree_pkg_ctx *ctx, void *priv)
 {
-   set *cache = priv;
-   tree_cat_ctx *cat_ctx;
-   tree_pkg_ctx *pkg;
-   tree_ctx *tctx = ctx->cat_ctx->ctx;
-   depend_atom *atom = tree_get_atom(ctx, true);
-   tree_pkg_meta *meta = tree_pkg_read(ctx);
+   tree_cat_ctx  *cat_ctx;
+   tree_pkg_ctx  *pkg;
+   set   *cache   = priv;
+   tree_ctx  *tctx= ctx->cat_ctx->ctx;
+   depend_atom   *atom= tree_get_atom(ctx, true);
+   tree_pkg_meta *meta= tree_pkg_read(ctx);
 
(void)priv;
 
@@ -1686,10 +1686,31 @@ tree_match_atom_cache_populate_cb(tree_pkg_ctx *ctx, 
void *priv)
pkg->name = xstrdup(pkg->atom->PF);
pkg->repo = tctx->repo != NULL ? xstrdup(tctx->repo) : NULL;
if (meta != NULL) {
+   pkg->fd = -2;  /* don't try to read, we fill it in here */
pkg->meta = xmalloc(sizeof(*pkg->meta));
memcpy(pkg->meta, meta, sizeof(*pkg->meta));
-   pkg->meta->Q__data = NULL;  /* avoid free here (just to be 
sure) */
-   pkg->fd = -2;  /* don't try to read, we already got it */
+   if (ctx->cat_ctx->ctx->cachetype == CACHE_PACKAGES) {
+   pkg->meta->Q__data = NULL;  /* avoid free here (just to 
be sure) */
+   } else {  /* CACHE_BINPKG */
+   char **newdata;
+   intelems;
+   size_t datasize = (size_t)meta->Q__eclasses_;
+
+   pkg->meta->Q__data = xmalloc(sizeof(char) * datasize);
+   memcpy(pkg->meta->Q__data, meta->Q__data, datasize);
+
+   /* re-position keys */
+   newdata = (char **)pkg->meta;
+   elems   = sizeof(tree_pkg_meta) / sizeof(char *);
+   while (elems-- > 1)  /* skip Q__data itself */
+   if (newdata[elems] != NULL)
+   newdata[elems] = pkg->meta->Q__data +
+   (newdata[elems] - 
meta->Q__data);
+
+   /* drop garbage used for Q__data admin in original case 
*/
+   pkg->meta->Q__eclasses_ = NULL;
+   pkg->meta->Q__md5_  = NULL;
+   }
} else {
pkg->meta = NULL;
}
@@ -1728,12 +1749,9 @@ tree_match_atom(tree_ctx *ctx, const depend_atom *query, 
int flags)
else
cache = create_set();
 
-   if (ctx->cachetype == CACHE_PACKAGES)
-   tree_foreach_packages(ctx,
-   tree_match_atom_cache_populate_cb, 
cache);
-   else  /* BINPKG */
-   tree_foreach_pkg(ctx,
-   tree_match_atom_cache_populate_cb, 
cache, true, NULL);
+   tree_foreach_pkg(ctx,
+   tree_match_atom_cache_populate_cb, cache, true, 
NULL);
+
ctx->do_sort = true;  /* turn it back on */
ctx->cache.all_categories = true;
 



[gentoo-commits] proj/portage-utils:master commit in: libq/

2021-06-14 Thread Fabian Groffen
commit: 3cd1221ff6fdd8b3af243f390569b6e61bfd9e18
Author: Fabian Groffen  gentoo  org>
AuthorDate: Sat Jun 12 20:03:13 2021 +
Commit: Fabian Groffen  gentoo  org>
CommitDate: Sat Jun 12 20:03:13 2021 +
URL:https://gitweb.gentoo.org/proj/portage-utils.git/commit/?id=3cd1221f

libq/tree: fix double free/use after free scenarios

- ensure we don't reuse pointers too many so we end up freeing the wrong
  thing
- don't free atom and meta in case of cached pkg_ctx

Signed-off-by: Fabian Groffen  gentoo.org>

 libq/tree.c | 39 ---
 libq/tree.h |  5 -
 2 files changed, 24 insertions(+), 20 deletions(-)

diff --git a/libq/tree.c b/libq/tree.c
index 39beac8..a247f66 100644
--- a/libq/tree.c
+++ b/libq/tree.c
@@ -162,11 +162,11 @@ tree_open_binpkg(const char *sroot, const char *spkg)
ret->cachetype = CACHE_BINPKGS;
 
fd = openat(ret->tree_fd, binpkg_packages, O_RDONLY | 
O_CLOEXEC);
-   if (eat_file_fd(fd, >pkgs, >pkgslen)) {
+   if (eat_file_fd(fd, >cache.store, >cache.storesize)) {
ret->cachetype = CACHE_PACKAGES;
-   } else if (ret->pkgs != NULL) {
-   free(ret->pkgs);
-   ret->pkgs = NULL;
+   } else if (ret->cache.store != NULL) {
+   free(ret->cache.store);
+   ret->cache.store = NULL;
}
close(fd);
}
@@ -1358,14 +1358,13 @@ tree_foreach_packages(tree_ctx *ctx, tree_pkg_cb 
callback, void *priv)
depend_atom *atom = NULL;
 
/* re-read the contents, this is necessary to make it possible to
-* call this function multiple times
-* TODO: generate an internal in-memory tree when cache is enabled */
-   if (ctx->pkgs == NULL || ctx->pkgs[0] == '\0') {
+* call this function multiple times */
+   if (ctx->cache.store == NULL || ctx->cache.store[0] == '\0') {
int fd = openat(ctx->tree_fd, binpkg_packages, O_RDONLY | 
O_CLOEXEC);
-   if (!eat_file_fd(fd, >pkgs, >pkgslen)) {
-   if (ctx->pkgs != NULL) {
-   free(ctx->pkgs);
-   ctx->pkgs = NULL;
+   if (!eat_file_fd(fd, >cache.store, >cache.storesize)) 
{
+   if (ctx->cache.store != NULL) {
+   free(ctx->cache.store);
+   ctx->cache.store = NULL;
}
close(fd);
return 1;
@@ -1373,8 +1372,8 @@ tree_foreach_packages(tree_ctx *ctx, tree_pkg_cb 
callback, void *priv)
close(fd);
}
 
-   p = ctx->pkgs;
-   len = strlen(ctx->pkgs);  /* sucks, need eat_file change */
+   p = ctx->cache.store;
+   len = strlen(ctx->cache.store);  /* sucks, need eat_file change */
 
memset(, 0, sizeof(meta));
 
@@ -1396,9 +1395,8 @@ tree_foreach_packages(tree_ctx *ctx, tree_pkg_cb 
callback, void *priv)
 
memset(, 0, sizeof(pkg));
 
-   /* store meta ptr in repo->pkgs, such that 
get_pkg_meta
+   /* store meta ptr in ctx->pkgs, such that 
get_pkg_meta
 * can grab it from there (for free) */
-   c = ctx->pkgs;
ctx->pkgs = (char *)
 
if (cat == NULL || strcmp(cat->name, 
atom->CATEGORY) != 0)
@@ -1429,7 +1427,7 @@ tree_foreach_packages(tree_ctx *ctx, tree_pkg_cb 
callback, void *priv)
/* do call callback with pkg_atom (populate cat 
and pkg) */
ret |= callback(, priv);
 
-   ctx->pkgs = c;
+   ctx->pkgs = NULL;
if (atom != (depend_atom *)cat->pkg_ctxs)
atom_implode(atom);
}
@@ -1505,7 +1503,7 @@ tree_foreach_packages(tree_ctx *ctx, tree_pkg_cb 
callback, void *priv)
/* ensure we don't free a garbage pointer */
ctx->repo = NULL;
ctx->do_sort = false;
-   ctx->pkgs[0] = '\0';
+   ctx->cache.store[0] = '\0';
 
return ret;
 }
@@ -1690,7 +1688,7 @@ tree_match_atom_cache_populate_cb(tree_pkg_ctx *ctx, void 
*priv)
if (meta != NULL) {
pkg->meta = xmalloc(sizeof(*pkg->meta));
memcpy(pkg->meta, meta, sizeof(*pkg->meta));
-   pkg->meta->Q__data = NULL;  /* avoid free here */
+   pkg->meta->Q__data = NULL;  /* avoid free here (just to be 
sure) */
pkg->fd = -2;  /* don't try to read, we already got it */
} else {
pkg->meta = NULL;
@@ -1788,6 +1786,9 @@ tree_match_atom(tree_ctx *ctx, depend_atom *query, int 
flags)
 

[gentoo-commits] proj/portage-utils:master commit in: libq/

2021-06-14 Thread Fabian Groffen
commit: e8f5295c91f6e818455eac7414b17965ccbba061
Author: Fabian Groffen  gentoo  org>
AuthorDate: Sun Jun 13 15:05:23 2021 +
Commit: Fabian Groffen  gentoo  org>
CommitDate: Sun Jun 13 15:05:23 2021 +
URL:https://gitweb.gentoo.org/proj/portage-utils.git/commit/?id=e8f5295c

libq/tree: make some declarations const

Signed-off-by: Fabian Groffen  gentoo.org>

 libq/tree.c | 9 +
 libq/tree.h | 7 ---
 2 files changed, 9 insertions(+), 7 deletions(-)

diff --git a/libq/tree.c b/libq/tree.c
index a247f66..5a505f2 100644
--- a/libq/tree.c
+++ b/libq/tree.c
@@ -468,7 +468,7 @@ tree_next_pkg_int(tree_cat_ctx *cat_ctx)
 {
tree_pkg_ctx *pkg_ctx = NULL;
const struct dirent *de;
-   depend_atom *qa = cat_ctx->ctx->query_atom;
+   const depend_atom *qa = cat_ctx->ctx->query_atom;
 
if (cat_ctx->ctx->do_sort) {
if (cat_ctx->pkg_ctxs == NULL) {
@@ -1349,7 +1349,7 @@ tree_foreach_packages(tree_ctx *ctx, tree_pkg_cb 
callback, void *priv)
char pkgname[_Q_PATH_MAX];
size_t len;
int ret = 0;
-   depend_atom *query = ctx->query_atom;
+   const depend_atom *query = ctx->query_atom;
 
/* reused for every entry */
tree_cat_ctx *cat = NULL;
@@ -1510,7 +1510,7 @@ tree_foreach_packages(tree_ctx *ctx, tree_pkg_cb 
callback, void *priv)
 
 int
 tree_foreach_pkg(tree_ctx *ctx, tree_pkg_cb callback, void *priv,
-   bool sort, depend_atom *query)
+   bool sort, const depend_atom *query)
 {
tree_cat_ctx *cat_ctx;
tree_pkg_ctx *pkg_ctx;
@@ -1698,7 +1698,7 @@ tree_match_atom_cache_populate_cb(tree_pkg_ctx *ctx, void 
*priv)
 }
 
 tree_match_ctx *
-tree_match_atom(tree_ctx *ctx, depend_atom *query, int flags)
+tree_match_atom(tree_ctx *ctx, const depend_atom *query, int flags)
 {
tree_cat_ctx *cat_ctx;
tree_pkg_ctx *pkg_ctx;
@@ -1779,6 +1779,7 @@ tree_match_atom(tree_ctx *ctx, depend_atom *query, int 
flags)
/* create a new match result */ \
n = xzalloc(sizeof(tree_match_ctx)); \
n->atom = atom; \
+   n->pkg = pkg_ctx; \
snprintf(n->path, sizeof(n->path), "%s/%s/%s%s", \
(char *)C->ctx->path, C->name, 
pkg_ctx->name, \
C->ctx->cachetype == CACHE_EBUILD ? 
".ebuild" : \

diff --git a/libq/tree.h b/libq/tree.h
index 1f28205..0aa534d 100644
--- a/libq/tree.h
+++ b/libq/tree.h
@@ -45,7 +45,7 @@ struct tree_ctx {
char *repo;
char *pkgs;
size_t pkgslen;
-   depend_atom *query_atom;
+   const depend_atom *query_atom;
struct tree_cache {
char *store;
size_t storesize;
@@ -125,6 +125,7 @@ struct tree_metadata_xml {
  * (populated and deep copied) when set */
 struct tree_match_ctx {
depend_atom *atom;
+   tree_pkg_ctx *pkg;
tree_pkg_meta *meta;
char path[_Q_PATH_MAX + 48];
tree_match_ctx *next;
@@ -151,14 +152,14 @@ tree_metadata_xml *tree_pkg_metadata(tree_pkg_ctx 
*pkg_ctx);
 void tree_close_metadata(tree_metadata_xml *meta_ctx);
 void tree_close_pkg(tree_pkg_ctx *pkg_ctx);
 int tree_foreach_pkg(tree_ctx *ctx, tree_pkg_cb callback, void *priv,
-   bool sort, depend_atom *query);
+   bool sort, const depend_atom *query);
 #define tree_foreach_pkg_fast(ctx, cb, priv, query) \
tree_foreach_pkg(ctx, cb, priv, false, query);
 #define tree_foreach_pkg_sorted(ctx, cb, priv, query) \
tree_foreach_pkg(ctx, cb, priv, true, query);
 set *tree_get_atoms(tree_ctx *ctx, bool fullcpv, set *satoms);
 depend_atom *tree_get_atom(tree_pkg_ctx *pkg_ctx, bool complete);
-tree_match_ctx *tree_match_atom(tree_ctx *t, depend_atom *q, int flags);
+tree_match_ctx *tree_match_atom(tree_ctx *t, const depend_atom *q, int flags);
 #define TREE_MATCH_FULL_ATOM  (1<<1)
 #define TREE_MATCH_METADATA   (1<<2)
 #define TREE_MATCH_LATEST (1<<3)



[gentoo-commits] proj/portage-utils:master commit in: libq/

2021-06-14 Thread Fabian Groffen
commit: 9a4c654be5e759b4bb0fed1ac802a57fb1cb5c30
Author: Fabian Groffen  gentoo  org>
AuthorDate: Tue Jun  8 15:28:47 2021 +
Commit: Fabian Groffen  gentoo  org>
CommitDate: Tue Jun  8 15:28:47 2021 +
URL:https://gitweb.gentoo.org/proj/portage-utils.git/commit/?id=9a4c654b

libq/tree: build cache for Packages/binpkgs

Because we cannot trust Packages file to be in sorted order, and the
order isn't what we want (most recent match on top), we have to sort the
pkgs found in Packages, so make that exploit the cache, which will speed
up any subsequent tree_match_atom calls, which is good.

Do the same for binpkg trees, since they also cannot be cached
otherwise.

Signed-off-by: Fabian Groffen  gentoo.org>

 libq/tree.c | 180 ++--
 libq/tree.h |   1 +
 2 files changed, 90 insertions(+), 91 deletions(-)

diff --git a/libq/tree.c b/libq/tree.c
index 358b1f2..d7ec882 100644
--- a/libq/tree.c
+++ b/libq/tree.c
@@ -312,8 +312,29 @@ tree_next_cat(tree_ctx *ctx)
 
if (ctx->do_sort) {
if (ctx->cat_de == NULL) {
-   ctx->cat_cnt = scandirat(ctx->tree_fd,
-   ".", >cat_de, tree_filter_cat, 
alphasort);
+   if (ctx->cache.all_categories) {
+   char **cats;
+   size_t i;
+   size_t len;
+   struct dirent **ret;
+
+   /* exploit the cache instead of reading from 
directory */
+   ctx->cat_cnt = cnt_set(ctx->cache.categories);
+   ctx->cat_de = ret = xmalloc(sizeof(*ret) * 
ctx->cat_cnt);
+   list_set(ctx->cache.categories, );
+   for (i = 0; i < ctx->cat_cnt; i++) {
+   len = strlen(cats[i]) + 1;
+   ret[i] = xzalloc(sizeof(*de) + len);
+   snprintf(ret[i]->d_name, len, "%s", 
cats[i]);
+   }
+   if (i > 1)
+   qsort(ret, ctx->cat_cnt, sizeof(*ret),
+   (int (*)(const void *, 
const void *))alphasort);
+   free(cats);
+   } else {
+   ctx->cat_cnt = scandirat(ctx->tree_fd,
+   ".", >cat_de, 
tree_filter_cat, alphasort);
+   }
ctx->cat_cur = 0;
}
 
@@ -1511,7 +1532,7 @@ tree_foreach_pkg(tree_ctx *ctx, tree_pkg_cb callback, 
void *priv,
ctx->cat_de = NULL;
ctx->cat_cur = 0;
ctx->cat_cnt = 0;
-   ctx->do_sort = 0;
+   ctx->do_sort = false;
 
return ret;
 }
@@ -1624,77 +1645,33 @@ tree_get_atoms(tree_ctx *ctx, bool fullcpv, set *satoms)
return state.cpf;
 }
 
-struct tree_match_pkgs_cb_ctx {
-   int flags;
-   tree_match_ctx *ret;
-};
-
 static int
-tree_match_atom_packages_cb(tree_pkg_ctx *ctx, void *priv)
+tree_match_atom_cache_populate_cb(tree_pkg_ctx *ctx, void *priv)
 {
-   struct tree_match_pkgs_cb_ctx *rctx = priv;
-   depend_atom *a;
-   tree_match_ctx *n;
-
-   /* skip anything after finding first match */
-   if (rctx->flags & TREE_MATCH_FIRST && rctx->ret != NULL)
-   return 1;
-
-   a = tree_get_atom(ctx, rctx->flags & TREE_MATCH_FULL_ATOM);
-
-   /* skip virtual category if not requested */
-   if (!(rctx->flags & TREE_MATCH_VIRTUAL) &&
-   strcmp(a->CATEGORY, "virtual") == 0)
-   return 1;
-
-   n = xzalloc(sizeof(tree_match_ctx));
-   n->free_atom = true;
-   n->atom = atom_clone(a);
-   snprintf(n->path, sizeof(n->path), "%s/%s/%s.tbz2",
-   (char *)ctx->cat_ctx->ctx->path, ctx->cat_ctx->name, 
ctx->name);
-   if (rctx->flags & TREE_MATCH_METADATA) {
-   n->meta = xmalloc(sizeof(*n->meta));
-   /* for Packages, all pointers to meta here are to the in memory
-* copy of the Packages file, so these pointers can just be
-* copied since the tree has to remain open, thus the pointers
-* will stay valid */
-   memcpy(n->meta, ctx->cat_ctx->ctx->pkgs, sizeof(*n->meta));
+   set *cache = priv;
+   tree_cat_ctx *cat_ctx;
+   tree_pkg_ctx *pkg;
+   tree_ctx *tctx = ctx->cat_ctx->ctx;
+   depend_atom *atom = tree_get_atom(ctx, true);
+
+   (void)priv;
+
+   cat_ctx = get_set(atom->CATEGORY, cache);
+   if (cat_ctx == NULL) {
+   cat_ctx = tree_open_cat(tctx, ".");
+   add_set_value(atom->CATEGORY, cat_ctx, cache);
+   /* get a pointer from the set */
+

[gentoo-commits] proj/portage-utils:master commit in: libq/

2021-06-14 Thread Fabian Groffen
commit: f3ce28b07839e478051947ae7f04bc4b798c1345
Author: Fabian Groffen  gentoo  org>
AuthorDate: Sat Jun 12 15:37:46 2021 +
Commit: Fabian Groffen  gentoo  org>
CommitDate: Sat Jun 12 15:37:46 2021 +
URL:https://gitweb.gentoo.org/proj/portage-utils.git/commit/?id=f3ce28b0

libq/tree: avoid crash in tree_close_pkg on virtuals

Signed-off-by: Fabian Groffen  gentoo.org>

 libq/tree.c | 9 +
 1 file changed, 5 insertions(+), 4 deletions(-)

diff --git a/libq/tree.c b/libq/tree.c
index 2180867..39beac8 100644
--- a/libq/tree.c
+++ b/libq/tree.c
@@ -1221,7 +1221,7 @@ tree_pkg_meta_get_int(tree_pkg_ctx *pkg_ctx, size_t 
offset, const char *keyn)
ctx->cachetype = CACHE_PACKAGES;
if (pkg_ctx->meta == NULL) {
/* hrm. */
-   pkg_ctx->fd = 0;
+   pkg_ctx->fd = -2;
pkg_ctx->meta = tree_pkg_read(pkg_ctx);
}
key = (char **)((char *)_ctx->meta->Q__data + 
offset);
@@ -1324,7 +1324,7 @@ tree_close_metadata(tree_metadata_xml *meta_ctx)
 void
 tree_close_pkg(tree_pkg_ctx *pkg_ctx)
 {
-   if (pkg_ctx->fd != -1)
+   if (pkg_ctx->fd >= 0)
close(pkg_ctx->fd);
if (pkg_ctx->atom != NULL)
atom_implode(pkg_ctx->atom);
@@ -1424,7 +1424,7 @@ tree_foreach_packages(tree_ctx *ctx, tree_pkg_cb 
callback, void *priv)
pkg.repo = ctx->repo;
pkg.atom = atom;
pkg.cat_ctx = cat;
-   pkg.fd = 0;  /* intentional, meta has already 
been read */
+   pkg.fd = -2;  /* intentional, meta has already 
been read */
 
/* do call callback with pkg_atom (populate cat 
and pkg) */
ret |= callback(, priv);
@@ -1690,7 +1690,8 @@ tree_match_atom_cache_populate_cb(tree_pkg_ctx *ctx, void 
*priv)
if (meta != NULL) {
pkg->meta = xmalloc(sizeof(*pkg->meta));
memcpy(pkg->meta, meta, sizeof(*pkg->meta));
-   pkg->fd = 0;  /* don't try to read, we already got it */
+   pkg->meta->Q__data = NULL;  /* avoid free here */
+   pkg->fd = -2;  /* don't try to read, we already got it */
} else {
pkg->meta = NULL;
}



[gentoo-commits] proj/portage-utils:master commit in: libq/

2021-06-01 Thread Fabian Groffen
commit: 4fd296d65c76ceb98f69ff392c2ae0f31bd18d54
Author: Fabian Groffen  gentoo  org>
AuthorDate: Tue Jun  1 19:38:52 2021 +
Commit: Fabian Groffen  gentoo  org>
CommitDate: Tue Jun  1 19:38:52 2021 +
URL:https://gitweb.gentoo.org/proj/portage-utils.git/commit/?id=4fd296d6

libq/tree: fix empty cat_ctx and path when using binpkgs

- ensure cat_ctx is set for each pkg coming from Packages file
- set path in each tree match

Signed-off-by: Fabian Groffen  gentoo.org>

 libq/tree.c | 6 +-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/libq/tree.c b/libq/tree.c
index c00f251..358b1f2 100644
--- a/libq/tree.c
+++ b/libq/tree.c
@@ -1380,7 +1380,6 @@ tree_foreach_packages(tree_ctx *ctx, tree_pkg_cb 
callback, void *priv)
 * generate a dummy cat */
cat = tree_open_cat(ctx, ".");
}
-   pkg.cat_ctx = cat;
cat->pkg_ctxs = (tree_pkg_ctx **)atom;  
/* for name */
}
pkgnamelen = snprintf(pkgname, sizeof(pkgname),
@@ -1390,6 +1389,7 @@ tree_foreach_packages(tree_ctx *ctx, tree_pkg_cb 
callback, void *priv)
pkg.slot = meta.Q_SLOT == NULL ? (char *)"0" : 
meta.Q_SLOT;
pkg.repo = ctx->repo;
pkg.atom = atom;
+   pkg.cat_ctx = cat;
pkg.fd = 0;  /* intentional, meta has already 
been read */
 
/* do call callback with pkg_atom (populate cat 
and pkg) */
@@ -1650,6 +1650,8 @@ tree_match_atom_packages_cb(tree_pkg_ctx *ctx, void *priv)
n = xzalloc(sizeof(tree_match_ctx));
n->free_atom = true;
n->atom = atom_clone(a);
+   snprintf(n->path, sizeof(n->path), "%s/%s/%s.tbz2",
+   (char *)ctx->cat_ctx->ctx->path, ctx->cat_ctx->name, 
ctx->name);
if (rctx->flags & TREE_MATCH_METADATA) {
n->meta = xmalloc(sizeof(*n->meta));
/* for Packages, all pointers to meta here are to the in memory
@@ -1686,6 +1688,8 @@ tree_match_atom_binpkg_cb(tree_pkg_ctx *ctx, void *priv)
n = xzalloc(sizeof(tree_match_ctx));
n->free_atom = true;
n->atom = atom_clone(a);
+   snprintf(n->path, sizeof(n->path), "%s/%s/%s.tbz2",
+   (char *)ctx->cat_ctx->ctx->path, ctx->cat_ctx->name, 
ctx->name);
if (rctx->flags & TREE_MATCH_METADATA)
n->meta = tree_pkg_read(ctx);
 



[gentoo-commits] proj/portage-utils:master commit in: libq/

2021-05-23 Thread Fabian Groffen
commit: 6e42f76862860f19674fe1f87d9a7087acfa742e
Author: Fabian Groffen  gentoo  org>
AuthorDate: Sun May 23 10:54:00 2021 +
Commit: Fabian Groffen  gentoo  org>
CommitDate: Sun May 23 10:54:00 2021 +
URL:https://gitweb.gentoo.org/proj/portage-utils.git/commit/?id=6e42f768

libq/tree: silence warning about unknown keys in md5 cache format

Bug: https://bugs.gentoo.org/791571
Signed-off-by: Fabian Groffen  gentoo.org>

 libq/tree.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/libq/tree.c b/libq/tree.c
index f66059b..c00f251 100644
--- a/libq/tree.c
+++ b/libq/tree.c
@@ -785,8 +785,8 @@ tree_read_file_md5(tree_pkg_ctx *pkg_ctx)
assign_var(EPREFIX);
assign_var(_eclasses_);
assign_var(_md5_);
-   warn("Cache file for '%s/%s' has unknown key %s",
-   pkg_ctx->cat_ctx->name, pkg_ctx->name, keyptr);
+   IF_DEBUG(warn("Cache file for '%s/%s' has unknown key %s",
+   pkg_ctx->cat_ctx->name, pkg_ctx->name, 
keyptr));
}
 #undef assign_var
 #undef assign_var_cmp



[gentoo-commits] proj/portage-utils:master commit in: libq/

2021-05-10 Thread Fabian Groffen
commit: 09e2ac80fc030013031135bc3ffad19360920d6f
Author: Fabian Groffen  gentoo  org>
AuthorDate: Mon May 10 09:11:25 2021 +
Commit: Fabian Groffen  gentoo  org>
CommitDate: Mon May 10 09:11:25 2021 +
URL:https://gitweb.gentoo.org/proj/portage-utils.git/commit/?id=09e2ac80

libq/colors: add color_clear()

allow calling color_clear()/color_remap() repeatedly to disable/enable
colour escapes (this is necessary for the delayed argument handling by
the applets)

Signed-off-by: Fabian Groffen  gentoo.org>

 libq/colors.c | 92 +++
 libq/colors.h |  3 +-
 2 files changed, 63 insertions(+), 32 deletions(-)

diff --git a/libq/colors.c b/libq/colors.c
index 9a48e2e..6f3d7f1 100644
--- a/libq/colors.c
+++ b/libq/colors.c
@@ -1,5 +1,5 @@
 /*
- * Copyright 2005-2019 Gentoo Foundation
+ * Copyright 2005-2021 Gentoo Foundation
  * Distributed under the terms of the GNU General Public License v2
  *
  * Copyright 2005-2010 Ned Ludd- 
@@ -17,24 +17,22 @@
 #else
 # define _MAKE_COLOR(c,b) "\e[" c ";" b "m"
 #endif
-const char *BOLD = _MAKE_COLOR("00", "01");
-const char *NORM = _MAKE_COLOR("00", "00");
-const char *BLUE = _MAKE_COLOR("36", "01");
-const char *DKBLUE = _MAKE_COLOR("34", "01");
-const char *CYAN = _MAKE_COLOR("00", "36");
-const char *GREEN = _MAKE_COLOR("32", "01");
-const char *DKGREEN = _MAKE_COLOR("00", "32");
-const char *MAGENTA = _MAKE_COLOR("00", "35");
-const char *RED = _MAKE_COLOR("31", "01");
-const char *YELLOW = _MAKE_COLOR("33", "01");
-const char *BRYELLOW = _MAKE_COLOR("01", "33");
-const char *WHITE = _MAKE_COLOR("01", "38");
+const char *NORM;
+const char *BLUE;
+const char *BOLD;
+const char *BRYELLOW;
+const char *CYAN;
+const char *DKBLUE;
+const char *DKGREEN;
+const char *GREEN;
+const char *MAGENTA;
+const char *RED;
+const char *WHITE;
+const char *YELLOW;
 
 static const char *COLOR_MAP = CONFIG_EPREFIX "etc/portage/color.map";
 
-#define COLOR _MAKE_COLOR
 #define CPAIR_VALUE_LEN 16
-
 typedef struct {
const char *name;
char value[CPAIR_VALUE_LEN];
@@ -43,22 +41,22 @@ typedef struct {
 
 #define X2(X) X, X
 static cpairtype color_pairs[] = {
-   {"blue",  X2(COLOR("34", "01")) },
-   {"brown", X2(COLOR("00", "33")) },
-   {"darkblue",  X2(COLOR("00", "34")) },
-   {"darkgreen", X2(COLOR("00", "32")) },
-   {"darkred",   X2(COLOR("00", "31")) },
-   {"faint", X2(COLOR("00", "02")) },
-   {"fuchsia",   X2(COLOR("35", "01")) },
-   {"green", X2(COLOR("32", "01")) },
-   {"purple",X2(COLOR("00", "35")) },
-   {"red",   X2(COLOR("31", "01")) },
-   {"teal",  X2(COLOR("00", "36")) },
-   {"turquoise", X2(COLOR("36", "01")) },
-   {"yellow",X2(COLOR("01", "33")) },
-   {"white", X2(COLOR("01", "38")) },
-   {"lightgray", X2(COLOR("00", "37")) },
-   {"eol",   X2(COLOR("00", "00")) },
+   {"blue",  X2(_MAKE_COLOR("34", "01")) },
+   {"brown", X2(_MAKE_COLOR("00", "33")) },
+   {"darkblue",  X2(_MAKE_COLOR("00", "34")) },
+   {"darkgreen", X2(_MAKE_COLOR("00", "32")) },
+   {"darkred",   X2(_MAKE_COLOR("00", "31")) },
+   {"faint", X2(_MAKE_COLOR("00", "02")) },
+   {"fuchsia",   X2(_MAKE_COLOR("35", "01")) },
+   {"green", X2(_MAKE_COLOR("32", "01")) },
+   {"lightgray", X2(_MAKE_COLOR("00", "37")) },
+   {"purple",X2(_MAKE_COLOR("00", "35")) },
+   {"red",   X2(_MAKE_COLOR("31", "01")) },
+   {"teal",  X2(_MAKE_COLOR("00", "36")) },
+   {"turquoise", X2(_MAKE_COLOR("36", "01")) },
+   {"white", X2(_MAKE_COLOR("01", "38")) },
+   {"yellow",X2(_MAKE_COLOR("01", "33")) },
+   {"eol",   X2(_MAKE_COLOR("00", "00")) },
 };
 #undef X2
 
@@ -73,6 +71,21 @@ color_remap(void)
char *p;
unsigned int lineno = 0;
 
+   /* set q's defaults, if there's no colormap, or the file is empty,
+* or it doesn't match things, we at least got some defaults */
+   NORM = _MAKE_COLOR("00", "00");
+   BLUE = _MAKE_COLOR("36", "01");
+   BOLD = _MAKE_COLOR("00", "01");
+   BRYELLOW = _MAKE_COLOR("01", "33");
+   CYAN = _MAKE_COLOR("00", "36");
+   DKBLUE   = _MAKE_COLOR("34", "01");
+   DKGREEN  = _MAKE_COLOR("00", "32");
+   GREEN= _MAKE_COLOR("32", "01");
+   MAGENTA  = _MAKE_COLOR("00", "35");
+   RED  = _MAKE_COLOR("31", "01");
+   WHITE= _MAKE_COLOR("01", "38");
+   YELLOW   = _MAKE_COLOR("33", "01");
+
if ((fp = fopen(COLOR_MAP, "r")) == NULL)
return;
 
@@ -141,3 +154,20 @@ color_remap(void)
CYAN = color_pairs[i].value;
}
 }
+
+void
+color_clear(void)
+{
+   NORM = "";
+   BLUE = "";
+   BOLD = "";
+   BRYELLOW = "";
+   CYAN = "";
+   DKBLUE   = "";
+   DKGREEN  = "";
+   GREEN= "";
+   

[gentoo-commits] proj/portage-utils:master commit in: libq/

2021-04-29 Thread Fabian Groffen
commit: 7bbb7d1237d4fc6380c29059c7b0531d2adf0ee4
Author: Fabian Groffen  gentoo  org>
AuthorDate: Thu Apr 29 15:03:18 2021 +
Commit: Fabian Groffen  gentoo  org>
CommitDate: Thu Apr 29 15:03:18 2021 +
URL:https://gitweb.gentoo.org/proj/portage-utils.git/commit/?id=7bbb7d12

libq/tree: return all pkgs found in Packages file, whether or not existant

Signed-off-by: Fabian Groffen  gentoo.org>

 libq/tree.c | 15 +--
 1 file changed, 5 insertions(+), 10 deletions(-)

diff --git a/libq/tree.c b/libq/tree.c
index e692ee9..f66059b 100644
--- a/libq/tree.c
+++ b/libq/tree.c
@@ -1374,18 +1374,13 @@ tree_foreach_packages(tree_ctx *ctx, tree_pkg_cb 
callback, void *priv)
cat->pkg_ctxs = NULL;
tree_close_cat(cat);
}
-   pkg.cat_ctx = cat = tree_open_cat(ctx, 
atom->CATEGORY);
+   cat = tree_open_cat(ctx, 
atom->CATEGORY);
if (cat == NULL) {
-   /* probably dir doesn't exist 
or something, skip
-* this one */
-   memset(, 0, sizeof(meta));
-   if (len > 0) {  /* hop over \n 
*/
-   p++;
-   len--;
-   }
-   ctx->pkgs = c;
-   continue;
+   /* probably dir doesn't exist 
or something,
+* generate a dummy cat */
+   cat = tree_open_cat(ctx, ".");
}
+   pkg.cat_ctx = cat;
cat->pkg_ctxs = (tree_pkg_ctx **)atom;  
/* for name */
}
pkgnamelen = snprintf(pkgname, sizeof(pkgname),



[gentoo-commits] proj/portage-utils:master commit in: libq/

2021-04-29 Thread Fabian Groffen
commit: 76007ed6b28a5bc8c9b108bdf141fd31357fde6c
Author: Fabian Groffen  gentoo  org>
AuthorDate: Thu Apr 29 13:46:37 2021 +
Commit: Fabian Groffen  gentoo  org>
CommitDate: Thu Apr 29 13:46:37 2021 +
URL:https://gitweb.gentoo.org/proj/portage-utils.git/commit/?id=76007ed6

tree: avoid crash at close when a binpkg is skipped

this fixes up the previous commit 09b8177

Signed-off-by: Fabian Groffen  gentoo.org>

 libq/tree.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/libq/tree.c b/libq/tree.c
index 04bf468..e692ee9 100644
--- a/libq/tree.c
+++ b/libq/tree.c
@@ -1383,6 +1383,7 @@ tree_foreach_packages(tree_ctx *ctx, tree_pkg_cb 
callback, void *priv)
p++;
len--;
}
+   ctx->pkgs = c;
continue;
}
cat->pkg_ctxs = (tree_pkg_ctx **)atom;  
/* for name */



[gentoo-commits] proj/portage-utils:master commit in: libq/

2021-04-29 Thread Fabian Groffen
commit: 09b817763d3b03d9ccee92ddd4fa13edb82d53a9
Author: Fabian Groffen  gentoo  org>
AuthorDate: Thu Apr 29 13:23:27 2021 +
Commit: Fabian Groffen  gentoo  org>
CommitDate: Thu Apr 29 13:23:27 2021 +
URL:https://gitweb.gentoo.org/proj/portage-utils.git/commit/?id=09b81776

tree: avoid crash in tree_foreach_packages when category doesn't exist

This can be observed when reading a Packages file that refers to binpkgs
that do not exist.

Signed-off-by: Fabian Groffen  gentoo.org>

 libq/tree.c | 10 ++
 1 file changed, 10 insertions(+)

diff --git a/libq/tree.c b/libq/tree.c
index a947735..04bf468 100644
--- a/libq/tree.c
+++ b/libq/tree.c
@@ -1375,6 +1375,16 @@ tree_foreach_packages(tree_ctx *ctx, tree_pkg_cb 
callback, void *priv)
tree_close_cat(cat);
}
pkg.cat_ctx = cat = tree_open_cat(ctx, 
atom->CATEGORY);
+   if (cat == NULL) {
+   /* probably dir doesn't exist 
or something, skip
+* this one */
+   memset(, 0, sizeof(meta));
+   if (len > 0) {  /* hop over \n 
*/
+   p++;
+   len--;
+   }
+   continue;
+   }
cat->pkg_ctxs = (tree_pkg_ctx **)atom;  
/* for name */
}
pkgnamelen = snprintf(pkgname, sizeof(pkgname),



[gentoo-commits] proj/portage-utils:master commit in: libq/

2021-03-13 Thread Fabian Groffen
commit: 2cff8ef68b128ffe8f2074a6a8a58795ab7f06b4
Author: Fabian Groffen  gentoo  org>
AuthorDate: Sat Mar 13 12:42:58 2021 +
Commit: Fabian Groffen  gentoo  org>
CommitDate: Sat Mar 13 12:42:58 2021 +
URL:https://gitweb.gentoo.org/proj/portage-utils.git/commit/?id=2cff8ef6

libq/tree: fix tree_match_atom when returning newest match

we were not evaluating any versions after the first we've seen for each
package, disallowing us to match any but the most recent version

Signed-off-by: Fabian Groffen  gentoo.org>

 libq/tree.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libq/tree.c b/libq/tree.c
index 9b06720..a947735 100644
--- a/libq/tree.c
+++ b/libq/tree.c
@@ -1758,8 +1758,8 @@ tree_match_atom(tree_ctx *ctx, depend_atom *query, int 
flags)
n->meta = tree_pkg_read(pkg_ctx); \
n->next = ret; \
ret = n; \
+   lastpn = atom->PN; \
} \
-   lastpn = atom->PN; \
if (flags & TREE_MATCH_FIRST && ret != NULL) \
break; \
} \



[gentoo-commits] proj/portage-utils:master commit in: libq/

2021-02-20 Thread Fabian Groffen
commit: a94a9e688526d776c808fee96e9a3b9e1733764c
Author: Fabian Groffen  gentoo  org>
AuthorDate: Sat Feb 20 12:04:32 2021 +
Commit: Fabian Groffen  gentoo  org>
CommitDate: Sat Feb 20 12:04:32 2021 +
URL:https://gitweb.gentoo.org/proj/portage-utils.git/commit/?id=a94a9e68

libq/tree: allow tree_match_atom to skip over acct-* categories

Signed-off-by: Fabian Groffen  gentoo.org>

 libq/tree.c | 4 
 libq/tree.h | 7 ---
 2 files changed, 8 insertions(+), 3 deletions(-)

diff --git a/libq/tree.c b/libq/tree.c
index df52171..9b06720 100644
--- a/libq/tree.c
+++ b/libq/tree.c
@@ -1736,6 +1736,10 @@ tree_match_atom(tree_ctx *ctx, depend_atom *query, int 
flags)
if (!(flags & TREE_MATCH_VIRTUAL || \
strcmp(atom->CATEGORY, "virtual") != 0)) \
continue; \
+   /* skip acct-* package as requested */ \
+   if (!(flags & TREE_MATCH_ACCT || \
+   strncmp(atom->CATEGORY, "acct-", 
sizeof("acct-") - 1) != 0)) \
+   continue; \
/* see if this atom matches the query */ \
if (atom_compare(atom, query) == EQUAL) { \
tree_match_ctx *n; \

diff --git a/libq/tree.h b/libq/tree.h
index 53fee67..5a12c92 100644
--- a/libq/tree.h
+++ b/libq/tree.h
@@ -158,9 +158,10 @@ tree_match_ctx *tree_match_atom(tree_ctx *t, depend_atom 
*q, int flags);
 #define TREE_MATCH_FULL_ATOM  (1<<1)
 #define TREE_MATCH_METADATA   (1<<2)
 #define TREE_MATCH_LATEST (1<<3)
-#define TREE_MATCH_VIRTUAL(1<<4)
-#define TREE_MATCH_FIRST  (1<<5)
-#define TREE_MATCH_DEFAULT TREE_MATCH_VIRTUAL
+#define TREE_MATCH_FIRST  (1<<4)
+#define TREE_MATCH_VIRTUAL(1<<5)
+#define TREE_MATCH_ACCT   (1<<6)
+#define TREE_MATCH_DEFAULT(TREE_MATCH_VIRTUAL | TREE_MATCH_ACCT)
 void tree_match_close(tree_match_ctx *t);
 
 #endif



[gentoo-commits] proj/portage-utils:master commit in: libq/

2021-02-20 Thread Fabian Groffen
commit: 90de2c63f3d0d7e546265b02227b96b01dba24f7
Author: Fabian Groffen  gentoo  org>
AuthorDate: Sat Feb 20 10:54:05 2021 +
Commit: Fabian Groffen  gentoo  org>
CommitDate: Sat Feb 20 10:54:05 2021 +
URL:https://gitweb.gentoo.org/proj/portage-utils.git/commit/?id=90de2c63

libq/tree: add ability to match latest version per package in tree_match_atom

Allow retrieving the latest version per package matching the input atom.
E.g. a search for dash would return both app-shells/dash as well as
app-emacs/dash using LATEST, while FIRST would only return the app-emacs
one (or whichever came first while traversing).

Signed-off-by: Fabian Groffen  gentoo.org>

 libq/tree.c | 42 ++
 libq/tree.h |  9 +
 2 files changed, 31 insertions(+), 20 deletions(-)

diff --git a/libq/tree.c b/libq/tree.c
index 293d7f7..df52171 100644
--- a/libq/tree.c
+++ b/libq/tree.c
@@ -1728,26 +1728,36 @@ tree_match_atom(tree_ctx *ctx, depend_atom *query, int 
flags)
 
 #define search_cat(C) \
 { \
+   char *lastpn = NULL; \
while ((pkg_ctx = tree_next_pkg(C)) != NULL) { \
atom = tree_get_atom(pkg_ctx, \
query->SLOT != NULL || flags & 
TREE_MATCH_FULL_ATOM); \
-   if (flags & TREE_MATCH_VIRTUAL || \
-   strcmp(atom->CATEGORY, "virtual") != 0) { \
-   if (atom_compare(atom, query) == EQUAL) { \
-   tree_match_ctx *n = 
xzalloc(sizeof(tree_match_ctx)); \
-   n->atom = atom; \
-   snprintf(n->path, sizeof(n->path), 
"%s/%s/%s%s", \
-   (char *)C->ctx->path, C->name, 
pkg_ctx->name, \
-   C->ctx->cachetype == 
CACHE_EBUILD ? ".ebuild" : \
-   C->ctx->cachetype == 
CACHE_BINPKGS ? ".tbz2" : ""); \
-   if (flags & TREE_MATCH_METADATA) \
-   n->meta = tree_pkg_read(pkg_ctx); \
-   n->next = ret; \
-   ret = n; \
-   } \
-   if (flags & TREE_MATCH_FIRST && ret != NULL) \
-   break; \
+   /* skip virtual/ package as requested */ \
+   if (!(flags & TREE_MATCH_VIRTUAL || \
+   strcmp(atom->CATEGORY, "virtual") != 0)) \
+   continue; \
+   /* see if this atom matches the query */ \
+   if (atom_compare(atom, query) == EQUAL) { \
+   tree_match_ctx *n; \
+   /* skip over additional versions for match latest */ \
+   if (flags & TREE_MATCH_LATEST && lastpn != NULL && \
+   strcmp(lastpn, atom->PN) == 0) \
+   continue; \
+   /* create a new match result */ \
+   n = xzalloc(sizeof(tree_match_ctx)); \
+   n->atom = atom; \
+   snprintf(n->path, sizeof(n->path), "%s/%s/%s%s", \
+   (char *)C->ctx->path, C->name, 
pkg_ctx->name, \
+   C->ctx->cachetype == CACHE_EBUILD ? 
".ebuild" : \
+   C->ctx->cachetype == CACHE_BINPKGS ? 
".tbz2" : ""); \
+   if (flags & TREE_MATCH_METADATA) \
+   n->meta = tree_pkg_read(pkg_ctx); \
+   n->next = ret; \
+   ret = n; \
} \
+   lastpn = atom->PN; \
+   if (flags & TREE_MATCH_FIRST && ret != NULL) \
+   break; \
} \
C->pkg_cur = 0;  /* reset to allow another traversal */ \
 }

diff --git a/libq/tree.h b/libq/tree.h
index f756fd4..53fee67 100644
--- a/libq/tree.h
+++ b/libq/tree.h
@@ -155,10 +155,11 @@ int tree_foreach_pkg(tree_ctx *ctx, tree_pkg_cb callback, 
void *priv,
 set *tree_get_atoms(tree_ctx *ctx, bool fullcpv, set *satoms);
 depend_atom *tree_get_atom(tree_pkg_ctx *pkg_ctx, bool complete);
 tree_match_ctx *tree_match_atom(tree_ctx *t, depend_atom *q, int flags);
-#define TREE_MATCH_FULL_ATOM   1<<1
-#define TREE_MATCH_METADATA1<<2
-#define TREE_MATCH_FIRST   1<<3
-#define TREE_MATCH_VIRTUAL 1<<4
+#define TREE_MATCH_FULL_ATOM  (1<<1)
+#define TREE_MATCH_METADATA   (1<<2)
+#define TREE_MATCH_LATEST (1<<3)
+#define TREE_MATCH_VIRTUAL(1<<4)
+#define TREE_MATCH_FIRST  (1<<5)
 #define TREE_MATCH_DEFAULT TREE_MATCH_VIRTUAL
 void tree_match_close(tree_match_ctx *t);
 



[gentoo-commits] proj/portage-utils:master commit in: libq/

2021-02-17 Thread Fabian Groffen
commit: 16ff9817f7d68d37e39302dac6f632c306cdce4f
Author: Fabian Groffen  gentoo  org>
AuthorDate: Wed Feb 17 20:14:01 2021 +
Commit: Fabian Groffen  gentoo  org>
CommitDate: Wed Feb 17 20:14:01 2021 +
URL:https://gitweb.gentoo.org/proj/portage-utils.git/commit/?id=16ff9817

libq/tree: make tree_match_atom return path for each match

Along with some changes to make sure returned atoms remain valid (e.g.
not getting an expired pointer for category name), build a patch to the
returned objects, that should allow opening the ebuild or something.

Signed-off-by: Fabian Groffen  gentoo.org>

 libq/tree.c | 41 +
 libq/tree.h |  5 -
 2 files changed, 37 insertions(+), 9 deletions(-)

diff --git a/libq/tree.c b/libq/tree.c
index e41a0cb..293d7f7 100644
--- a/libq/tree.c
+++ b/libq/tree.c
@@ -1,5 +1,5 @@
 /*
- * Copyright 2005-2020 Gentoo Foundation
+ * Copyright 2005-2021 Gentoo Foundation
  * Distributed under the terms of the GNU General Public License v2
  *
  * Copyright 2005-2008 Ned Ludd- 
@@ -55,6 +55,10 @@ tree_open_int(const char *sroot, const char *tdir, bool 
quiet)
goto cp_error;
}
 
+   if (sroot[0] == '/' && sroot[1] == '\0')
+   sroot = "";
+   snprintf(ctx->path, sizeof(ctx->path), "%s/%s", sroot, tdir);
+
ctx->dir = fdopendir(ctx->tree_fd);
if (ctx->dir == NULL)
goto cv_error;
@@ -128,6 +132,25 @@ tree_open_vdb(const char *sroot, const char *svdb)
return ret;
 }
 
+tree_ctx *
+tree_open_ebuild(const char *sroot, const char *portdir)
+{
+   tree_ctx *ret = tree_open_int(sroot, portdir, true);
+   if (ret != NULL) {
+   char buf[_Q_PATH_MAX];
+   char *repo = NULL;
+   size_t repolen = 0;
+
+   snprintf(buf, sizeof(buf), "%s%s/%s", sroot, portdir, 
portrepo_name);
+   if (eat_file(buf, , )) {
+   (void)rmspace(repo);
+   ret->repo = repo;
+   }
+   ret->cachetype = CACHE_EBUILD;
+   }
+   return ret;
+}
+
 static const char binpkg_packages[]  = "Packages";
 tree_ctx *
 tree_open_binpkg(const char *sroot, const char *spkg)
@@ -1491,10 +1514,10 @@ depend_atom *
 tree_get_atom(tree_pkg_ctx *pkg_ctx, bool complete)
 {
if (pkg_ctx->atom == NULL) {
-   pkg_ctx->atom = atom_explode(pkg_ctx->name);
+   pkg_ctx->atom =
+   atom_explode_cat(pkg_ctx->name, (char 
*)pkg_ctx->cat_ctx->name);
if (pkg_ctx->atom == NULL)
return NULL;
-   pkg_ctx->atom->CATEGORY = (char *)pkg_ctx->cat_ctx->name;
}
 
if (complete) {
@@ -1708,14 +1731,15 @@ tree_match_atom(tree_ctx *ctx, depend_atom *query, int 
flags)
while ((pkg_ctx = tree_next_pkg(C)) != NULL) { \
atom = tree_get_atom(pkg_ctx, \
query->SLOT != NULL || flags & 
TREE_MATCH_FULL_ATOM); \
-fprintf(stderr, "fbg: %s\n", atom_to_string(atom)); \
if (flags & TREE_MATCH_VIRTUAL || \
-   strcmp(atom->CATEGORY, "virtual") != 0) \
+   strcmp(atom->CATEGORY, "virtual") != 0) { \
if (atom_compare(atom, query) == EQUAL) { \
-   tree_match_ctx *n; \
-   n = xzalloc(sizeof(tree_match_ctx)); \
-   n->free_atom = false; \
+   tree_match_ctx *n = 
xzalloc(sizeof(tree_match_ctx)); \
n->atom = atom; \
+   snprintf(n->path, sizeof(n->path), 
"%s/%s/%s%s", \
+   (char *)C->ctx->path, C->name, 
pkg_ctx->name, \
+   C->ctx->cachetype == 
CACHE_EBUILD ? ".ebuild" : \
+   C->ctx->cachetype == 
CACHE_BINPKGS ? ".tbz2" : ""); \
if (flags & TREE_MATCH_METADATA) \
n->meta = tree_pkg_read(pkg_ctx); \
n->next = ret; \
@@ -1723,6 +1747,7 @@ fprintf(stderr, "fbg: %s\n", atom_to_string(atom)); \
} \
if (flags & TREE_MATCH_FIRST && ret != NULL) \
break; \
+   } \
} \
C->pkg_cur = 0;  /* reset to allow another traversal */ \
 }

diff --git a/libq/tree.h b/libq/tree.h
index 900b998..f756fd4 100644
--- a/libq/tree.h
+++ b/libq/tree.h
@@ -1,5 +1,5 @@
 /*
- * Copyright 2005-2020 Gentoo Foundation
+ * Copyright 2005-2021 Gentoo Foundation
  * Distributed under the terms of the GNU General Public License v2
  */
 
@@ -24,6 +24,7 @@ typedef struct tree_match_ctxtree_match_ctx;
 struct tree_ctx {
int portroot_fd;
int 

[gentoo-commits] proj/portage-utils:master commit in: libq/

2021-02-17 Thread Fabian Groffen
commit: e3c6591032d6a4589ae98d6abb0f59d3325bc11e
Author: Fabian Groffen  gentoo  org>
AuthorDate: Wed Feb 17 20:00:28 2021 +
Commit: Fabian Groffen  gentoo  org>
CommitDate: Wed Feb 17 20:00:28 2021 +
URL:https://gitweb.gentoo.org/proj/portage-utils.git/commit/?id=e3c65910

libq/atom: adapt atom_explode to take an optional category

Sometimes we don't have the category available in the to be parsed
string, but in a separate string.  Make it relatively cheap to use this
category, compared to having to allocate and format a string to make
atom_explode pick it up.

Signed-off-by: Fabian Groffen  gentoo.org>

 libq/atom.c | 21 ++---
 libq/atom.h |  5 +++--
 2 files changed, 17 insertions(+), 9 deletions(-)

diff --git a/libq/atom.c b/libq/atom.c
index acf28be..f4c7c1e 100644
--- a/libq/atom.c
+++ b/libq/atom.c
@@ -1,5 +1,5 @@
 /*
- * Copyright 2005-2020 Gentoo Foundation
+ * Copyright 2005-2021 Gentoo Foundation
  * Distributed under the terms of the GNU General Public License v2
  *
  * Copyright 2005-2008 Ned Ludd- 
@@ -43,7 +43,7 @@ const char * const booga[] = {"!!!", "!=", "==", ">", "<"};
  * for a definition of which variable contains what, see:
  * https://dev.gentoo.org/~ulm/pms/head/pms.html#x1-10800011 */
 depend_atom *
-atom_explode(const char *atom)
+atom_explode_cat(const char *atom, const char *cat)
 {
depend_atom *ret;
char *ptr;
@@ -70,14 +70,14 @@ atom_explode(const char *atom)
 * We allocate memory for atom struct, one string for CAT/PF + PVR,
 * another to cover PN and a final one for P + PV. */
slen = strlen(atom) + 1;
-   len = sizeof(*ret) + (slen * 3);
-   ret = xmalloc(len);
+   len = cat != NULL ? strlen(cat) + 1 : 0;
+   ret = xmalloc(sizeof(*ret) + (slen * 3) + len);
memset(ret, '\0', sizeof(*ret));
 
/* assign pointers to the three storage containers */
-   ret->CATEGORY = (char *)ret + sizeof(*ret); /* CAT PF PVR */
-   ret->P= ret->CATEGORY + slen;   /* P   PV */
-   ret->PN   = ret->P + slen;  /* PN */
+   ret->CATEGORY = (char *)ret + sizeof(*ret) + len; /* CAT PF PVR */
+   ret->P= ret->CATEGORY + slen; /* P   PV */
+   ret->PN   = ret->P + slen;/* PN */
 
/* check for blocker operators */
ret->blocker = ATOM_BL_NONE;
@@ -245,6 +245,13 @@ atom_explode(const char *atom)
ret->CATEGORY = NULL;
}
 
+   /* inject separate CATEGORY when given, this will override any found
+* CATEGORY, which is what it could be used for too */
+   if (cat != NULL) {
+   ret->CATEGORY = (char *)ret + sizeof(*ret);
+   memcpy(ret->CATEGORY, cat, len);
+   }
+
if (ret->PF == NULL) {
/* atom has no name, this is it */
ret->P = NULL;

diff --git a/libq/atom.h b/libq/atom.h
index aff4548..ead9154 100644
--- a/libq/atom.h
+++ b/libq/atom.h
@@ -1,5 +1,5 @@
 /*
- * Copyright 2005-2019 Gentoo Foundation
+ * Copyright 2005-2021 Gentoo Foundation
  * Distributed under the terms of the GNU General Public License v2
  *
  * Copyright 2005-2008 Ned Ludd- 
@@ -96,7 +96,8 @@ typedef enum {
OLDER
 } atom_equality;
 
-depend_atom *atom_explode(const char *atom);
+depend_atom *atom_explode_cat(const char *atom, const char *cat);
+#define atom_explode(A) atom_explode_cat(A, NULL)
 depend_atom *atom_clone(depend_atom *atom);
 void atom_implode(depend_atom *atom);
 atom_equality atom_compare(const depend_atom *a1, const depend_atom *a2);



[gentoo-commits] proj/portage-utils:master commit in: libq/

2021-01-15 Thread Fabian Groffen
commit: 6480394a50b1be7632ce414ca8d956484eac51f2
Author: Fabian Groffen  gentoo  org>
AuthorDate: Fri Jan 15 20:03:51 2021 +
Commit: Fabian Groffen  gentoo  org>
CommitDate: Fri Jan 15 20:03:51 2021 +
URL:https://gitweb.gentoo.org/proj/portage-utils.git/commit/?id=6480394a

libq/hash: close fd once in hash_multiple_file_fd

Signed-off-by: Fabian Groffen  gentoo.org>

 libq/hash.c | 6 --
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/libq/hash.c b/libq/hash.c
index 88c4b56..b5aec46 100644
--- a/libq/hash.c
+++ b/libq/hash.c
@@ -147,6 +147,7 @@ hash_multiple_file_fd(
(void)blak2b;
 #endif
 
+   *flen = 0;
if ((f = fdopen(fd, "r")) == NULL)
return -1;
 
@@ -164,7 +165,6 @@ hash_multiple_file_fd(
blake2b_init(, BLAKE2B_OUTBYTES);
 #endif
 
-   *flen = 0;
while ((len = fread(data, 1, sizeof(data), f)) > 0) {
*flen += len;
 #pragma omp parallel sections
@@ -323,7 +323,9 @@ hash_multiple_file_at_cb(
ret = hash_multiple_file_fd(fd, md5, sha1, sha256, sha512,
whrlpl, blak2b, flen, hashes);
 
-   close(fd);
+   if (ret != 0)
+   close(fd);
+
return ret;
 }
 



[gentoo-commits] proj/portage-utils:master commit in: libq/, tests/profile/, tests/qfile/, tests/atom_compare/, tests/atom_explode/, ...

2020-11-13 Thread Fabian Groffen
commit: 9cbdb752cdf67fadf0eced5a852cf6eedfb6a33d
Author: Fabian Groffen  gentoo  org>
AuthorDate: Fri Nov 13 09:32:14 2020 +
Commit: Fabian Groffen  gentoo  org>
CommitDate: Fri Nov 13 09:32:14 2020 +
URL:https://gitweb.gentoo.org/proj/portage-utils.git/commit/?id=9cbdb752

buildsys: regen

Signed-off-by: Fabian Groffen  gentoo.org>

 Makefile.in| 16 +++
 autotools/gnulib/Makefile.in   |  4 +--
 config.h.in|  6 
 configure  | 65 +-
 libq/Makefile.in   |  4 +--
 tests/Makefile.in  |  4 +--
 tests/atom_compare/Makefile.in |  4 +--
 tests/atom_explode/Makefile.in |  4 +--
 tests/copy_file/Makefile.in|  4 +--
 tests/install/Makefile.in  |  4 +--
 tests/mkdir/Makefile.in|  4 +--
 tests/profile/Makefile.in  |  4 +--
 tests/qatom/Makefile.in|  4 +--
 tests/qcheck/Makefile.in   |  4 +--
 tests/qdepends/Makefile.in |  4 +--
 tests/qfile/Makefile.in|  4 +--
 tests/qlist/Makefile.in|  4 +--
 tests/qlop/Makefile.in |  4 +--
 tests/qmanifest/Makefile.in|  4 +--
 tests/qmerge/Makefile.in   |  4 +--
 tests/qtbz2/Makefile.in|  4 +--
 tests/quse/Makefile.in |  4 +--
 tests/qxpak/Makefile.in|  4 +--
 tests/rmspace/Makefile.in  |  4 +--
 tests/source/Makefile.in   |  4 +--
 25 files changed, 125 insertions(+), 50 deletions(-)

diff --git a/Makefile.in b/Makefile.in
index 91d9a3b..4e26d75 100644
--- a/Makefile.in
+++ b/Makefile.in
@@ -1,7 +1,7 @@
-# Makefile.in generated by automake 1.16.1 from Makefile.am.
+# Makefile.in generated by automake 1.16.2 from Makefile.am.
 # @configure_input@
 
-# Copyright (C) 1994-2018 Free Software Foundation, Inc.
+# Copyright (C) 1994-2020 Free Software Foundation, Inc.
 
 # This Makefile.in is free software; the Free Software Foundation
 # gives unlimited permission to copy and/or distribute it,
@@ -375,8 +375,8 @@ am__recursive_targets = \
   $(am__extra_recursive_targets)
 AM_RECURSIVE_TARGETS = $(am__recursive_targets:-recursive=) TAGS CTAGS \
cscope distdir distdir-am dist dist-all distcheck
-am__tagged_files = $(HEADERS) $(SOURCES) $(TAGS_FILES) \
-   $(LISP)config.h.in
+am__tagged_files = $(HEADERS) $(SOURCES) $(TAGS_FILES) $(LISP) \
+   config.h.in
 # Read a list of newline-separated strings from the standard input,
 # and print each of them once, without duplicates.  Input order is
 # *not* preserved.
@@ -2281,6 +2281,10 @@ dist-xz: distdir
tardir=$(distdir) && $(am__tar) | XZ_OPT=$${XZ_OPT--e} xz -c 
>$(distdir).tar.xz
$(am__post_remove_distdir)
 
+dist-zstd: distdir
+   tardir=$(distdir) && $(am__tar) | zstd -c 
$${ZSTD_CLEVEL-$${ZSTD_OPT--19}} >$(distdir).tar.zst
+   $(am__post_remove_distdir)
+
 dist-tarZ: distdir
@echo WARNING: "Support for distribution archives compressed with" \
   "legacy program 'compress' is deprecated." >&2
@@ -2323,6 +2327,8 @@ distcheck: dist
  eval GZIP= gzip $(GZIP_ENV) -dc $(distdir).shar.gz | unshar ;;\
*.zip*) \
  unzip $(distdir).zip ;;\
+   *.tar.zst*) \
+ zstd -dc $(distdir).tar.zst | $(am__untar) ;;\
esac
chmod -R a-w $(distdir)
chmod u+w $(distdir)
@@ -2548,7 +2554,7 @@ uninstall-man: uninstall-man1
clean-binPROGRAMS clean-cscope clean-generic clean-libtool \
clean-local cscope cscopelist-am ctags ctags-am dist dist-all \
dist-bzip2 dist-gzip dist-lzip dist-shar dist-tarZ dist-xz \
-   dist-zip distcheck distclean distclean-compile \
+   dist-zip dist-zstd distcheck distclean distclean-compile \
distclean-generic distclean-hdr distclean-libtool \
distclean-tags distcleancheck distdir distuninstallcheck dvi \
dvi-am html html-am info info-am install install-am \

diff --git a/autotools/gnulib/Makefile.in b/autotools/gnulib/Makefile.in
index 8be76d3..7103387 100644
--- a/autotools/gnulib/Makefile.in
+++ b/autotools/gnulib/Makefile.in
@@ -1,7 +1,7 @@
-# Makefile.in generated by automake 1.16.1 from Makefile.am.
+# Makefile.in generated by automake 1.16.2 from Makefile.am.
 # @configure_input@
 
-# Copyright (C) 1994-2018 Free Software Foundation, Inc.
+# Copyright (C) 1994-2020 Free Software Foundation, Inc.
 
 # This Makefile.in is free software; the Free Software Foundation
 # gives unlimited permission to copy and/or distribute it,

diff --git a/config.h.in b/config.h.in
index c8155e2..9b75f3a 100644
--- a/config.h.in
+++ b/config.h.in
@@ -670,6 +670,9 @@
 /* Define if you have ssl */
 #undef HAVE_SSL
 
+/* Define to 1 if you have the  header file. */
+#undef HAVE_STDDEF_H
+
 /* Define to 1 if you have the  header file. */
 #undef HAVE_STDINT_H
 
@@ -987,6 +990,9 @@
'sig_atomic_t'. */
 #undef SIG_ATOMIC_T_SUFFIX
 
+/* The number of bytes in type size_t */
+#undef SIZEOF_SIZE_T
+
 /* Define as the 

[gentoo-commits] proj/portage-utils:master commit in: libq/

2020-06-27 Thread Fabian Groffen
commit: 1b42d9bd178a8fddf8e31615ac37ce3bb9d94d16
Author: Fabian Groffen  gentoo  org>
AuthorDate: Sat Jun 27 09:34:49 2020 +
Commit: Fabian Groffen  gentoo  org>
CommitDate: Sat Jun 27 09:34:49 2020 +
URL:https://gitweb.gentoo.org/proj/portage-utils.git/commit/?id=1b42d9bd

libq/tree: ensure tree_foreach_pkg_fast can be run multiple times too

Signed-off-by: Fabian Groffen  gentoo.org>

 libq/tree.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/libq/tree.c b/libq/tree.c
index ad8db47..e41a0cb 100644
--- a/libq/tree.c
+++ b/libq/tree.c
@@ -1477,6 +1477,8 @@ tree_foreach_pkg(tree_ctx *ctx, tree_pkg_cb callback, 
void *priv,
/* allow foreach to be called again on the same open tree */
if (ctx->do_sort)
scandir_free(ctx->cat_de, ctx->cat_cnt);
+   else
+   rewinddir(ctx->dir);
ctx->cat_de = NULL;
ctx->cat_cur = 0;
ctx->cat_cnt = 0;



[gentoo-commits] proj/portage-utils:master commit in: libq/

2020-06-07 Thread Fabian Groffen
commit: 4fbeb8ccca1b93da4987b0d58aba24c0901e898d
Author: Fabian Groffen  gentoo  org>
AuthorDate: Sun Jun  7 10:39:40 2020 +
Commit: Fabian Groffen  gentoo  org>
CommitDate: Sun Jun  7 10:39:40 2020 +
URL:https://gitweb.gentoo.org/proj/portage-utils.git/commit/?id=4fbeb8cc

libq/tree: fix metadata cache after realloc

A realloc caused a relocation of pointers, which also changed the value
of Q__md5_ and Q__eclasses_ which are secretly used to store len and
pos, so make sure we reset them to correct values after a relocation
takes place.

While at it, reduce the allocation requirements by only considering the
really needed space (over-allocate less here).

Signed-off-by: Fabian Groffen  gentoo.org>

 libq/tree.c | 21 +++--
 1 file changed, 15 insertions(+), 6 deletions(-)

diff --git a/libq/tree.c b/libq/tree.c
index d8d238c..ad8db47 100644
--- a/libq/tree.c
+++ b/libq/tree.c
@@ -957,9 +957,8 @@ tree_read_file_binpkg_xpak_cb(
 
if (len - pos < (size_t)(data_len + 1)) {
char *old_data = m->Q__data;
-   len += (((data_len + 1) / BUFSIZ) + 1) * BUFSIZ;
+   len += (((data_len + 1 - (len - pos)) / BUFSIZ) + 1) * BUFSIZ;
m->Q__data = xrealloc(m->Q__data, len);
-   m->Q__md5_ = (char *)len;
 
/* re-position existing keys */
if (old_data != NULL && m->Q__data != old_data) {
@@ -969,6 +968,10 @@ tree_read_file_binpkg_xpak_cb(
if (newdata[elems] != NULL)
newdata[elems] = m->Q__data + 
(newdata[elems] - old_data);
}
+
+   /* set after repositioning! */
+   m->Q__md5_ = (char *)len;
+   m->Q__eclasses_ = (char *)pos;
}
 
*key = m->Q__data + pos;
@@ -997,9 +1000,8 @@ tree_read_file_binpkg(tree_pkg_ctx *pkg_ctx)
 
if (len - pos < needlen) {
char *old_data = m->Q__data;
-   len += ((needlen / BUFSIZ) + 1) * BUFSIZ;
+   len += (((needlen - (len - pos)) / BUFSIZ) + 1) * 
BUFSIZ;
m->Q__data = xrealloc(m->Q__data, len);
-   m->Q__md5_ = (char *)len;
 
/* re-position existing keys */
if (old_data != NULL && m->Q__data != old_data) {
@@ -1010,6 +1012,10 @@ tree_read_file_binpkg(tree_pkg_ctx *pkg_ctx)
newdata[elems] =
m->Q__data + 
(newdata[elems] - old_data);
}
+
+   /* set after repositioning! */
+   m->Q__md5_ = (char *)len;
+   m->Q__eclasses_ = (char *)pos;
}
 
m->Q_SHA1 = m->Q__data + pos;
@@ -1112,9 +1118,8 @@ tree_pkg_meta_get_int(tree_pkg_ctx *pkg_ctx, size_t 
offset, const char *keyn)
/* TODO: this is an exact copy from 
tree_read_file_binpkg_xpak_cb */
if (len - pos < (size_t)(s.st_size + 1)) {
p = m->Q__data;
-   len += (((s.st_size + 1) / BUFSIZ) + 1) * 
BUFSIZ;
+   len += (((s.st_size + 1 - (len - pos)) / 
BUFSIZ) + 1) * BUFSIZ;
m->Q__data = xrealloc(m->Q__data, len);
-   m->Q__md5_ = (char *)len;
 
/* re-position existing keys */
if (p != NULL && m->Q__data != p) {
@@ -1124,6 +1129,10 @@ tree_pkg_meta_get_int(tree_pkg_ctx *pkg_ctx, size_t 
offset, const char *keyn)
if (newdata[elems] != NULL)
newdata[elems] = 
m->Q__data + (newdata[elems] - p);
}
+
+   /* set after repositioning! */
+   m->Q__md5_ = (char *)len;
+   m->Q__eclasses_ = (char *)pos;
}
 
p = *key = m->Q__data + pos;



[gentoo-commits] proj/portage-utils:master commit in: libq/

2020-05-25 Thread Fabian Groffen
commit: 7b8a0e92eaddea4e699b0b551e2bf7ce6b8aecb1
Author: Fabian Groffen  gentoo  org>
AuthorDate: Mon May 25 18:19:15 2020 +
Commit: Fabian Groffen  gentoo  org>
CommitDate: Mon May 25 18:19:15 2020 +
URL:https://gitweb.gentoo.org/proj/portage-utils.git/commit/?id=7b8a0e92

libq/tree: properly free meta in tree_match_close

Signed-off-by: Fabian Groffen  gentoo.org>

 libq/tree.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libq/tree.c b/libq/tree.c
index eb5f324..d8d238c 100644
--- a/libq/tree.c
+++ b/libq/tree.c
@@ -1744,7 +1744,7 @@ tree_match_close(tree_match_ctx *match)
if (match->free_atom)
atom_implode(match->atom);
if (match->meta != NULL)
-   free(match->meta);
+   tree_close_meta(match->meta);
free(match);
}
 }



[gentoo-commits] proj/portage-utils:master commit in: libq/

2020-05-25 Thread Fabian Groffen
commit: 598110a8c77b8d6995b9f34e2455742b692ff8f1
Author: Fabian Groffen  gentoo  org>
AuthorDate: Mon May 25 18:01:49 2020 +
Commit: Fabian Groffen  gentoo  org>
CommitDate: Mon May 25 18:01:49 2020 +
URL:https://gitweb.gentoo.org/proj/portage-utils.git/commit/?id=598110a8

libq/hash: avoid invalid (double) fclose

Signed-off-by: Fabian Groffen  gentoo.org>

 libq/hash.c | 1 -
 1 file changed, 1 deletion(-)

diff --git a/libq/hash.c b/libq/hash.c
index a51ea6a..88c4b56 100644
--- a/libq/hash.c
+++ b/libq/hash.c
@@ -291,7 +291,6 @@ hash_multiple_file_fd(
 #endif
}
 
-   fclose(f);
return 0;
 }
 



[gentoo-commits] proj/portage-utils:master commit in: libq/

2020-05-25 Thread Fabian Groffen
commit: 93b42c880a13128663c6ddf2ee1a98b901ede6fa
Author: Fabian Groffen  gentoo  org>
AuthorDate: Mon May 25 13:25:15 2020 +
Commit: Fabian Groffen  gentoo  org>
CommitDate: Mon May 25 13:25:15 2020 +
URL:https://gitweb.gentoo.org/proj/portage-utils.git/commit/?id=93b42c88

libq/tree: avoid invalid read in tree_foreach_packages

eat_file doesn't return how much data was written, only produced buffer
size, so need to calculate length there

Signed-off-by: Fabian Groffen  gentoo.org>

 libq/tree.c | 7 +--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/libq/tree.c b/libq/tree.c
index e4c4eb7..eb5f324 100644
--- a/libq/tree.c
+++ b/libq/tree.c
@@ -1277,11 +1277,11 @@ tree_close_pkg(tree_pkg_ctx *pkg_ctx)
 static int
 tree_foreach_packages(tree_ctx *ctx, tree_pkg_cb callback, void *priv)
 {
-   char *p = ctx->pkgs;
+   char *p;
char *q;
char *c;
char pkgname[_Q_PATH_MAX];
-   size_t len = ctx->pkgslen;
+   size_t len;
int ret = 0;
depend_atom *query = ctx->query_atom;
 
@@ -1307,6 +1307,9 @@ tree_foreach_packages(tree_ctx *ctx, tree_pkg_cb 
callback, void *priv)
close(fd);
}
 
+   p = ctx->pkgs;
+   len = strlen(ctx->pkgs);  /* sucks, need eat_file change */
+
memset(, 0, sizeof(meta));
 
do {



[gentoo-commits] proj/portage-utils:master commit in: libq/

2020-05-25 Thread Fabian Groffen
commit: 74aeefacd106fcf87e755f2d1a53b0c7bc9f2e10
Author: Fabian Groffen  gentoo  org>
AuthorDate: Mon May 25 11:19:38 2020 +
Commit: Fabian Groffen  gentoo  org>
CommitDate: Mon May 25 11:19:38 2020 +
URL:https://gitweb.gentoo.org/proj/portage-utils.git/commit/?id=74aeefac

libq/tree: fix Coverity 210534

tree_close_pkg can be called from tree_open_pkg, which will then free
the pointer de->d_name, which should only be freed by scandir_free.

Signed-off-by: Fabian Groffen  gentoo.org>

 libq/tree.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/libq/tree.c b/libq/tree.c
index d313f3b..e4c4eb7 100644
--- a/libq/tree.c
+++ b/libq/tree.c
@@ -399,6 +399,7 @@ tree_open_pkg(tree_cat_ctx *cat_ctx, const char *name)
if (cat_ctx->ctx->query_atom != NULL) {
(void)tree_get_atom(pkg_ctx, cat_ctx->ctx->query_atom->SLOT != 
NULL);
if (atom_compare(pkg_ctx->atom, cat_ctx->ctx->query_atom) != 
EQUAL) {
+   pkg_ctx->name = NULL;
tree_close_pkg(pkg_ctx);
return NULL;
}



[gentoo-commits] proj/portage-utils:master commit in: libq/

2020-05-25 Thread Fabian Groffen
commit: a68b9b4ebc840805f504fe681196e7f15737985d
Author: Fabian Groffen  gentoo  org>
AuthorDate: Mon May 25 11:03:36 2020 +
Commit: Fabian Groffen  gentoo  org>
CommitDate: Mon May 25 11:03:36 2020 +
URL:https://gitweb.gentoo.org/proj/portage-utils.git/commit/?id=a68b9b4e

libq/atom: fixup USE-dep printing in atom_format

Bug: https://bugs.gentoo.org/724892
Signed-off-by: Fabian Groffen  gentoo.org>

 libq/atom.c | 20 ++--
 1 file changed, 14 insertions(+), 6 deletions(-)

diff --git a/libq/atom.c b/libq/atom.c
index 7e72bf3..acf28be 100644
--- a/libq/atom.c
+++ b/libq/atom.c
@@ -939,12 +939,20 @@ atom_format_r(
} else if (!strncmp("USE", fmt, len)) {
if (showit || atom->usedeps) {
atom_usedep *ud;
-   append_buf(buf, buflen, "%s", 
"[");
-   for (ud = atom->usedeps; ud != 
NULL; ud = ud->next)
-   append_buf(buf, buflen, 
"%s%s%s%s%s%s",
-   
MAGENTA, atom_usecond_str[ud->pfx_cond],
-   
ud->use, atom_usecond_str[ud->sfx_cond],
-   NORM, 
ud->next == NULL ? "]" : ",");
+   if (atom->usedeps == NULL) {
+   append_buf(buf, buflen, 
"%s", "");
+   } else {
+   if (connected)
+   append_buf(buf, 
buflen, "%s", "[");
+   for (ud = 
atom->usedeps; ud != NULL; ud = ud->next)
+   append_buf(buf, 
buflen, "%s%s%s%s%s%s",
+   
MAGENTA, atom_usecond_str[ud->pfx_cond],
+   
ud->use, atom_usecond_str[ud->sfx_cond],
+   
NORM, ud->next == NULL ? "" :
+   
(connected ? "," : " "));
+   if (connected)
+   append_buf(buf, 
buflen, "%s", "]");
+   }
}
} else
append_buf(buf, buflen, "", 
(int)len, fmt);



[gentoo-commits] proj/portage-utils:master commit in: libq/

2020-05-25 Thread Fabian Groffen
commit: 04978409eb34973d3af6ce0592fd623e82ea6573
Author: Fabian Groffen  gentoo  org>
AuthorDate: Mon May 25 10:33:59 2020 +
Commit: Fabian Groffen  gentoo  org>
CommitDate: Mon May 25 10:33:59 2020 +
URL:https://gitweb.gentoo.org/proj/portage-utils.git/commit/?id=04978409

libq/tree: allow tree_foreach_packages to be called multiple times

Signed-off-by: Fabian Groffen  gentoo.org>

 libq/tree.c | 16 
 1 file changed, 16 insertions(+)

diff --git a/libq/tree.c b/libq/tree.c
index d901fc6..4b9109e 100644
--- a/libq/tree.c
+++ b/libq/tree.c
@@ -1293,6 +1293,22 @@ tree_foreach_packages(tree_ctx *ctx, tree_pkg_cb 
callback, void *priv)
tree_pkg_meta meta;
depend_atom *atom = NULL;
 
+   /* re-read the contents, this is necessary to make it possible to
+* call this function multiple times
+* TODO: generate an internal in-memory tree when cache is enabled */
+   if (ctx->pkgs == NULL || ctx->pkgs[0] == '\0') {
+   int fd = openat(ctx->tree_fd, binpkg_packages, O_RDONLY | 
O_CLOEXEC);
+   if (!eat_file_fd(fd, >pkgs, >pkgslen)) {
+   if (ctx->pkgs != NULL) {
+   free(ctx->pkgs);
+   ctx->pkgs = NULL;
+   }
+   close(fd);
+   return 1;
+   }
+   close(fd);
+   }
+
memset(, 0, sizeof(meta));
 
do {



[gentoo-commits] proj/portage-utils:master commit in: libq/

2020-05-25 Thread Fabian Groffen
commit: 1cffb01452f2553747be26778ef4f84425e45554
Author: Fabian Groffen  gentoo  org>
AuthorDate: Mon May 25 10:30:52 2020 +
Commit: Fabian Groffen  gentoo  org>
CommitDate: Mon May 25 10:30:52 2020 +
URL:https://gitweb.gentoo.org/proj/portage-utils.git/commit/?id=1cffb014

libq/tree: slightly optimise tree_open_pkg

don't construct a new path, but open at the existing filedescriptor
instead.

Signed-off-by: Fabian Groffen  gentoo.org>

 libq/tree.c | 9 +
 1 file changed, 5 insertions(+), 4 deletions(-)

diff --git a/libq/tree.c b/libq/tree.c
index ebcc133..7fbb739 100644
--- a/libq/tree.c
+++ b/libq/tree.c
@@ -27,7 +27,7 @@
 #include 
 
 static int tree_pkg_compar(const void *l, const void *r);
-static tree_pkg_ctx * tree_next_pkg_int(tree_cat_ctx *cat_ctx);
+static tree_pkg_ctx *tree_next_pkg_int(tree_cat_ctx *cat_ctx);
 static void tree_close_meta(tree_pkg_meta *cache);
 
 static tree_ctx *
@@ -132,18 +132,19 @@ tree_ctx *
 tree_open_binpkg(const char *sroot, const char *spkg)
 {
tree_ctx *ret = tree_open_int(sroot, spkg, true);
-   char buf[_Q_PATH_MAX];
+   int fd;
 
if (ret != NULL) {
ret->cachetype = CACHE_BINPKGS;
 
-   snprintf(buf, sizeof(buf), "%s%s/%s", sroot, spkg, 
binpkg_packages);
-   if (eat_file(buf, >pkgs, >pkgslen)) {
+   fd = openat(ret->tree_fd, binpkg_packages, O_RDONLY | 
O_CLOEXEC);
+   if (eat_file_fd(fd, >pkgs, >pkgslen)) {
ret->cachetype = CACHE_PACKAGES;
} else if (ret->pkgs != NULL) {
free(ret->pkgs);
ret->pkgs = NULL;
}
+   close(fd);
}
 
return ret;



[gentoo-commits] proj/portage-utils:master commit in: libq/

2020-05-25 Thread Fabian Groffen
commit: f6d31778569b3bb53a743515a8993aa64cdf0bfe
Author: Fabian Groffen  gentoo  org>
AuthorDate: Mon May 25 10:28:35 2020 +
Commit: Fabian Groffen  gentoo  org>
CommitDate: Mon May 25 10:28:35 2020 +
URL:https://gitweb.gentoo.org/proj/portage-utils.git/commit/?id=f6d31778

libq/atom: add atom_clone function

atom_clone() does a deep copy of the given atom, such that it lives
completely on its own and needs its own atom_implode() call.

Signed-off-by: Fabian Groffen  gentoo.org>

 libq/atom.c | 106 
 libq/atom.h |   1 +
 2 files changed, 107 insertions(+)

diff --git a/libq/atom.c b/libq/atom.c
index e79c30a..7e72bf3 100644
--- a/libq/atom.c
+++ b/libq/atom.c
@@ -355,6 +355,112 @@ atom_explode(const char *atom)
return ret;
 }
 
+depend_atom *
+atom_clone(depend_atom *atom)
+{
+   depend_atom *ret;
+   char *p;
+   size_t alen;
+   size_t clen = 0;
+   size_t flen = 0;
+   size_t plen = 0;
+   size_t nlen = 0;
+   size_t slen = 0;
+   size_t rlen = 0;
+
+   if (atom->REPO != NULL)
+   rlen = strlen(atom->REPO) + 1;
+   if (atom->SLOT != NULL)
+   slen = strlen(atom->SLOT) + 1;
+   if (atom->CATEGORY != NULL)
+   clen = strlen(atom->CATEGORY) + 1;
+   if (atom->PF != NULL)
+   flen = strlen(atom->PF) + 1;  /* should include PVR */
+   if (atom->P != NULL)
+   plen = strlen(atom->P) + 1;  /* should include PV */
+   if (atom->PN != NULL)
+   nlen = strlen(atom->PN) + 1;
+
+   alen = sizeof(*ret) + clen + flen + plen + nlen + rlen + slen;
+   ret = xmalloc(alen);
+   memset(ret, '\0', sizeof(*ret));
+
+   /* build up main storage pointers, see explode */
+   p = (char *)ret + sizeof(*ret);
+   if (atom->CATEGORY != NULL) {
+   ret->CATEGORY = p;
+   memcpy(ret->CATEGORY, atom->CATEGORY, clen);
+   p += clen;
+   }
+   if (atom->PF != NULL) {
+   ret->PF = p;
+   memcpy(ret->PF, atom->PF, flen);
+   p += flen;
+   }
+   if (atom->PVR > atom->PF && atom->PVR < (atom->PF + flen))
+   ret->PVR = ret->PF + (atom->PVR - atom->PF);
+   if (atom->P != NULL) {
+   ret->P = p;
+   memcpy(ret->P, atom->P, plen);
+   p += plen;
+   }
+   if (atom->PV > atom->P && atom->PV < (atom->P + plen))
+   ret->PV = ret->P + (atom->PV - atom->P);
+   if (atom->PN != NULL) {
+   ret->PN = p;
+   memcpy(ret->PN, atom->PN, nlen);
+   p += nlen;
+   }
+   if (atom->SLOT != NULL) {
+   ret->SLOT = p;
+   memcpy(ret->SLOT, atom->SLOT, slen);
+   p += slen;
+   }
+   if (atom->SUBSLOT > atom->SLOT && atom->SUBSLOT < (atom->SLOT + slen))
+   ret->SUBSLOT = ret->SLOT + (atom->SUBSLOT - atom->SLOT);
+   if (atom->REPO != NULL) {
+   ret->REPO = p;
+   memcpy(ret->REPO, atom->REPO, rlen);
+   p += rlen;
+   }
+
+   ret->blocker = atom->blocker;
+   ret->pfx_op = atom->pfx_op;
+   ret->sfx_op = atom->pfx_op;
+   ret->PR_int = atom->PR_int;
+   ret->letter = atom->letter;
+   ret->slotdep = atom->slotdep;
+
+   if (atom->suffixes != NULL) {
+   for (slen = 0; atom->suffixes[slen].suffix != VER_NORM; slen++)
+   ;
+   slen++;
+   ret->suffixes = xmalloc(sizeof(ret->suffixes[0]) * slen);
+   memcpy(ret->suffixes, atom->suffixes, sizeof(ret->suffixes[0]) 
* slen);
+   }
+
+   if (atom->usedeps) {
+   atom_usedep *w;
+   atom_usedep *n = NULL;
+
+   for (w = atom->usedeps; w != NULL; w = w->next) {
+   nlen = w->use != NULL ? strlen(w->use) + 1 : 0;
+   if (n == NULL) {
+   atom->usedeps = n = xmalloc(sizeof(*n) + nlen);
+   } else {
+   n = n->next = xmalloc(sizeof(*n) + nlen);
+   }
+   n->next = NULL;
+   n->pfx_cond = w->pfx_cond;
+   n->sfx_cond = w->sfx_cond;
+   n->use = (char *)n + sizeof(*n);
+   memcpy(n->use, w->use, nlen);
+   }
+   }
+
+   return ret;
+}
+
 void
 atom_implode(depend_atom *atom)
 {

diff --git a/libq/atom.h b/libq/atom.h
index 1548dd9..aff4548 100644
--- a/libq/atom.h
+++ b/libq/atom.h
@@ -97,6 +97,7 @@ typedef enum {
 } atom_equality;
 
 depend_atom *atom_explode(const char *atom);
+depend_atom *atom_clone(depend_atom *atom);
 void atom_implode(depend_atom *atom);
 atom_equality atom_compare(const depend_atom *a1, const depend_atom *a2);
 atom_equality atom_compare_str(const char * 

[gentoo-commits] proj/portage-utils:master commit in: libq/

2020-05-25 Thread Fabian Groffen
commit: 553eb9afd1a57bbe56b77ddf0bb450ee32b8
Author: Fabian Groffen  gentoo  org>
AuthorDate: Mon May 25 10:34:54 2020 +
Commit: Fabian Groffen  gentoo  org>
CommitDate: Mon May 25 10:34:54 2020 +
URL:https://gitweb.gentoo.org/proj/portage-utils.git/commit/?id=553eb9af

libq/tree: rework tree_match_atom to return a list of results

Major change is that multiple results are returned, somewhat controlled
by flags, and that the results are valid until the tree is closed.  Each
match result needs to be closed individually though.

This required some hoops to make it work with Packages file or binpkg
repos.  The latter are largely simulated now, and do not really benefit
from the cheaper point and lookup approach that tree_match_atom tries to
provide.

Signed-off-by: Fabian Groffen  gentoo.org>

 libq/tree.c | 181 
 libq/tree.h |  21 ++-
 2 files changed, 177 insertions(+), 25 deletions(-)

diff --git a/libq/tree.c b/libq/tree.c
index 4b9109e..d313f3b 100644
--- a/libq/tree.c
+++ b/libq/tree.c
@@ -388,14 +388,11 @@ tree_filter_pkg(const struct dirent *de)
 tree_pkg_ctx *
 tree_open_pkg(tree_cat_ctx *cat_ctx, const char *name)
 {
-   tree_pkg_ctx *pkg_ctx = xmalloc(sizeof(*pkg_ctx));
+   tree_pkg_ctx *pkg_ctx = xzalloc(sizeof(*pkg_ctx));
pkg_ctx->name = name;
-   pkg_ctx->slot = NULL;
pkg_ctx->repo = cat_ctx->ctx->repo;
pkg_ctx->fd = -1;
pkg_ctx->cat_ctx = cat_ctx;
-   pkg_ctx->atom = NULL;
-   pkg_ctx->meta = NULL;
 
/* see if this pkg matches the query, here we can finally check
 * version conditions like >=, etc. */
@@ -1405,12 +1402,14 @@ tree_foreach_packages(tree_ctx *ctx, tree_pkg_cb 
callback, void *priv)
match_key(IUSE);
match_key(KEYWORDS);
match_key(LICENSE);
-   match_key2(MD5, _md5_);
-   match_key2(SHA1, _eclasses_);
+   match_key(MD5);
+   match_key(SHA1);
match_key(RDEPEND);
match_key(SLOT);
match_key(USE);
match_key(PDEPEND);
+   match_key2(REPO, repository);
+   match_key(SIZE);
 #undef match_key
 #undef match_key2
}
@@ -1430,6 +1429,7 @@ tree_foreach_packages(tree_ctx *ctx, tree_pkg_cb 
callback, void *priv)
/* ensure we don't free a garbage pointer */
ctx->repo = NULL;
ctx->do_sort = false;
+   ctx->pkgs[0] = '\0';
 
return ret;
 }
@@ -1580,34 +1580,167 @@ tree_get_atoms(tree_ctx *ctx, bool fullcpv, set 
*satoms)
return state.cpf;
 }
 
-tree_pkg_ctx *
-tree_match_atom(tree_ctx *ctx, depend_atom *a)
+struct tree_match_pkgs_cb_ctx {
+   int flags;
+   tree_match_ctx *ret;
+};
+
+static int
+tree_match_atom_packages_cb(tree_pkg_ctx *ctx, void *priv)
+{
+   struct tree_match_pkgs_cb_ctx *rctx = priv;
+   depend_atom *a;
+   tree_match_ctx *n;
+
+   /* skip anything after finding first match */
+   if (rctx->flags & TREE_MATCH_FIRST && rctx->ret != NULL)
+   return 1;
+
+   a = tree_get_atom(ctx, rctx->flags & TREE_MATCH_FULL_ATOM);
+
+   /* skip virtual category if not requested */
+   if (!(rctx->flags & TREE_MATCH_VIRTUAL) &&
+   strcmp(a->CATEGORY, "virtual") == 0)
+   return 1;
+
+   n = xzalloc(sizeof(tree_match_ctx));
+   n->free_atom = true;
+   n->atom = atom_clone(a);
+   if (rctx->flags & TREE_MATCH_METADATA) {
+   n->meta = xmalloc(sizeof(*n->meta));
+   /* for Packages, all pointers to meta here are to the in memory
+* copy of the Packages file, so these pointers can just be
+* copied since the tree has to remain open, thus the pointers
+* will stay valid */
+   memcpy(n->meta, ctx->cat_ctx->ctx->pkgs, sizeof(*n->meta));
+   }
+
+   n->next = rctx->ret;
+   rctx->ret = n;
+
+   return 0;
+}
+
+static int
+tree_match_atom_binpkg_cb(tree_pkg_ctx *ctx, void *priv)
+{
+   struct tree_match_pkgs_cb_ctx *rctx = priv;
+   depend_atom *a;
+   tree_match_ctx *n;
+
+   /* skip anything after finding first match */
+   if (rctx->flags & TREE_MATCH_FIRST && rctx->ret != NULL)
+   return 1;
+
+   a = tree_get_atom(ctx, rctx->flags & TREE_MATCH_FULL_ATOM);
+
+   /* skip virtual category if not requested */
+   if (!(rctx->flags & TREE_MATCH_VIRTUAL) &&
+   strcmp(a->CATEGORY, "virtual") == 0)
+   return 1;
+
+   n = xzalloc(sizeof(tree_match_ctx));
+   n->free_atom = true;
+   n->atom = atom_clone(a);
+   if (rctx->flags & TREE_MATCH_METADATA)
+   n->meta = tree_pkg_read(ctx);
+
+   n->next = rctx->ret;
+   rctx->ret = n;
+
+   return 0;
+}
+
+tree_match_ctx *
+tree_match_atom(tree_ctx 

[gentoo-commits] proj/portage-utils:master commit in: libq/

2020-05-25 Thread Fabian Groffen
commit: 3794f21d3da7f182c85b63e87f0e073b5df3de18
Author: Fabian Groffen  gentoo  org>
AuthorDate: Mon May 25 10:32:27 2020 +
Commit: Fabian Groffen  gentoo  org>
CommitDate: Mon May 25 10:32:27 2020 +
URL:https://gitweb.gentoo.org/proj/portage-utils.git/commit/?id=3794f21d

libq/tree: have tree_read_file_binpkg populate some meta fields

The SHA1 and SIZE fields might be necessary, so psuedo fill them in
here, as we don't have a meta that contains them, except the file
itself.

Signed-off-by: Fabian Groffen  gentoo.org>

 libq/tree.c | 39 +++
 1 file changed, 39 insertions(+)

diff --git a/libq/tree.c b/libq/tree.c
index 7fbb739..d901fc6 100644
--- a/libq/tree.c
+++ b/libq/tree.c
@@ -17,6 +17,7 @@
 
 #include "atom.h"
 #include "eat_file.h"
+#include "hash.h"
 #include "rmspace.h"
 #include "scandirat.h"
 #include "set.h"
@@ -982,10 +983,48 @@ static tree_pkg_meta *
 tree_read_file_binpkg(tree_pkg_ctx *pkg_ctx)
 {
tree_pkg_meta *m = xzalloc(sizeof(tree_pkg_meta));
+   int newfd = dup(pkg_ctx->fd);
 
xpak_process_fd(pkg_ctx->fd, true, m, tree_read_file_binpkg_xpak_cb);
pkg_ctx->fd = -1;  /* closed by xpak_process_fd */
 
+   /* fill in some properties which are not available, but would be in
+* Packages, and used to verify the package ... this is somewhat
+* fake, but allows to transparantly use a dir of binpkgs */
+   if (newfd != -1) {
+   size_t fsize;
+   size_t needlen = 40 + 1 + 19 + 1;
+   size_t pos = (size_t)m->Q__eclasses_;
+   size_t len = (size_t)m->Q__md5_;
+
+   if (len - pos < needlen) {
+   char *old_data = m->Q__data;
+   len += ((needlen / BUFSIZ) + 1) * BUFSIZ;
+   m->Q__data = xrealloc(m->Q__data, len);
+   m->Q__md5_ = (char *)len;
+
+   /* re-position existing keys */
+   if (old_data != NULL && m->Q__data != old_data) {
+   char **newdata = (char **)m;
+   int elems = sizeof(tree_pkg_meta) / sizeof(char 
*);
+   while (elems-- > 1)  /* skip Q__data itself */
+   if (newdata[elems] != NULL)
+   newdata[elems] =
+   m->Q__data + 
(newdata[elems] - old_data);
+   }
+   }
+
+   m->Q_SHA1 = m->Q__data + pos;
+   m->Q_SIZE = m->Q_SHA1 + 40 + 1;
+   pos += needlen;
+   m->Q__eclasses_ = (char *)pos;
+
+   lseek(newfd, 0, SEEK_SET);  /* reposition at the whole file */
+   if (hash_multiple_file_fd(newfd, NULL, m->Q_SHA1, NULL, NULL,
+   NULL, NULL, , HASH_SHA1) == 0)
+   snprintf(m->Q_SIZE, 19 + 1, "%zu", fsize);
+   }
+
return m;
 }
 



[gentoo-commits] proj/portage-utils:master commit in: libq/

2020-05-17 Thread Fabian Groffen
commit: 0d354ac463a11013068f61cb7c1db987048f2a12
Author: Fabian Groffen  gentoo  org>
AuthorDate: Sun May 17 10:03:34 2020 +
Commit: Fabian Groffen  gentoo  org>
CommitDate: Sun May 17 10:03:34 2020 +
URL:https://gitweb.gentoo.org/proj/portage-utils.git/commit/?id=0d354ac4

xpak: change xpak_process to return start position of XPAKPACK

Allow to get the size of the archive by a call to xpak_process, or
failure if size is -1.

Signed-off-by: Fabian Groffen  gentoo.org>

 libq/xpak.c | 14 +-
 1 file changed, 9 insertions(+), 5 deletions(-)

diff --git a/libq/xpak.c b/libq/xpak.c
index 59c541d..0e8bd7e 100644
--- a/libq/xpak.c
+++ b/libq/xpak.c
@@ -1,5 +1,5 @@
 /*
- * Copyright 2005-2019 Gentoo Foundation
+ * Copyright 2005-2020 Gentoo Foundation
  * Distributed under the terms of the GNU General Public License v2
  *
  * Copyright 2005-2010 Ned Ludd- 
@@ -46,9 +46,11 @@
 typedef struct {
void *ctx;
FILE *fp;
+   unsigned int xpakstart;  /* offset in the file for XPAKPACK */
unsigned int index_len;
unsigned int data_len;
-   char *index, *data;
+   char *index;
+   char *data;
 } _xpak_archive;
 
 static void _xpak_walk_index(
@@ -119,6 +121,7 @@ static _xpak_archive *_xpak_open(const int fd)
 
if (fseek(ret.fp, -(xpaklen + TBZ2_FOOTER_LEN), 
SEEK_END) == 0)
{
+   ret.xpakstart = (unsigned 
int)ftell(ret.fp);
if (fread(buf, 1, XPAK_START_LEN, 
ret.fp) != XPAK_START_LEN)
goto close_and_ret;
if (memcmp(buf, XPAK_START_MSG, 
XPAK_START_MSG_LEN) == 0)
@@ -129,6 +132,7 @@ static _xpak_archive *_xpak_open(const int fd)
warn("Not an xpak file");
goto close_and_ret;
}
+   ret.xpakstart = 0;  /* pure xpak file */
 
 setup_lens:
/* calc index and data sizes */
@@ -165,7 +169,7 @@ xpak_process_fd(
 
x = _xpak_open(fd);
if (!x)
-   return 1;
+   return -1;
 
x->ctx = ctx;
x->index = buf;
@@ -196,7 +200,7 @@ xpak_process_fd(
if (get_data)
free(x->data);
 
-   return 0;
+   return x->xpakstart;
 }
 
 int
@@ -215,7 +219,7 @@ xpak_process(
return -1;
 
ret = xpak_process_fd(fd, get_data, ctx, func);
-   if (ret != 0)
+   if (ret < 0)
warn("Unable to open file '%s'", file);
 
return ret;



[gentoo-commits] proj/portage-utils:master commit in: libq/

2020-05-17 Thread Fabian Groffen
commit: 2dce04019d38a49f7930db13e62dd47ecf5f9471
Author: Fabian Groffen  gentoo  org>
AuthorDate: Sun May 17 12:32:52 2020 +
Commit: Fabian Groffen  gentoo  org>
CommitDate: Sun May 17 12:32:52 2020 +
URL:https://gitweb.gentoo.org/proj/portage-utils.git/commit/?id=2dce0401

hash_multiple_file_fd: return success status

Signed-off-by: Fabian Groffen  gentoo.org>

 libq/hash.c | 29 ++---
 libq/hash.h |  4 ++--
 2 files changed, 20 insertions(+), 13 deletions(-)

diff --git a/libq/hash.c b/libq/hash.c
index a174a0c..a51ea6a 100644
--- a/libq/hash.c
+++ b/libq/hash.c
@@ -113,7 +113,7 @@ hash_hex(char *out, const unsigned char *buf, const int 
length)
  * left untouched, e.g. they can be NULL.  The number of bytes read from
  * the file pointed to by fname is returned in the flen argument.
  */
-void
+int
 hash_multiple_file_fd(
int fd,
char *md5,
@@ -148,7 +148,7 @@ hash_multiple_file_fd(
 #endif
 
if ((f = fdopen(fd, "r")) == NULL)
-   return;
+   return -1;
 
 #ifdef HAVE_SSL
MD5_Init();
@@ -164,6 +164,7 @@ hash_multiple_file_fd(
blake2b_init(, BLAKE2B_OUTBYTES);
 #endif
 
+   *flen = 0;
while ((len = fread(data, 1, sizeof(data), f)) > 0) {
*flen += len;
 #pragma omp parallel sections
@@ -291,9 +292,10 @@ hash_multiple_file_fd(
}
 
fclose(f);
+   return 0;
 }
 
-void
+int
 hash_multiple_file_at_cb(
int pfd,
const char *fname,
@@ -307,19 +309,23 @@ hash_multiple_file_at_cb(
size_t *flen,
int hashes)
 {
+   int ret;
int fd = openat(pfd, fname, O_RDONLY | O_CLOEXEC);
-   if (fd == -1) {
-   *flen = 0;
-   return;
-   }
 
-   if (cb != NULL)
+   if (fd == -1)
+   return -1;
+
+   if (cb != NULL) {
fd = cb(fd, fname);
+   if (fd == -1)
+   return -1;
+   }
 
-   hash_multiple_file_fd(fd, md5, sha1, sha256, sha512,
+   ret = hash_multiple_file_fd(fd, md5, sha1, sha256, sha512,
whrlpl, blak2b, flen, hashes);
 
close(fd);
+   return ret;
 }
 
 static char _hash_file_buf[128 + 1];
@@ -335,10 +341,11 @@ hash_file_at_cb(int pfd, const char *fname, int hash, 
hash_cb_t cb)
case HASH_SHA512:
case HASH_WHIRLPOOL:
case HASH_BLAKE2B:
-   hash_multiple_file_at_cb(pfd, fname, cb,
+   if (hash_multiple_file_at_cb(pfd, fname, cb,
_hash_file_buf, _hash_file_buf, 
_hash_file_buf,
_hash_file_buf, _hash_file_buf, 
_hash_file_buf,
-   , hash);
+   , hash) != 0)
+   return NULL;
break;
default:
return NULL;

diff --git a/libq/hash.h b/libq/hash.h
index 204da5f..f85080d 100644
--- a/libq/hash.h
+++ b/libq/hash.h
@@ -30,10 +30,10 @@ enum hash_impls {
 typedef int (*hash_cb_t) (int, const char *);
 
 void hash_hex(char *out, const unsigned char *buf, const int length);
-void hash_multiple_file_fd(
+int hash_multiple_file_fd(
int fd, char *md5, char *sha1, char *sha256, char *sha512,
char *whrlpl, char *blak2b, size_t *flen, int hashes);
-void hash_multiple_file_at_cb(
+int hash_multiple_file_at_cb(
int pfd, const char *fname, hash_cb_t cb, char *md5,
char *sha1, char *sha256, char *sha512, char *whrlpl,
char *blak2b, size_t *flen, int hashes);



[gentoo-commits] proj/portage-utils:master commit in: /, libq/

2020-05-16 Thread Fabian Groffen
commit: dcab7ec282cfb8827a95c59c51322271d14d91c4
Author: Fabian Groffen  gentoo  org>
AuthorDate: Sat May 16 18:24:45 2020 +
Commit: Fabian Groffen  gentoo  org>
CommitDate: Sat May 16 18:24:45 2020 +
URL:https://gitweb.gentoo.org/proj/portage-utils.git/commit/?id=dcab7ec2

libq/hash: unify hash methods into single approach

remove duplicate hashing strategies, use private copies of md5 and sha1
hashes when ssl is not available, else rely on ssl to provide hashing
capabilities

Signed-off-by: Fabian Groffen  gentoo.org>

 Makefile.am |  11 +--
 Makefile.in |  50 +--
 libq/Makefile.am|   8 +-
 libq/Makefile.in|  93 
 libq/hash.c | 165 +---
 libq/hash.h |  34 ++--
 libq/hash_fd.h  |  13 ---
 libq/{hash_fd.c => hash_md5_sha1.c} | 125 ++-
 libq/hash_md5_sha1.h|  35 
 libq/md5_sha1_sum.c |  93 
 libq/md5_sha1_sum.h |  24 --
 qcheck.c|  10 +--
 qmerge.c|  14 ++-
 qpkg.c  |   7 +-
 14 files changed, 301 insertions(+), 381 deletions(-)

diff --git a/Makefile.am b/Makefile.am
index 3107bda..ceded24 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -69,10 +69,12 @@ q_CPPFLAGS = \
-I$(top_srcdir)/libq \
-I$(top_builddir)/autotools/gnulib \
-I$(top_srcdir)/autotools/gnulib \
+   $(OPENMP_CFLAGS) \
$(NULL)
 q_LDADD = \
$(top_builddir)/libq/libq.la \
$(top_builddir)/autotools/gnulib/libgnu.a \
+   $(OPENMP_CFLAGS) \
$(LIBSSL) \
$(LIBBL2) \
$(LIBZ) \
@@ -84,21 +86,12 @@ q_LDADD = \
 if QMANIFEST_ENABLED
 q_SOURCES += qmanifest.c
 q_CPPFLAGS += \
-   $(OPENMP_CFLAGS) \
$(GPGME_CFLAGS)
-q_LDADD += \
-   $(OPENMP_CFLAGS)
 dist_man_MANS += man/qmanifest.1
 APPLETS += qmanifest
 endif
 if QTEGRITY_ENABLED
 q_SOURCES += qtegrity.c
-if !QMANIFEST_ENABLED
-q_CPPFLAGS += \
-   $(OPENMP_CFLAGS)
-q_LDADD += \
-   $(OPENMP_CFLAGS)
-endif
 dist_man_MANS += man/qtegrity.1
 APPLETS += qtegrity
 endif

diff --git a/Makefile.in b/Makefile.in
index 7403b5b..91d9a3b 100644
--- a/Makefile.in
+++ b/Makefile.in
@@ -91,23 +91,13 @@ host_triplet = @host@
 bin_PROGRAMS = q$(EXEEXT)
 @QMANIFEST_ENABLED_TRUE@am__append_1 = qmanifest.c
 @QMANIFEST_ENABLED_TRUE@am__append_2 = \
-@QMANIFEST_ENABLED_TRUE@   $(OPENMP_CFLAGS) \
 @QMANIFEST_ENABLED_TRUE@   $(GPGME_CFLAGS)
 
-@QMANIFEST_ENABLED_TRUE@am__append_3 = \
-@QMANIFEST_ENABLED_TRUE@   $(OPENMP_CFLAGS)
-
-@QMANIFEST_ENABLED_TRUE@am__append_4 = man/qmanifest.1
-@QMANIFEST_ENABLED_TRUE@am__append_5 = qmanifest
-@QTEGRITY_ENABLED_TRUE@am__append_6 = qtegrity.c
-@QMANIFEST_ENABLED_FALSE@@QTEGRITY_ENABLED_TRUE@am__append_7 = \
-@QMANIFEST_ENABLED_FALSE@@QTEGRITY_ENABLED_TRUE@   $(OPENMP_CFLAGS)
-
-@QMANIFEST_ENABLED_FALSE@@QTEGRITY_ENABLED_TRUE@am__append_8 = \
-@QMANIFEST_ENABLED_FALSE@@QTEGRITY_ENABLED_TRUE@   $(OPENMP_CFLAGS)
-
-@QTEGRITY_ENABLED_TRUE@am__append_9 = man/qtegrity.1
-@QTEGRITY_ENABLED_TRUE@am__append_10 = qtegrity
+@QMANIFEST_ENABLED_TRUE@am__append_3 = man/qmanifest.1
+@QMANIFEST_ENABLED_TRUE@am__append_4 = qmanifest
+@QTEGRITY_ENABLED_TRUE@am__append_5 = qtegrity.c
+@QTEGRITY_ENABLED_TRUE@am__append_6 = man/qtegrity.1
+@QTEGRITY_ENABLED_TRUE@am__append_7 = qtegrity
 subdir = .
 ACLOCAL_M4 = $(top_srcdir)/aclocal.m4
 am__aclocal_m4_deps = $(top_srcdir)/autotools/m4/00gnulib.m4 \
@@ -278,14 +268,12 @@ am_q_OBJECTS = q-main.$(OBJEXT) q-q.$(OBJEXT) 
q-qatom.$(OBJEXT) \
$(am__objects_2)
 q_OBJECTS = $(am_q_OBJECTS)
 am__DEPENDENCIES_1 =
-@QMANIFEST_ENABLED_TRUE@am__DEPENDENCIES_2 = $(am__DEPENDENCIES_1)
-@QMANIFEST_ENABLED_FALSE@@QTEGRITY_ENABLED_TRUE@am__DEPENDENCIES_3 = 
$(am__DEPENDENCIES_1)
 q_DEPENDENCIES = $(top_builddir)/libq/libq.la \
$(top_builddir)/autotools/gnulib/libgnu.a \
$(am__DEPENDENCIES_1) $(am__DEPENDENCIES_1) \
$(am__DEPENDENCIES_1) $(am__DEPENDENCIES_1) \
$(am__DEPENDENCIES_1) $(am__DEPENDENCIES_1) \
-   $(am__DEPENDENCIES_2) $(am__DEPENDENCIES_3)
+   $(am__DEPENDENCIES_1)
 AM_V_lt = $(am__v_lt_@AM_V@)
 am__v_lt_ = $(am__v_lt_@AM_DEFAULT_V@)
 am__v_lt_0 = --silent
@@ -1598,21 +1586,29 @@ SUBDIRS = \
 
 APPLETS = q qatom qcheck qdepends qfile qgrep qkeyword qlist qlop \
qmerge qpkg qsearch qsize qtbz2 quse qxpak $(NULL) \
-   $(am__append_5) $(am__append_10)
+   $(am__append_4) $(am__append_7)
 dist_man_MANS = man/q.1 man/qatom.1 man/qcheck.1 man/qdepends.1 \
man/qfile.1 man/qgrep.1 man/qkeyword.1 man/qlist.1 man/qlop.1 \
man/qmerge.1 man/qpkg.1 man/qsearch.1 man/qsize.1 man/qtbz2.1 \
-   man/quse.1 man/qxpak.1 $(NULL) $(am__append_4) 

[gentoo-commits] proj/portage-utils:master commit in: libq/, /

2020-02-21 Thread Fabian Groffen
commit: 814f9ad4b3bfe41617e21f634b6facb84c2e1dfe
Author: Fabian Groffen  gentoo  org>
AuthorDate: Fri Feb 21 08:17:09 2020 +
Commit: Fabian Groffen  gentoo  org>
CommitDate: Fri Feb 21 08:17:09 2020 +
URL:https://gitweb.gentoo.org/proj/portage-utils.git/commit/?id=814f9ad4

libq/tree: respect SLOT in query atom for tree_open_pkg

Bug: https://bugs.gentoo.org/710372
Signed-off-by: Fabian Groffen  gentoo.org>

 TODO.md | 1 -
 libq/tree.c | 2 +-
 2 files changed, 1 insertion(+), 2 deletions(-)

diff --git a/TODO.md b/TODO.md
index 2cce64a..43c4d6a 100644
--- a/TODO.md
+++ b/TODO.md
@@ -46,7 +46,6 @@
 - support TTL field in binpkgs file
 - merge duplicate atoms on the CLI (`qmerge -Uq nano nano nano`)
 - unmerging should clean out @world set
-- test should work on local vdb (so TRAVIS can test it too)
 - fixup lame misnaming of force\_download (--fetch/--force) actually
   not-forcing things
 - use xpak.h instead of shelling out to qxpak binary

diff --git a/libq/tree.c b/libq/tree.c
index 1c2a54e..ebcc133 100644
--- a/libq/tree.c
+++ b/libq/tree.c
@@ -398,7 +398,7 @@ tree_open_pkg(tree_cat_ctx *cat_ctx, const char *name)
/* see if this pkg matches the query, here we can finally check
 * version conditions like >=, etc. */
if (cat_ctx->ctx->query_atom != NULL) {
-   (void)tree_get_atom(pkg_ctx, false);
+   (void)tree_get_atom(pkg_ctx, cat_ctx->ctx->query_atom->SLOT != 
NULL);
if (atom_compare(pkg_ctx->atom, cat_ctx->ctx->query_atom) != 
EQUAL) {
tree_close_pkg(pkg_ctx);
return NULL;



[gentoo-commits] proj/portage-utils:master commit in: libq/

2020-02-03 Thread Fabian Groffen
commit: 38bb361b2a8ed4bcf9b6f9ee3eb48ccd815bb382
Author: Fabian Groffen  gentoo  org>
AuthorDate: Mon Feb  3 13:15:48 2020 +
Commit: Fabian Groffen  gentoo  org>
CommitDate: Mon Feb  3 13:15:48 2020 +
URL:https://gitweb.gentoo.org/proj/portage-utils.git/commit/?id=38bb361b

libq/tree: be more conservative with mem-clearing

Previous fix cleared unnecessary amounts of memory (immediately
overwritten by fread()), use a memset on the area of memory required.

Signed-off-by: Fabian Groffen  gentoo.org>

 libq/tree.c | 8 +---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/libq/tree.c b/libq/tree.c
index 8424459..1c2a54e 100644
--- a/libq/tree.c
+++ b/libq/tree.c
@@ -689,8 +689,9 @@ tree_read_file_md5(tree_pkg_ctx *pkg_ctx)
goto err;
 
len = sizeof(*ret) + s.st_size + 1;
-   ret = xzalloc(len);
-   ptr = (char*)ret + sizeof(*ret);
+   ret = xmalloc(len);
+   memset(ret, 0, sizeof(*ret));
+   ptr = (char *)ret + sizeof(*ret);
if ((off_t)fread(ptr, 1, s.st_size, f) != s.st_size)
goto err;
ptr[s.st_size] = '\0';
@@ -802,7 +803,8 @@ tree_read_file_ebuild(tree_pkg_ctx *pkg_ctx)
goto err;
 
len = sizeof(*ret) + s.st_size + 1;
-   ret = xzalloc(len);
+   ret = xmalloc(len);
+   memset(ret, 0, sizeof(*ret));
p = (char *)ret + sizeof(*ret);
if ((off_t)fread(p, 1, s.st_size, f) != s.st_size)
goto err;



[gentoo-commits] proj/portage-utils:master commit in: libq/

2020-02-03 Thread Fabian Groffen
commit: a7182e09e90bcd37cca9f56639f604a809ab4c1d
Author: Fabian Groffen  gentoo  org>
AuthorDate: Mon Feb  3 13:07:47 2020 +
Commit: Fabian Groffen  gentoo  org>
CommitDate: Mon Feb  3 13:07:47 2020 +
URL:https://gitweb.gentoo.org/proj/portage-utils.git/commit/?id=a7182e09

libq/tree: ensure meta fields are clear when not set

For some reason we went with uncleared pointers.  Probably because we
only requested things that should/would exist.  However, for sanity, and
probably bug #701470, return NULL pointers for anything not set (in
metadata).

Bug: https://bugs.gentoo.org/show_bug.cgi?id=701470
Signed-off-by: Fabian Groffen  gentoo.org>

 libq/tree.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/libq/tree.c b/libq/tree.c
index 9df3541..8424459 100644
--- a/libq/tree.c
+++ b/libq/tree.c
@@ -621,7 +621,7 @@ tree_read_file_pms(tree_pkg_ctx *pkg_ctx)
goto err;
 
len = sizeof(*ret) + s.st_size + 1;
-   ret = xmalloc(len);
+   ret = xzalloc(len);
ptr = (char*)ret + sizeof(*ret);
if ((off_t)fread(ptr, 1, s.st_size, f) != s.st_size)
goto err;
@@ -689,7 +689,7 @@ tree_read_file_md5(tree_pkg_ctx *pkg_ctx)
goto err;
 
len = sizeof(*ret) + s.st_size + 1;
-   ret = xmalloc(len);
+   ret = xzalloc(len);
ptr = (char*)ret + sizeof(*ret);
if ((off_t)fread(ptr, 1, s.st_size, f) != s.st_size)
goto err;
@@ -802,7 +802,7 @@ tree_read_file_ebuild(tree_pkg_ctx *pkg_ctx)
goto err;
 
len = sizeof(*ret) + s.st_size + 1;
-   ret = xmalloc(len);
+   ret = xzalloc(len);
p = (char *)ret + sizeof(*ret);
if ((off_t)fread(p, 1, s.st_size, f) != s.st_size)
goto err;



[gentoo-commits] proj/portage-utils:master commit in: libq/

2020-01-26 Thread Fabian Groffen
commit: 982ea6b9dcea2a86d3772c99cff9ada0c400bf29
Author: Fabian Groffen  gentoo  org>
AuthorDate: Sun Jan 26 19:30:45 2020 +
Commit: Fabian Groffen  gentoo  org>
CommitDate: Sun Jan 26 19:30:45 2020 +
URL:https://gitweb.gentoo.org/proj/portage-utils.git/commit/?id=982ea6b9

libq/xpak: fix Coverity 125939 Time of check time of use

Signed-off-by: Fabian Groffen  gentoo.org>

 libq/xpak.c | 38 +++---
 1 file changed, 23 insertions(+), 15 deletions(-)

diff --git a/libq/xpak.c b/libq/xpak.c
index 90a3570..59c541d 100644
--- a/libq/xpak.c
+++ b/libq/xpak.c
@@ -223,7 +223,7 @@ xpak_process(
 
 static void
 _xpak_add_file(
-   int dir_fd,
+   int fd,
const char *filename,
struct stat *st,
FILE *findex,
@@ -236,7 +236,7 @@ _xpak_add_file(
unsigned char intbuf[4];
unsigned char *p = intbuf;
const char *basefile;
-   int fd, in_len;
+   int in_len;
 
basefile = basename(filename);
 
@@ -259,28 +259,24 @@ _xpak_add_file(
 
/* now open the file, get (data_len),
 * and append the file to the data file */
-   fd = openat(dir_fd, filename, O_RDONLY|O_CLOEXEC);
-   if (fd < 0) {
- open_fail:
+   if ((fin = fdopen(fd, "r")) == NULL) {
warnp("could not open for reading: %s", filename);
- fake_data_len:
WRITE_BE_INT32(p, 0);
fwrite(p, 1, 4, findex);
return;
}
-   fin = fdopen(fd, "r");
-   if (!fin) {
-   close(fd);
-   goto open_fail;
-   }
+
in_len = st->st_size;
/* the xpak format can only store files whose size is a 32bit int
 * so we have to make sure we don't store a big file */
if (in_len != st->st_size) {
warnf("File is too big: %zu", (size_t)st->st_size);
fclose(fin);
-   goto fake_data_len;
+   WRITE_BE_INT32(p, 0);
+   fwrite(p, 1, 4, findex);
+   return;
}
+
WRITE_BE_INT32(p, in_len);
fwrite(p, 1, 4, findex);
copy_file(fin, fdata);
@@ -333,6 +329,8 @@ xpak_create(
 
index_len = data_len = 0;
for (i = 0; i < argc; ++i) {
+   int fd;
+
if (fstatat(dir_fd, argv[i], , 0)) {
warnp("fstatat(%s) failed", argv[i]);
continue;
@@ -344,22 +342,32 @@ xpak_create(
for (fidx = 0; fidx < numfiles; ++fidx) {
int ret = snprintf(path, sizeof(path), "%s/%s",
argv[i], dir[fidx]->d_name);
+
if (ret < 0 || (size_t)ret >= sizeof(path)) {
warn("skipping path too long: %s/%s",
argv[i], 
dir[fidx]->d_name);
continue;
}
-   if (stat(path, ) < 0) {
+
+   fd = openat(dir_fd, path, O_RDONLY|O_CLOEXEC);
+   if (fd < 0 || fstat(fd, ) < 0) {
warnp("could not read %s", path);
continue;
}
-   _xpak_add_file(dir_fd, path, ,
+   _xpak_add_file(fd, path, ,
findex, _len, fdata, 
_len, verbose);
+   close(fd);
}
scandir_free(dir, numfiles);
} else if (S_ISREG(st.st_mode)) {
-   _xpak_add_file(dir_fd, argv[i], ,
+   fd = openat(dir_fd, argv[i], O_RDONLY|O_CLOEXEC);
+   if (fd < 0 || fstat(fd, ) < 0) {
+   warnp("could not read %s", path);
+   continue;
+   }
+   _xpak_add_file(fd, argv[i], ,
findex, _len, fdata, _len, 
verbose);
+   close(fd);
} else
warn("Skipping non file/directory '%s'", argv[i]);
}



[gentoo-commits] proj/portage-utils:master commit in: libq/

2020-01-22 Thread Fabian Groffen
commit: f7f550ce23ea6c0db4ce33a816aa61e0e815cf91
Author: Fabian Groffen  gentoo  org>
AuthorDate: Wed Jan 22 19:29:30 2020 +
Commit: Fabian Groffen  gentoo  org>
CommitDate: Wed Jan 22 19:29:30 2020 +
URL:https://gitweb.gentoo.org/proj/portage-utils.git/commit/?id=f7f550ce

libq/eat_file: fix Coverity 125891 Ignoring number of bytes read

Signed-off-by: Fabian Groffen  gentoo.org>

 libq/eat_file.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/libq/eat_file.c b/libq/eat_file.c
index 6deabe2..85ba691 100644
--- a/libq/eat_file.c
+++ b/libq/eat_file.c
@@ -40,7 +40,7 @@ eat_file_fd(int fd, char **bufptr, size_t *bufsize)
/* We assume a min allocation size so that repeat calls don't
 * hit ugly ramp ups -- if you read a file that is 1 byte, then
 * 5 bytes, then 10 bytes, then 20 bytes, ... you'll allocate
-* constantly.  So we round up a few pages as wasiting virtual
+* constantly.  So we round up a few pages as wasting virtual
 * memory is cheap when it is unused.  */
*bufsize = ((read_size + 1) + BUFSIZE - 1) & -BUFSIZE;
*bufptr = xrealloc(*bufptr, *bufsize);
@@ -55,9 +55,9 @@ eat_file_fd(int fd, char **bufptr, size_t *bufsize)
return false;
buf[read_size] = '\0';
} else {
-   if (read(fd, buf, read_size) == 0)
+   if ((read_size = read(fd, buf, read_size)) <= 0)
return false;
-   buf[read_size - 1] = '\0';
+   buf[read_size] = '\0';
}
}
 



[gentoo-commits] proj/portage-utils:master commit in: libq/

2020-01-22 Thread Fabian Groffen
commit: 0501fd2dfe83fc29d44a5b45586fef33e63800f5
Author: Fabian Groffen  gentoo  org>
AuthorDate: Wed Jan 22 19:42:24 2020 +
Commit: Fabian Groffen  gentoo  org>
CommitDate: Wed Jan 22 19:42:24 2020 +
URL:https://gitweb.gentoo.org/proj/portage-utils.git/commit/?id=0501fd2d

libq/dep: fix Coverity 125901 Explicit null dereferenced

Signed-off-by: Fabian Groffen  gentoo.org>

 libq/dep.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libq/dep.c b/libq/dep.c
index 0507326..3667ae5 100644
--- a/libq/dep.c
+++ b/libq/dep.c
@@ -178,7 +178,7 @@ dep_grow_tree(const char *depend)
break;
_maybe_consume_word(DEP_NORM);
 
-   if (curr_node->parent == NULL) {
+   if (curr_node == NULL || curr_node->parent == NULL) {
warnf("Group lacks a parent");
goto error_out;
}



[gentoo-commits] proj/portage-utils:master commit in: libq/

2020-01-20 Thread Fabian Groffen
commit: 981f0a47acc281bcfec4faa966d0bfb447b28ddd
Author: Fabian Groffen  gentoo  org>
AuthorDate: Mon Jan 20 19:53:47 2020 +
Commit: Fabian Groffen  gentoo  org>
CommitDate: Mon Jan 20 19:53:47 2020 +
URL:https://gitweb.gentoo.org/proj/portage-utils.git/commit/?id=981f0a47

libq/colors: fix Coverity 183476 Buffer not null terminated

Signed-off-by: Fabian Groffen  gentoo.org>

 libq/colors.c | 7 ---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/libq/colors.c b/libq/colors.c
index 88664c3..9a48e2e 100644
--- a/libq/colors.c
+++ b/libq/colors.c
@@ -102,8 +102,9 @@ color_remap(void)
int found = 0;
for (n = 0; n < 
ARRAY_SIZE(color_pairs); n++) {
if (strcmp(color_pairs[n].name, 
p) == 0) {
-   
strncpy(color_pairs[i].value,
-   
color_pairs[n].origval, CPAIR_VALUE_LEN);
+   
snprintf(color_pairs[i].value,
+   
sizeof(color_pairs[i].value),
+   "%s", 
color_pairs[n].origval);
found = 1;
break;
}
@@ -111,7 +112,7 @@ color_remap(void)
 
if (!found)
snprintf(color_pairs[i].value,
-   
sizeof(color_pairs[i].origval), "\e[%s", p);
+   
sizeof(color_pairs[i].value), "\e[%s", p);
}
}
}



[gentoo-commits] proj/portage-utils:master commit in: libq/

2020-01-20 Thread Fabian Groffen
commit: 3cb097b70c46b499c7736d50ea6b683a8e4ac2b2
Author: Fabian Groffen  gentoo  org>
AuthorDate: Mon Jan 20 19:33:35 2020 +
Commit: Fabian Groffen  gentoo  org>
CommitDate: Mon Jan 20 19:33:35 2020 +
URL:https://gitweb.gentoo.org/proj/portage-utils.git/commit/?id=3cb097b7

libq/tree: fix Coverity 206560 Resource leak

Signed-off-by: Fabian Groffen  gentoo.org>

 libq/tree.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/libq/tree.c b/libq/tree.c
index 8da8120..9df3541 100644
--- a/libq/tree.c
+++ b/libq/tree.c
@@ -1366,6 +1366,9 @@ tree_foreach_packages(tree_ctx *ctx, tree_pkg_cb 
callback, void *priv)
tree_close_cat(cat);
}
 
+   if (atom != NULL)
+   atom_implode(atom);
+
/* ensure we don't free a garbage pointer */
ctx->repo = NULL;
ctx->do_sort = false;



[gentoo-commits] proj/portage-utils:master commit in: libq/

2020-01-19 Thread Fabian Groffen
commit: 5cdb5572185636cd5ab056241635d33b1b85fc98
Author: Fabian Groffen  gentoo  org>
AuthorDate: Sun Jan 19 19:18:48 2020 +
Commit: Fabian Groffen  gentoo  org>
CommitDate: Sun Jan 19 19:18:48 2020 +
URL:https://gitweb.gentoo.org/proj/portage-utils.git/commit/?id=5cdb5572

libq/tree: help Coverity 206538 String not null terminated

Coverity doesn't see that zalloc would have null-terminated.  Upside,
replace zalloc with malloc and just clear one (relevant) byte.

Signed-off-by: Fabian Groffen  gentoo.org>

 libq/tree.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/libq/tree.c b/libq/tree.c
index c8ada5c..8da8120 100644
--- a/libq/tree.c
+++ b/libq/tree.c
@@ -689,10 +689,11 @@ tree_read_file_md5(tree_pkg_ctx *pkg_ctx)
goto err;
 
len = sizeof(*ret) + s.st_size + 1;
-   ret = xzalloc(len);
+   ret = xmalloc(len);
ptr = (char*)ret + sizeof(*ret);
if ((off_t)fread(ptr, 1, s.st_size, f) != s.st_size)
goto err;
+   ptr[s.st_size] = '\0';
 
/* We have a block of key=value\n data.
 * KEY=VALUE\n



[gentoo-commits] proj/portage-utils:master commit in: libq/

2020-01-19 Thread Fabian Groffen
commit: 1c6dcbf136e0cfd7613dc696d482028453ee306b
Author: Fabian Groffen  gentoo  org>
AuthorDate: Sun Jan 19 18:15:56 2020 +
Commit: Fabian Groffen  gentoo  org>
CommitDate: Sun Jan 19 18:15:56 2020 +
URL:https://gitweb.gentoo.org/proj/portage-utils.git/commit/?id=1c6dcbf1

libq/tree: help for Coverity 206550 String not null terminated

the zalloc on buffer + 1 size should ensure null-termination, but
Coverity doesn't quite see this, so explicitly null-terminate the
string, thereby slightly optimising zalloc away for plain malloc

Signed-off-by: Fabian Groffen  gentoo.org>

 libq/tree.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/libq/tree.c b/libq/tree.c
index 9645237..dc6ee61 100644
--- a/libq/tree.c
+++ b/libq/tree.c
@@ -1164,13 +1164,14 @@ tree_pkg_metadata(tree_pkg_ctx *pkg_ctx)
}
 
len = sizeof(*ret) + s.st_size + 1;
-   p = xbuf = xzalloc(len);
+   p = xbuf = xmalloc(len);
if ((off_t)fread(p, 1, s.st_size, f) != s.st_size) {
free(p);
fclose(f);
pkg_ctx->fd = -1;
return NULL;
}
+   p[s.st_size] = '\0';
 
ret = xmalloc(sizeof(*ret));
ret->email = NULL;



[gentoo-commits] proj/portage-utils:master commit in: libq/

2020-01-19 Thread Fabian Groffen
commit: 00e2a72d50acf329a128b81f116e037c82f27c72
Author: Fabian Groffen  gentoo  org>
AuthorDate: Sun Jan 19 18:30:49 2020 +
Commit: Fabian Groffen  gentoo  org>
CommitDate: Sun Jan 19 18:30:49 2020 +
URL:https://gitweb.gentoo.org/proj/portage-utils.git/commit/?id=00e2a72d

libq/set: fix Coverity 206548 Sizeof not portable

Signed-off-by: Fabian Groffen  gentoo.org>

 libq/set.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libq/set.c b/libq/set.c
index ceb6f47..88b5876 100644
--- a/libq/set.c
+++ b/libq/set.c
@@ -252,7 +252,7 @@ list_set(set *q, char ***l)
set_elem *w;
char **ret;
 
-   ret = *l = xmalloc(sizeof(char **) * (q->len + 1));
+   ret = *l = xmalloc(sizeof(char *) * (q->len + 1));
for (i = 0; i < _SET_HASH_SIZE; i++) {
for (w = q->buckets[i]; w != NULL; w = w->next) {
*ret = w->name;



[gentoo-commits] proj/portage-utils:master commit in: libq/

2020-01-19 Thread Fabian Groffen
commit: f7d28b1055bc515d9e510329c2840c1993f75654
Author: Fabian Groffen  gentoo  org>
AuthorDate: Sun Jan 19 19:08:44 2020 +
Commit: Fabian Groffen  gentoo  org>
CommitDate: Sun Jan 19 19:08:44 2020 +
URL:https://gitweb.gentoo.org/proj/portage-utils.git/commit/?id=f7d28b10

libq/tree: fix Coverity 206542 Resource leak

Signed-off-by: Fabian Groffen  gentoo.org>

 libq/tree.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/libq/tree.c b/libq/tree.c
index dc6ee61..c8ada5c 100644
--- a/libq/tree.c
+++ b/libq/tree.c
@@ -553,7 +553,10 @@ tree_next_pkg(tree_cat_ctx *cat_ctx)
} while (ret == NULL);
} else if (ctx->cachetype == CACHE_BINPKGS) {
char *p = NULL;
+   ret = NULL;
do {
+   if (ret != NULL)
+   tree_close_pkg(ret);
ret = tree_next_pkg_int(cat_ctx);
} while (ret != NULL && (p = strstr(ret->name, ".tbz2")) == 
NULL);
if (p != NULL)



[gentoo-commits] proj/portage-utils:master commit in: libq/

2020-01-19 Thread Fabian Groffen
commit: c4e0ef9df105c2a1459d283cd3d977fcd31d363d
Author: Fabian Groffen  gentoo  org>
AuthorDate: Sun Jan 19 18:14:07 2020 +
Commit: Fabian Groffen  gentoo  org>
CommitDate: Sun Jan 19 18:14:07 2020 +
URL:https://gitweb.gentoo.org/proj/portage-utils.git/commit/?id=c4e0ef9d

libq/tree: fix Coverity 206551 String not null terminated

Signed-off-by: Fabian Groffen  gentoo.org>

 libq/tree.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/libq/tree.c b/libq/tree.c
index 2efdb7c..9645237 100644
--- a/libq/tree.c
+++ b/libq/tree.c
@@ -618,10 +618,11 @@ tree_read_file_pms(tree_pkg_ctx *pkg_ctx)
goto err;
 
len = sizeof(*ret) + s.st_size + 1;
-   ret = xzalloc(len);
+   ret = xmalloc(len);
ptr = (char*)ret + sizeof(*ret);
if ((off_t)fread(ptr, 1, s.st_size, f) != s.st_size)
goto err;
+   ptr[s.st_size] = '\0';
 
ret->Q_DEPEND = ptr;
 #define next_line(curr, next) \



[gentoo-commits] proj/portage-utils:master commit in: libq/

2020-01-19 Thread Fabian Groffen
commit: c8bf4b933d88520d7a9ad6f856412e62772f044f
Author: Fabian Groffen  gentoo  org>
AuthorDate: Sun Jan 19 16:31:23 2020 +
Commit: Fabian Groffen  gentoo  org>
CommitDate: Sun Jan 19 16:31:23 2020 +
URL:https://gitweb.gentoo.org/proj/portage-utils.git/commit/?id=c8bf4b93

libq/tree: fix Coverity 206560 Resource leak

Signed-off-by: Fabian Groffen  gentoo.org>

 libq/tree.c | 52 +---
 1 file changed, 37 insertions(+), 15 deletions(-)

diff --git a/libq/tree.c b/libq/tree.c
index 94f9665..2efdb7c 100644
--- a/libq/tree.c
+++ b/libq/tree.c
@@ -138,8 +138,12 @@ tree_open_binpkg(const char *sroot, const char *spkg)
ret->cachetype = CACHE_BINPKGS;
 
snprintf(buf, sizeof(buf), "%s%s/%s", sroot, spkg, 
binpkg_packages);
-   if (eat_file(buf, >pkgs, >pkgslen))
+   if (eat_file(buf, >pkgs, >pkgslen)) {
ret->cachetype = CACHE_PACKAGES;
+   } else if (ret->pkgs != NULL) {
+   free(ret->pkgs);
+   ret->pkgs = NULL;
+   }
}
 
return ret;
@@ -1237,10 +1241,12 @@ tree_foreach_packages(tree_ctx *ctx, tree_pkg_cb 
callback, void *priv)
 
/* reused for every entry */
tree_cat_ctx *cat = NULL;
-   tree_pkg_ctx *pkg = xzalloc(sizeof(tree_pkg_ctx));
-   tree_pkg_meta *meta = xzalloc(sizeof(tree_pkg_meta));
+   tree_pkg_ctx pkg;
+   tree_pkg_meta meta;
depend_atom *atom = NULL;
 
+   memset(, 0, sizeof(meta));
+
do {
/* find next line */
c = NULL;
@@ -1257,32 +1263,41 @@ tree_foreach_packages(tree_ctx *ctx, tree_pkg_cb 
callback, void *priv)
if (atom != NULL) {
size_t pkgnamelen;
 
+   memset(, 0, sizeof(pkg));
+
/* store meta ptr in repo->pkgs, such that 
get_pkg_meta
 * can grab it from there (for free) */
-   ctx->pkgs = (char *)meta;
+   c = ctx->pkgs;
+   ctx->pkgs = (char *)
 
if (cat == NULL || strcmp(cat->name, 
atom->CATEGORY) != 0)
{
-   if (cat != NULL)
+   if (cat != NULL) {
+   atom_implode((depend_atom 
*)cat->pkg_ctxs);
+   cat->pkg_ctxs = NULL;
tree_close_cat(cat);
-   pkg->cat_ctx = cat = tree_open_cat(ctx, 
atom->CATEGORY);
+   }
+   pkg.cat_ctx = cat = tree_open_cat(ctx, 
atom->CATEGORY);
+   cat->pkg_ctxs = (tree_pkg_ctx **)atom;  
/* for name */
}
pkgnamelen = snprintf(pkgname, sizeof(pkgname),
"%s.tbz2", atom->PF);
pkgname[pkgnamelen - (sizeof(".tbz2") - 1)] = 
'\0';
-   pkg->name = pkgname;
-   pkg->slot = meta->Q_SLOT == NULL ? (char *)"0" 
: meta->Q_SLOT;
-   pkg->repo = ctx->repo;
-   pkg->atom = atom;
-   pkg->fd = 0;  /* intentional, meta has already 
been read */
+   pkg.name = pkgname;
+   pkg.slot = meta.Q_SLOT == NULL ? (char *)"0" : 
meta.Q_SLOT;
+   pkg.repo = ctx->repo;
+   pkg.atom = atom;
+   pkg.fd = 0;  /* intentional, meta has already 
been read */
 
/* do call callback with pkg_atom (populate cat 
and pkg) */
-   ret |= callback(pkg, priv);
+   ret |= callback(, priv);
 
-   atom_implode(atom);
+   ctx->pkgs = c;
+   if (atom != (depend_atom *)cat->pkg_ctxs)
+   atom_implode(atom);
}
 
-   memset(meta, 0, sizeof(meta[0]));
+   memset(, 0, sizeof(meta));
atom = NULL;
if (len > 0) {  /* hop over \n */
p++;
@@ -1318,7 +1333,7 @@ tree_foreach_packages(tree_ctx *ctx, tree_pkg_cb 
callback, void *priv)
 #define match_key(X) match_key2(X,X)
 #define match_key2(X,Y) \
} else if (strcmp(p, #X) == 0) { \
-   meta->Q_##Y = c
+   

[gentoo-commits] proj/portage-utils:master commit in: libq/

2020-01-19 Thread Fabian Groffen
commit: 0467d4c73cc564101ceff32a3b74cc86ea36262c
Author: Fabian Groffen  gentoo  org>
AuthorDate: Sun Jan 19 11:48:20 2020 +
Commit: Fabian Groffen  gentoo  org>
CommitDate: Sun Jan 19 11:48:20 2020 +
URL:https://gitweb.gentoo.org/proj/portage-utils.git/commit/?id=0467d4c7

libq/tree: Coverity 206569 String not terminated

Help Coverity see the string is terminated, effectively turning a more
expensive zalloc into malloc.

Signed-off-by: Fabian Groffen  gentoo.org>

 libq/tree.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/libq/tree.c b/libq/tree.c
index 1802d79..94f9665 100644
--- a/libq/tree.c
+++ b/libq/tree.c
@@ -793,10 +793,11 @@ tree_read_file_ebuild(tree_pkg_ctx *pkg_ctx)
goto err;
 
len = sizeof(*ret) + s.st_size + 1;
-   ret = xzalloc(len);
+   ret = xmalloc(len);
p = (char *)ret + sizeof(*ret);
if ((off_t)fread(p, 1, s.st_size, f) != s.st_size)
goto err;
+   p[s.st_size] = '\0';
 
do {
q = p;



[gentoo-commits] proj/portage-utils:master commit in: libq/

2020-01-19 Thread Fabian Groffen
commit: 275298ccf4c33cfe6cc4a816afd8ef15dce6d59f
Author: Fabian Groffen  gentoo  org>
AuthorDate: Sun Jan 19 10:04:39 2020 +
Commit: Fabian Groffen  gentoo  org>
CommitDate: Sun Jan 19 10:04:39 2020 +
URL:https://gitweb.gentoo.org/proj/portage-utils.git/commit/?id=275298cc

libq/tree: fix initialisation in tree_open_cat

Signed-off-by: Fabian Groffen  gentoo.org>

 libq/tree.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/libq/tree.c b/libq/tree.c
index f87e751..1802d79 100644
--- a/libq/tree.c
+++ b/libq/tree.c
@@ -262,6 +262,8 @@ tree_open_cat(tree_ctx *ctx, const char *name)
cat_ctx->dir = dir;
cat_ctx->ctx = ctx;
cat_ctx->pkg_ctxs = NULL;
+   cat_ctx->pkg_cur = 0;
+   cat_ctx->pkg_cnt = 0;
 
if (ctx->cache.categories != NULL) {
add_set_value(name, cat_ctx, ctx->cache.categories);



[gentoo-commits] proj/portage-utils:master commit in: libq/

2020-01-19 Thread Fabian Groffen
commit: 3d6b64ef4c4dfd0fe2e008c7cc28a94904775e1e
Author: Fabian Groffen  gentoo  org>
AuthorDate: Sun Jan 19 09:44:57 2020 +
Commit: Fabian Groffen  gentoo  org>
CommitDate: Sun Jan 19 09:44:57 2020 +
URL:https://gitweb.gentoo.org/proj/portage-utils.git/commit/?id=3d6b64ef

libq/set: change interface of contains_set to return internal key

Allow to refer to the internal allocated key name, which can avoid
another duplicate in certain cases.

Signed-off-by: Fabian Groffen  gentoo.org>

 libq/set.c | 11 ++-
 libq/set.h |  3 +--
 2 files changed, 7 insertions(+), 7 deletions(-)

diff --git a/libq/set.c b/libq/set.c
index 4529c3a..ceb6f47 100644
--- a/libq/set.c
+++ b/libq/set.c
@@ -148,23 +148,24 @@ add_set_value(const char *name, void *ptr, set *q)
return NULL;
 }
 
-/* returns whether s is in set */
-bool
+/* returns whether name is in set, and if so, the set-internal key
+ * representation (an internal copy of name made during addition) */
+const char *
 contains_set(const char *name, set *q)
 {
unsigned int hash;
int pos;
set_elem *w;
-   bool found;
+   const char *found;
 
hash = fnv1a32(name);
pos = hash % _SET_HASH_SIZE;
 
-   found = false;
+   found = NULL;
if (q->buckets[pos] != NULL) {
for (w = q->buckets[pos]; w != NULL; w = w->next) {
if (w->hash == hash && strcmp(w->name, name) == 0) {
-   found = true;
+   found = w->name;
break;
}
}

diff --git a/libq/set.h b/libq/set.h
index c65eb0f..5d53f95 100644
--- a/libq/set.h
+++ b/libq/set.h
@@ -7,7 +7,6 @@
 #define _SET_H 1
 
 #include 
-#include 
 #include 
 
 #include "xarray.h"
@@ -32,7 +31,7 @@ set *create_set(void);
 set *add_set(const char *name, set *q);
 set *add_set_unique(const char *name, set *q, bool *unique);
 void *add_set_value(const char *name, void *ptr, set *q);
-bool contains_set(const char *name, set *q);
+const char *contains_set(const char *name, set *q);
 void *get_set(const char *name, set *q);
 void *del_set(const char *s, set *q, bool *removed);
 size_t list_set(set *q, char ***l);



[gentoo-commits] proj/portage-utils:master commit in: libq/

2020-01-19 Thread Fabian Groffen
commit: dadb2666f54fed0478e0914d9fc4349f27730d58
Author: Fabian Groffen  gentoo  org>
AuthorDate: Sun Jan 19 09:46:18 2020 +
Commit: Fabian Groffen  gentoo  org>
CommitDate: Sun Jan 19 09:46:18 2020 +
URL:https://gitweb.gentoo.org/proj/portage-utils.git/commit/?id=dadb2666

libq/tree: add initial tree_match_atom with caching

tree_match_atom is meant for retrieving the best matching element from a
tree based on a query.  It caches the underlying packages it traverses,
such that repetitive lookups will benefit from previous lookups.  This
comes in handy for recursive scenarios such as when
calculating/resolving dependencies.

Signed-off-by: Fabian Groffen  gentoo.org>

 libq/tree.c | 80 +
 libq/tree.h |  4 
 2 files changed, 84 insertions(+)

diff --git a/libq/tree.c b/libq/tree.c
index 0df2e0d..f87e751 100644
--- a/libq/tree.c
+++ b/libq/tree.c
@@ -148,6 +148,24 @@ tree_open_binpkg(const char *sroot, const char *spkg)
 void
 tree_close(tree_ctx *ctx)
 {
+   if (ctx->cache.categories != NULL) {
+   DECLARE_ARRAY(t);
+   size_t n;
+   tree_cat_ctx *cat;
+
+   values_set(ctx->cache.categories, t);
+   free_set(ctx->cache.categories);
+   ctx->cache.categories = NULL;  /* must happen before close_cat 
*/
+
+   array_for_each(t, n, cat) {
+   /* ensure we cleanup all pkgs */
+   cat->pkg_cur = 0;
+   tree_close_cat(cat);
+   }
+
+   xarrayfree_int(t);
+   }
+
closedir(ctx->dir);
/* closedir() above does this for us: */
/* close(ctx->tree_fd); */
@@ -212,6 +230,21 @@ tree_open_cat(tree_ctx *ctx, const char *name)
int fd;
DIR *dir;
 
+   /* lookup in the cache, if any */
+   if (ctx->cache.categories != NULL) {
+   cat_ctx = get_set(name, ctx->cache.categories);
+   if (cat_ctx != NULL) {
+   /* reset state so it can be re-iterated (sort benefits 
the
+* most here) */
+   if (ctx->do_sort) {
+   cat_ctx->pkg_cur = 0;
+   } else {
+   rewinddir(cat_ctx->dir);
+   }
+   return cat_ctx;
+   }
+   }
+
/* Cannot use O_PATH as we want to use fdopendir() */
fd = openat(ctx->tree_fd, name, O_RDONLY | O_CLOEXEC);
if (fd == -1)
@@ -229,6 +262,13 @@ tree_open_cat(tree_ctx *ctx, const char *name)
cat_ctx->dir = dir;
cat_ctx->ctx = ctx;
cat_ctx->pkg_ctxs = NULL;
+
+   if (ctx->cache.categories != NULL) {
+   add_set_value(name, cat_ctx, ctx->cache.categories);
+   /* ensure name doesn't expire after this instantiation is 
closed */
+   cat_ctx->name = contains_set(name, ctx->cache.categories);
+   }
+
return cat_ctx;
 }
 
@@ -289,6 +329,14 @@ tree_next_cat(tree_ctx *ctx)
 void
 tree_close_cat(tree_cat_ctx *cat_ctx)
 {
+   if (cat_ctx->ctx->cache.categories != NULL &&
+   contains_set(cat_ctx->name, 
cat_ctx->ctx->cache.categories))
+   return;
+
+   /* cleanup unreturned pkgs when sorted (or cache in use) */
+   while (cat_ctx->pkg_cur < cat_ctx->pkg_cnt)
+   tree_close_pkg(cat_ctx->pkg_ctxs[cat_ctx->pkg_cur++]);
+
closedir(cat_ctx->dir);
/* closedir() above does this for us: */
/* close(ctx->fd); */
@@ -1439,3 +1487,35 @@ tree_get_atoms(tree_ctx *ctx, bool fullcpv, set *satoms)
 
return state.cpf;
 }
+
+tree_pkg_ctx *
+tree_match_atom(tree_ctx *ctx, depend_atom *a)
+{
+   tree_cat_ctx *cat_ctx;
+   tree_pkg_ctx *pkg_ctx;
+   depend_atom *atom;
+
+   if (ctx->cache.categories == NULL)
+   ctx->cache.categories = create_set();
+
+   if (a->P == NULL) {
+   return NULL;
+   } else if (a->CATEGORY == NULL) {
+   /* loop through all cats and recurse */
+   /* TODO: some day */
+   return NULL;
+   } else {
+   /* try CAT, and PN for latest version */
+   if ((cat_ctx = tree_open_cat(ctx, a->CATEGORY)) == NULL)
+   return NULL;
+   ctx->do_sort = true; /* sort uses buffer, which cache 
relies on */
+   ctx->query_atom = NULL;  /* ensure the cache contains ALL pkgs 
*/
+   while ((pkg_ctx = tree_next_pkg(cat_ctx)) != NULL) {
+   atom = tree_get_atom(pkg_ctx, a->SLOT != NULL);
+   if (atom_compare(atom, a) == EQUAL)
+   return pkg_ctx;
+   }
+
+   return NULL;
+   }
+}

diff --git a/libq/tree.h b/libq/tree.h
index 6627e80..eaee7ad 100644
--- a/libq/tree.h
+++ 

[gentoo-commits] proj/portage-utils:master commit in: libq/

2020-01-17 Thread Fabian Groffen
commit: 0c691939a77d0056ced7f06d5142c1952f917fee
Author: Fabian Groffen  gentoo  org>
AuthorDate: Fri Jan 17 08:21:07 2020 +
Commit: Fabian Groffen  gentoo  org>
CommitDate: Fri Jan 17 08:21:07 2020 +
URL:https://gitweb.gentoo.org/proj/portage-utils.git/commit/?id=0c691939

libq/tree: avoid double free in sorted case for tree_next_pkg_int

Thanks Georgy Yakovlev for the report with stacktrace.

Bug: https://bugs.gentoo.org/705636
Signed-off-by: Fabian Groffen  gentoo.org>

 libq/tree.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libq/tree.c b/libq/tree.c
index 0b01f14..0df2e0d 100644
--- a/libq/tree.c
+++ b/libq/tree.c
@@ -403,7 +403,7 @@ tree_next_pkg_int(tree_cat_ctx *cat_ctx)
pkg_ctx = cat_ctx->pkg_ctxs[cat_ctx->pkg_cnt++] 
=
tree_open_pkg(cat_ctx, name);
if (pkg_ctx == NULL) {
-   free(name);
+   /* name was freed by tree_close_pkg on 
fail */
cat_ctx->pkg_cnt--;
}
}



[gentoo-commits] proj/portage-utils:master commit in: /, libq/

2020-01-05 Thread Fabian Groffen
commit: dc9f36140c34969f57e4fb3259315fedd1c61544
Author: Fabian Groffen  gentoo  org>
AuthorDate: Sun Jan  5 15:21:02 2020 +
Commit: Fabian Groffen  gentoo  org>
CommitDate: Sun Jan  5 15:59:25 2020 +
URL:https://gitweb.gentoo.org/proj/portage-utils.git/commit/?id=dc9f3614

qfile/qlist: move away from tree_pkg_vdb_fopenat

Signed-off-by: Fabian Groffen  gentoo.org>

 TODO.md |  1 +
 libq/tree.c | 33 +++--
 libq/tree.h | 21 ++---
 qfile.c | 12 ++--
 qsize.c | 24 +---
 5 files changed, 29 insertions(+), 62 deletions(-)

diff --git a/TODO.md b/TODO.md
index fe74cab..fc10f26 100644
--- a/TODO.md
+++ b/TODO.md
@@ -24,6 +24,7 @@
 or parsing Packages)
   - cached, such that repeated matches for the same thing are served off
 the cache (set), as frequently happens in dependency calculations
+  - tree\_{open,close}\_cat can be made static afterwards
 
 # qmerge
 - dep resolver needs spanktastic love.

diff --git a/libq/tree.c b/libq/tree.c
index 49b2fa1..0c05dc5 100644
--- a/libq/tree.c
+++ b/libq/tree.c
@@ -161,7 +161,7 @@ tree_close(tree_ctx *ctx)
free(ctx);
 }
 
-int
+static int
 tree_filter_cat(const struct dirent *de)
 {
int i;
@@ -230,7 +230,7 @@ tree_open_cat(tree_ctx *ctx, const char *name)
return cat_ctx;
 }
 
-tree_cat_ctx *
+static tree_cat_ctx *
 tree_next_cat(tree_ctx *ctx)
 {
/* search for a category directory */
@@ -295,7 +295,7 @@ tree_close_cat(tree_cat_ctx *cat_ctx)
free(cat_ctx);
 }
 
-int
+static int
 tree_filter_pkg(const struct dirent *de)
 {
int i;
@@ -527,29 +527,7 @@ tree_pkg_vdb_openat(
return openat(pkg_ctx->fd, file, flags | O_CLOEXEC, mode);
 }
 
-FILE *
-tree_pkg_vdb_fopenat(
-   tree_pkg_ctx *pkg_ctx,
-   const char *file,
-   int flags,
-   mode_t mode,
-   const char *fmode)
-{
-   FILE *fp;
-   int fd;
-
-   fd = tree_pkg_vdb_openat(pkg_ctx, file, flags, mode);
-   if (fd == -1)
-   return NULL;
-
-   fp = fdopen(fd, fmode);
-   if (!fp)
-   close(fd);
-
-   return fp;
-}
-
-bool
+static bool
 tree_pkg_vdb_eat(
tree_pkg_ctx *pkg_ctx,
const char *file,
@@ -721,6 +699,7 @@ tree_read_file_md5(tree_pkg_ctx *pkg_ctx)
assign_var(DEFINED_PHASES);
assign_var(REQUIRED_USE);
assign_var(BDEPEND);
+   assign_var(EPREFIX);
assign_var(_eclasses_);
assign_var(_md5_);
warn("Cache file for '%s/%s' has unknown key %s",
@@ -794,6 +773,7 @@ tree_read_file_ebuild(tree_pkg_ctx *pkg_ctx)
match_key(PDEPEND);
match_key(EAPI);
match_key(REQUIRED_USE);
+   match_key(BDEPEND);
 #undef match_key
}
 
@@ -899,6 +879,7 @@ tree_read_file_binpkg_xpak_cb(
match_path(BDEPEND);
match_path(CONTENTS);
match_path(USE);
+   match_path(EPREFIX);
match_path(repository);
else
return;

diff --git a/libq/tree.h b/libq/tree.h
index eb60296..c941172 100644
--- a/libq/tree.h
+++ b/libq/tree.h
@@ -89,16 +89,17 @@ struct tree_pkg_meta {
char *Q_PROVIDE;   /* line 14 */
char *Q_EAPI;
char *Q_PROPERTIES;
-   /* These are MD5-Cache only */
-   char *Q_DEFINED_PHASES;
-   char *Q_REQUIRED_USE;
char *Q_BDEPEND;
-   char *Q__eclasses_;
-   char *Q__md5_;
/* binpkgs/vdb */
+   char *Q_DEFINED_PHASES;
+   char *Q_REQUIRED_USE;
char *Q_CONTENTS;
char *Q_USE;
+   char *Q_EPREFIX;
char *Q_repository;
+   /* These are MD5-Cache only */
+   char *Q__eclasses_;
+   char *Q__md5_;
 };
 
 /* Metadata.xml */
@@ -116,20 +117,10 @@ tree_ctx *tree_open(const char *sroot, const char 
*portdir);
 tree_ctx *tree_open_vdb(const char *sroot, const char *svdb);
 tree_ctx *tree_open_binpkg(const char *sroot, const char *spkg);
 void tree_close(tree_ctx *ctx);
-int tree_filter_cat(const struct dirent *de);
 tree_cat_ctx *tree_open_cat(tree_ctx *ctx, const char *name);
-tree_cat_ctx *tree_next_cat(tree_ctx *ctx);
 void tree_close_cat(tree_cat_ctx *cat_ctx);
-int tree_filter_pkg(const struct dirent *de);
 tree_pkg_ctx *tree_open_pkg(tree_cat_ctx *cat_ctx, const char *name);
 tree_pkg_ctx *tree_next_pkg(tree_cat_ctx *cat_ctx);
-FILE *tree_pkg_vdb_fopenat(tree_pkg_ctx *pkg_ctx, const char *file,
-   int flags, mode_t mode, const char *fmode);
-#define tree_pkg_vdb_fopenat_ro(pkg_ctx, file) \
-   tree_pkg_vdb_fopenat(pkg_ctx, file, O_RDONLY, 0, "r")
-#define tree_pkg_vdb_fopenat_rw(pkg_ctx, file) \
-   tree_pkg_vdb_fopenat(pkg_ctx, file, O_RDWR | O_CREAT | O_TRUNC, 0644, 
"w")
-bool tree_pkg_vdb_eat(tree_pkg_ctx *pkg_ctx, const char *file, char **bufptr, 

[gentoo-commits] proj/portage-utils:master commit in: libq/

2020-01-05 Thread Fabian Groffen
commit: 98b3632c7e28b4f7d5eebb7b7ffc255adabe81b7
Author: Fabian Groffen  gentoo  org>
AuthorDate: Sun Jan  5 16:08:00 2020 +
Commit: Fabian Groffen  gentoo  org>
CommitDate: Sun Jan  5 16:08:00 2020 +
URL:https://gitweb.gentoo.org/proj/portage-utils.git/commit/?id=98b3632c

libq/tree: make some unused functions private (static)

Signed-off-by: Fabian Groffen  gentoo.org>

 libq/tree.c | 8 
 libq/tree.h | 3 ---
 2 files changed, 4 insertions(+), 7 deletions(-)

diff --git a/libq/tree.c b/libq/tree.c
index bb3aa69..0b01f14 100644
--- a/libq/tree.c
+++ b/libq/tree.c
@@ -27,6 +27,8 @@
 #include 
 
 static int tree_pkg_compar(const void *l, const void *r);
+static tree_pkg_ctx * tree_next_pkg_int(tree_cat_ctx *cat_ctx);
+static void tree_close_meta(tree_pkg_meta *cache);
 
 static tree_ctx *
 tree_open_int(const char *sroot, const char *tdir, bool quiet)
@@ -363,8 +365,6 @@ tree_pkg_compar(const void *l, const void *r)
return atom_compar_cb(al, ar);
 }
 
-static tree_pkg_ctx *
-tree_next_pkg_int(tree_cat_ctx *cat_ctx);
 static tree_pkg_ctx *
 tree_next_pkg_int(tree_cat_ctx *cat_ctx)
 {
@@ -926,7 +926,7 @@ tree_read_file_binpkg(tree_pkg_ctx *pkg_ctx)
return m;
 }
 
-tree_pkg_meta *
+static tree_pkg_meta *
 tree_pkg_read(tree_pkg_ctx *pkg_ctx)
 {
tree_ctx *ctx = pkg_ctx->cat_ctx->ctx;
@@ -963,7 +963,7 @@ tree_pkg_read(tree_pkg_ctx *pkg_ctx)
return NULL;
 }
 
-void
+static void
 tree_close_meta(tree_pkg_meta *cache)
 {
if (cache == NULL)

diff --git a/libq/tree.h b/libq/tree.h
index c941172..6627e80 100644
--- a/libq/tree.h
+++ b/libq/tree.h
@@ -121,8 +121,6 @@ tree_cat_ctx *tree_open_cat(tree_ctx *ctx, const char 
*name);
 void tree_close_cat(tree_cat_ctx *cat_ctx);
 tree_pkg_ctx *tree_open_pkg(tree_cat_ctx *cat_ctx, const char *name);
 tree_pkg_ctx *tree_next_pkg(tree_cat_ctx *cat_ctx);
-tree_pkg_meta *tree_pkg_read(tree_pkg_ctx *pkg_ctx);
-void tree_close_meta(tree_pkg_meta *cache);
 char *tree_pkg_meta_get_int(tree_pkg_ctx *pkg_ctx, size_t offset, const char 
*key);
 #define tree_pkg_meta_get(P,X) \
tree_pkg_meta_get_int(P, offsetof(tree_pkg_meta, Q_##X), #X)
@@ -135,7 +133,6 @@ int tree_foreach_pkg(tree_ctx *ctx, tree_pkg_cb callback, 
void *priv,
tree_foreach_pkg(ctx, cb, priv, false, query);
 #define tree_foreach_pkg_sorted(ctx, cb, priv, query) \
tree_foreach_pkg(ctx, cb, priv, true, query);
-struct dirent *tree_get_next_dir(DIR *dir);
 set *tree_get_atoms(tree_ctx *ctx, bool fullcpv, set *satoms);
 depend_atom *tree_get_atom(tree_pkg_ctx *pkg_ctx, bool complete);
 



  1   2   3   >