From 62c1102cc4edff734571815ed15844c8af46ef68 Mon Sep 17 00:00:00 2001 From: Duncaen Date: Sun, 7 Jul 2019 14:08:55 +0200 Subject: [PATCH] lib/util.c: xbps_remote_binpkg_exists to check if signature and binpkg are cached --- include/xbps.h.in | 11 +++++++++++ lib/util.c | 29 +++++++++++++++++++++++++++++ 2 files changed, 40 insertions(+) diff --git a/include/xbps.h.in b/include/xbps.h.in index 6f99f42c..02990291 100644 --- a/include/xbps.h.in +++ b/include/xbps.h.in @@ -1913,6 +1913,17 @@ bool xbps_pkg_is_ignored(struct xbps_handle *xhp, const char *pkg); */ bool xbps_binpkg_exists(struct xbps_handle *xhp, xbps_dictionary_t pkgd); +/** + * Returns true if binary package and signature exists in cachedir, + * false otherwise. + * + * @param[in] xhp The pointer to an xbps_handle struct. + * @param[in] pkgd Package dictionary returned by rpool. + * + * @return true if exists, false otherwise. + */ +bool xbps_remote_binpkg_exists(struct xbps_handle *xhp, xbps_dictionary_t pkgd); + /** * Checks if the URI specified by \a uri is remote or local. * diff --git a/lib/util.c b/lib/util.c index 059e1a03..6228d8fc 100644 --- a/lib/util.c +++ b/lib/util.c @@ -378,6 +378,35 @@ xbps_binpkg_exists(struct xbps_handle *xhp, xbps_dictionary_t pkgd) return access(path, R_OK) == 0; } +bool +xbps_remote_binpkg_exists(struct xbps_handle *xhp, xbps_dictionary_t pkgd) +{ + char path[PATH_MAX]; + const char *pkgver, *arch; + + assert(xhp); + assert(xbps_object_type(pkgd) == XBPS_TYPE_DICTIONARY); + + if (!xbps_dictionary_get_cstring_nocopy(pkgd, + "pkgver", &pkgver)) + return NULL; + if (!xbps_dictionary_get_cstring_nocopy(pkgd, + "architecture", &arch)) + return NULL; + + snprintf(path, sizeof(path), "%s/%s.%s.xbps.sig", xhp->cachedir, + pkgver, arch); + + /* check if the signature file exists */ + if (access(path, R_OK) != 0) + return false; + + /* strip the .sig suffix and check if binpkg file exists */ + path[strlen(path)-sizeof (".sig")+1] = '\0'; + + return access(path, R_OK) == 0; +} + bool xbps_pkg_has_rundeps(xbps_dictionary_t pkgd) {