commit:     95c95c9840129ec9d32be0bddda924f4426481b0
Author:     Fabian Groffen <grobian <AT> gentoo <DOT> org>
AuthorDate: Tue Apr 23 08:41:21 2019 +0000
Commit:     Fabian Groffen <grobian <AT> gentoo <DOT> org>
CommitDate: Tue Apr 23 08:41:21 2019 +0000
URL:        https://gitweb.gentoo.org/proj/portage-utils.git/commit/?id=95c95c98

q_vdb_open2: introduce version that is optionally quiet

For probing, it may be nice not to emit a warning for each probe.

Signed-off-by: Fabian Groffen <grobian <AT> gentoo.org>

 libq/vdb.c | 14 +++++++++++---
 libq/vdb.h |  1 +
 2 files changed, 12 insertions(+), 3 deletions(-)

diff --git a/libq/vdb.c b/libq/vdb.c
index 6b973e8..a32ba53 100644
--- a/libq/vdb.c
+++ b/libq/vdb.c
@@ -18,13 +18,14 @@
 #include <xalloc.h>
 
 q_vdb_ctx *
-q_vdb_open(const char *sroot, const char *svdb)
+q_vdb_open2(const char *sroot, const char *svdb, bool quiet)
 {
        q_vdb_ctx *ctx = xmalloc(sizeof(*ctx));
 
        ctx->portroot_fd = open(sroot, O_RDONLY|O_CLOEXEC|O_PATH);
        if (ctx->portroot_fd == -1) {
-               warnp("could not open root: %s", sroot);
+               if (!quiet)
+                       warnp("could not open root: %s", sroot);
                goto f_error;
        }
 
@@ -35,7 +36,8 @@ q_vdb_open(const char *sroot, const char *svdb)
        /* Cannot use O_PATH as we want to use fdopendir() */
        ctx->vdb_fd = openat(ctx->portroot_fd, svdb, O_RDONLY|O_CLOEXEC);
        if (ctx->vdb_fd == -1) {
-               warnp("could not open vdb: %s (in root %s)", svdb, sroot);
+               if (!quiet)
+                       warnp("could not open vdb: %s (in root %s)", svdb, 
sroot);
                goto cp_error;
        }
 
@@ -54,6 +56,12 @@ q_vdb_open(const char *sroot, const char *svdb)
        return NULL;
 }
 
+q_vdb_ctx *
+q_vdb_open(const char *sroot, const char *svdb)
+{
+       return q_vdb_open2(sroot, svdb, false);
+}
+
 void
 q_vdb_close(q_vdb_ctx *ctx)
 {

diff --git a/libq/vdb.h b/libq/vdb.h
index 80c318c..102f5a9 100644
--- a/libq/vdb.h
+++ b/libq/vdb.h
@@ -38,6 +38,7 @@ typedef int (q_vdb_pkg_cb)(q_vdb_pkg_ctx *, void *priv);
 typedef int (q_vdb_cat_filter)(q_vdb_cat_ctx *, void *priv);
 
 q_vdb_ctx *q_vdb_open(const char *sroot, const char *svdb);
+q_vdb_ctx *q_vdb_open2(const char *sroot, const char *svdb, bool quiet);
 void q_vdb_close(q_vdb_ctx *ctx);
 int q_vdb_filter_cat(const struct dirent *de);
 q_vdb_cat_ctx *q_vdb_open_cat(q_vdb_ctx *ctx, const char *name);

Reply via email to