1 |
commit: 1cffb01452f2553747be26778ef4f84425e45554 |
2 |
Author: Fabian Groffen <grobian <AT> gentoo <DOT> org> |
3 |
AuthorDate: Mon May 25 10:30:52 2020 +0000 |
4 |
Commit: Fabian Groffen <grobian <AT> gentoo <DOT> org> |
5 |
CommitDate: Mon May 25 10:30:52 2020 +0000 |
6 |
URL: https://gitweb.gentoo.org/proj/portage-utils.git/commit/?id=1cffb014 |
7 |
|
8 |
libq/tree: slightly optimise tree_open_pkg |
9 |
|
10 |
don't construct a new path, but open at the existing filedescriptor |
11 |
instead. |
12 |
|
13 |
Signed-off-by: Fabian Groffen <grobian <AT> gentoo.org> |
14 |
|
15 |
libq/tree.c | 9 +++++---- |
16 |
1 file changed, 5 insertions(+), 4 deletions(-) |
17 |
|
18 |
diff --git a/libq/tree.c b/libq/tree.c |
19 |
index ebcc133..7fbb739 100644 |
20 |
--- a/libq/tree.c |
21 |
+++ b/libq/tree.c |
22 |
@@ -27,7 +27,7 @@ |
23 |
#include <xalloc.h> |
24 |
|
25 |
static int tree_pkg_compar(const void *l, const void *r); |
26 |
-static tree_pkg_ctx * tree_next_pkg_int(tree_cat_ctx *cat_ctx); |
27 |
+static tree_pkg_ctx *tree_next_pkg_int(tree_cat_ctx *cat_ctx); |
28 |
static void tree_close_meta(tree_pkg_meta *cache); |
29 |
|
30 |
static tree_ctx * |
31 |
@@ -132,18 +132,19 @@ tree_ctx * |
32 |
tree_open_binpkg(const char *sroot, const char *spkg) |
33 |
{ |
34 |
tree_ctx *ret = tree_open_int(sroot, spkg, true); |
35 |
- char buf[_Q_PATH_MAX]; |
36 |
+ int fd; |
37 |
|
38 |
if (ret != NULL) { |
39 |
ret->cachetype = CACHE_BINPKGS; |
40 |
|
41 |
- snprintf(buf, sizeof(buf), "%s%s/%s", sroot, spkg, binpkg_packages); |
42 |
- if (eat_file(buf, &ret->pkgs, &ret->pkgslen)) { |
43 |
+ fd = openat(ret->tree_fd, binpkg_packages, O_RDONLY | O_CLOEXEC); |
44 |
+ if (eat_file_fd(fd, &ret->pkgs, &ret->pkgslen)) { |
45 |
ret->cachetype = CACHE_PACKAGES; |
46 |
} else if (ret->pkgs != NULL) { |
47 |
free(ret->pkgs); |
48 |
ret->pkgs = NULL; |
49 |
} |
50 |
+ close(fd); |
51 |
} |
52 |
|
53 |
return ret; |