xbps_binpkg_exists: fix access() on remote packages and avoid malloc
This commit is contained in:
parent
53e23d348e
commit
45fc07260c
26
lib/util.c
26
lib/util.c
@ -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
|
||||||
|
Loading…
Reference in New Issue
Block a user