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