commit: dc9f36140c34969f57e4fb3259315fedd1c61544
Author: Fabian Groffen <grobian <AT> gentoo <DOT> org>
AuthorDate: Sun Jan 5 15:21:02 2020 +0000
Commit: Fabian Groffen <grobian <AT> gentoo <DOT> org>
CommitDate: Sun Jan 5 15:59:25 2020 +0000
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 <grobian <AT> 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,
size_t *buflen);
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);
diff --git a/qfile.c b/qfile.c
index 0b01061..3036be0 100644
--- a/qfile.c
+++ b/qfile.c
@@ -160,7 +160,8 @@ static int qfile_cb(tree_pkg_ctx *pkg_ctx, void *priv)
struct qfile_opt_state *state = priv;
const char *catname = pkg_ctx->cat_ctx->name;
qfile_args_t *args = &state->args;
- FILE *fp;
+ char *line;
+ char *savep;
const char *base;
depend_atom *atom = NULL;
int i;
@@ -196,16 +197,16 @@ static int qfile_cb(tree_pkg_ctx *pkg_ctx, void *priv)
}
dont_skip_pkg: /* End of the package exclusion tests. */
- fp = tree_pkg_vdb_fopenat_ro(pkg_ctx, "CONTENTS");
- if (fp == NULL)
+ line = tree_pkg_meta_get(pkg_ctx, CONTENTS);
+ if (line == NULL)
goto qlist_done;
/* Run through CONTENTS file */
- while (getline(&state->buf, &state->buflen, fp) != -1) {
+ for (; (line = strtok_r(line, "\n", &savep)) != NULL; line = NULL) {
size_t dirname_len;
contents_entry *e;
- e = contents_parse_line(state->buf);
+ e = contents_parse_line(line);
if (!e)
continue;
@@ -314,7 +315,6 @@ static int qfile_cb(tree_pkg_ctx *pkg_ctx, void *priv)
found++;
}
}
- fclose(fp);
qlist_done:
return found;
diff --git a/qsize.c b/qsize.c
index 617b50b..a25ce78 100644
--- a/qsize.c
+++ b/qsize.c
@@ -93,9 +93,6 @@ struct qsize_opt_state {
const char *fmt;
bool need_full_atom:1;
- size_t buflen;
- char *buf;
-
size_t num_all_files, num_all_nonfiles, num_all_ignored;
uint64_t num_all_bytes;
};
@@ -106,28 +103,30 @@ qsize_cb(tree_pkg_ctx *pkg_ctx, void *priv)
struct qsize_opt_state *state = priv;
size_t i;
depend_atom *atom;
- FILE *fp;
+ char *line;
+ char *savep;
size_t num_files, num_nonfiles, num_ignored;
uint64_t num_bytes;
- if ((fp = tree_pkg_vdb_fopenat_ro(pkg_ctx, "CONTENTS")) == NULL)
+ if ((line = tree_pkg_meta_get(pkg_ctx, CONTENTS)) == NULL)
return EXIT_SUCCESS;
num_ignored = num_files = num_nonfiles = num_bytes = 0;
- while (getline(&state->buf, &state->buflen, fp) != -1) {
+ for (; (line = strtok_r(line, "\n", &savep)) != NULL; line = NULL) {
contents_entry *e;
regex_t *regex;
int ok = 0;
- e = contents_parse_line(state->buf);
+ e = contents_parse_line(line);
if (!e)
continue;
- array_for_each(state->ignore_regexp, i, regex)
- if (!regexec(regex, state->buf, 0, NULL, 0)) {
- num_ignored += 1;
+ array_for_each(state->ignore_regexp, i, regex) {
+ if (!regexec(regex, e->name, 0, NULL, 0)) {
+ num_ignored++;
ok = 1;
}
+ }
if (ok)
continue;
@@ -141,7 +140,6 @@ qsize_cb(tree_pkg_ctx *pkg_ctx, void *priv)
} else
++num_nonfiles;
}
- fclose(fp);
state->num_all_bytes += num_bytes;
state->num_all_files += num_files;
state->num_all_nonfiles += num_nonfiles;
@@ -227,9 +225,6 @@ int qsize_main(int argc, char **argv)
state.fmt = "%[CATEGORY]%[PN]";
}
- state.buflen = _Q_PATH_MAX;
- state.buf = xmalloc(state.buflen);
-
vdb = tree_open_vdb(portroot, portvdb);
if (vdb != NULL) {
if (array_cnt(atoms) > 0) {
@@ -257,7 +252,6 @@ int qsize_main(int argc, char **argv)
atom_implode(atom);
xarrayfree_int(state.atoms);
xarrayfree(state.ignore_regexp);
- free(state.buf);
return ret;
}