1 |
commit: 3794f21d3da7f182c85b63e87f0e073b5df3de18 |
2 |
Author: Fabian Groffen <grobian <AT> gentoo <DOT> org> |
3 |
AuthorDate: Mon May 25 10:32:27 2020 +0000 |
4 |
Commit: Fabian Groffen <grobian <AT> gentoo <DOT> org> |
5 |
CommitDate: Mon May 25 10:32:27 2020 +0000 |
6 |
URL: https://gitweb.gentoo.org/proj/portage-utils.git/commit/?id=3794f21d |
7 |
|
8 |
libq/tree: have tree_read_file_binpkg populate some meta fields |
9 |
|
10 |
The SHA1 and SIZE fields might be necessary, so psuedo fill them in |
11 |
here, as we don't have a meta that contains them, except the file |
12 |
itself. |
13 |
|
14 |
Signed-off-by: Fabian Groffen <grobian <AT> gentoo.org> |
15 |
|
16 |
libq/tree.c | 39 +++++++++++++++++++++++++++++++++++++++ |
17 |
1 file changed, 39 insertions(+) |
18 |
|
19 |
diff --git a/libq/tree.c b/libq/tree.c |
20 |
index 7fbb739..d901fc6 100644 |
21 |
--- a/libq/tree.c |
22 |
+++ b/libq/tree.c |
23 |
@@ -17,6 +17,7 @@ |
24 |
|
25 |
#include "atom.h" |
26 |
#include "eat_file.h" |
27 |
+#include "hash.h" |
28 |
#include "rmspace.h" |
29 |
#include "scandirat.h" |
30 |
#include "set.h" |
31 |
@@ -982,10 +983,48 @@ static tree_pkg_meta * |
32 |
tree_read_file_binpkg(tree_pkg_ctx *pkg_ctx) |
33 |
{ |
34 |
tree_pkg_meta *m = xzalloc(sizeof(tree_pkg_meta)); |
35 |
+ int newfd = dup(pkg_ctx->fd); |
36 |
|
37 |
xpak_process_fd(pkg_ctx->fd, true, m, tree_read_file_binpkg_xpak_cb); |
38 |
pkg_ctx->fd = -1; /* closed by xpak_process_fd */ |
39 |
|
40 |
+ /* fill in some properties which are not available, but would be in |
41 |
+ * Packages, and used to verify the package ... this is somewhat |
42 |
+ * fake, but allows to transparantly use a dir of binpkgs */ |
43 |
+ if (newfd != -1) { |
44 |
+ size_t fsize; |
45 |
+ size_t needlen = 40 + 1 + 19 + 1; |
46 |
+ size_t pos = (size_t)m->Q__eclasses_; |
47 |
+ size_t len = (size_t)m->Q__md5_; |
48 |
+ |
49 |
+ if (len - pos < needlen) { |
50 |
+ char *old_data = m->Q__data; |
51 |
+ len += ((needlen / BUFSIZ) + 1) * BUFSIZ; |
52 |
+ m->Q__data = xrealloc(m->Q__data, len); |
53 |
+ m->Q__md5_ = (char *)len; |
54 |
+ |
55 |
+ /* re-position existing keys */ |
56 |
+ if (old_data != NULL && m->Q__data != old_data) { |
57 |
+ char **newdata = (char **)m; |
58 |
+ int elems = sizeof(tree_pkg_meta) / sizeof(char *); |
59 |
+ while (elems-- > 1) /* skip Q__data itself */ |
60 |
+ if (newdata[elems] != NULL) |
61 |
+ newdata[elems] = |
62 |
+ m->Q__data + (newdata[elems] - old_data); |
63 |
+ } |
64 |
+ } |
65 |
+ |
66 |
+ m->Q_SHA1 = m->Q__data + pos; |
67 |
+ m->Q_SIZE = m->Q_SHA1 + 40 + 1; |
68 |
+ pos += needlen; |
69 |
+ m->Q__eclasses_ = (char *)pos; |
70 |
+ |
71 |
+ lseek(newfd, 0, SEEK_SET); /* reposition at the whole file */ |
72 |
+ if (hash_multiple_file_fd(newfd, NULL, m->Q_SHA1, NULL, NULL, |
73 |
+ NULL, NULL, &fsize, HASH_SHA1) == 0) |
74 |
+ snprintf(m->Q_SIZE, 19 + 1, "%zu", fsize); |
75 |
+ } |
76 |
+ |
77 |
return m; |
78 |
} |