xbps_binpkg_exists: fix access() on remote packages and avoid malloc

This commit is contained in:
Duncaen 2019-06-14 23:19:59 +02:00
parent 53e23d348e
commit 45fc07260c

View File

@ -328,17 +328,27 @@ xbps_repository_pkg_path(struct xbps_handle *xhp, xbps_dictionary_t pkg_repod)
bool bool
xbps_binpkg_exists(struct xbps_handle *xhp, xbps_dictionary_t pkgd) xbps_binpkg_exists(struct xbps_handle *xhp, xbps_dictionary_t pkgd)
{ {
char *binpkg; char path[PATH_MAX];
bool exists = true; const char *pkgver, *arch, *repoloc;
if ((binpkg = xbps_repository_pkg_path(xhp, pkgd)) == NULL) assert(xhp);
return false; assert(xbps_object_type(pkgd) == XBPS_TYPE_DICTIONARY);
if (access(binpkg, R_OK) == -1) if (!xbps_dictionary_get_cstring_nocopy(pkgd,
exists = false; "pkgver", &pkgver))
return NULL;
if (!xbps_dictionary_get_cstring_nocopy(pkgd,
"architecture", &arch))
return NULL;
if (!xbps_dictionary_get_cstring_nocopy(pkgd,
"repository", &repoloc))
return NULL;
free(binpkg); snprintf(path, sizeof(path), "%s/%s.%s.xbps",
return exists; xbps_repository_is_remote(repoloc) ? xhp->cachedir : repoloc,
pkgver, arch);
return access(path, R_OK) == 0;
} }
bool bool