1 |
commit: 8b4086e7e32e3e548929fa532056a65188f8def8 |
2 |
Author: Fabian Groffen <grobian <AT> gentoo <DOT> org> |
3 |
AuthorDate: Sat Jan 4 19:47:57 2020 +0000 |
4 |
Commit: Fabian Groffen <grobian <AT> gentoo <DOT> org> |
5 |
CommitDate: Sat Jan 4 19:47:57 2020 +0000 |
6 |
URL: https://gitweb.gentoo.org/proj/portage-utils.git/commit/?id=8b4086e7 |
7 |
|
8 |
libq/tree: ignore Packages file when seemingly outdated |
9 |
|
10 |
Signed-off-by: Fabian Groffen <grobian <AT> gentoo.org> |
11 |
|
12 |
TODO.md | 1 - |
13 |
libq/tree.c | 18 ++++++++++++++++-- |
14 |
2 files changed, 16 insertions(+), 3 deletions(-) |
15 |
|
16 |
diff --git a/TODO.md b/TODO.md |
17 |
index 1de8b5f..ded7553 100644 |
18 |
--- a/TODO.md |
19 |
+++ b/TODO.md |
20 |
@@ -15,7 +15,6 @@ |
21 |
- parse package.accept\_keywords such that we can provide the latest |
22 |
"available" version like Portage |
23 |
- check timestamps in libq/tree for choosing which method to take: |
24 |
- - ignore Packages when it is older than the last directory change |
25 |
- ignore metadata when ebuild is modified |
26 |
- add some method to skip these checks and assume everything is right |
27 |
|
28 |
|
29 |
diff --git a/libq/tree.c b/libq/tree.c |
30 |
index 49b2fa1..976f166 100644 |
31 |
--- a/libq/tree.c |
32 |
+++ b/libq/tree.c |
33 |
@@ -133,11 +133,25 @@ tree_open_binpkg(const char *sroot, const char *spkg) |
34 |
char buf[_Q_PATH_MAX]; |
35 |
|
36 |
if (ret != NULL) { |
37 |
+ struct stat st; |
38 |
+ struct timespec pkgstim; |
39 |
+ |
40 |
ret->cachetype = CACHE_BINPKGS; |
41 |
|
42 |
snprintf(buf, sizeof(buf), "%s%s/%s", sroot, spkg, binpkg_packages); |
43 |
- if (eat_file(buf, &ret->pkgs, &ret->pkgslen)) |
44 |
- ret->cachetype = CACHE_PACKAGES; |
45 |
+ if (eat_file(buf, &ret->pkgs, &ret->pkgslen)) { |
46 |
+ if (stat(buf, &st) == 0) |
47 |
+ memcpy(&pkgstim, &st.st_mtim, sizeof(st.st_mtim)); |
48 |
+ else |
49 |
+ memset(&pkgstim, 0, sizeof(pkgstim)); |
50 |
+ |
51 |
+ /* if the Packages file seems outdated, don't trust/use it */ |
52 |
+ if (fstat(ret->tree_fd, &st) != 0 || |
53 |
+ st.st_mtim.tv_sec < pkgstim.tv_sec || /* impossible? */ |
54 |
+ (st.st_mtim.tv_sec == pkgstim.tv_sec && |
55 |
+ st.st_mtim.tv_nsec <= pkgstim.tv_nsec)) |
56 |
+ ret->cachetype = CACHE_PACKAGES; |
57 |
+ } |
58 |
} |
59 |
|
60 |
return ret; |