Fix some issues in repo handling.
--HG-- extra : convert_revision : 5ec7488c8967f50b7e2dce93276accd829c541b3
This commit is contained in:
parent
b13563dbfd
commit
3f7c353356
|
@ -114,9 +114,9 @@ getrepolist_dict(void)
|
|||
static const char *
|
||||
sanitize_localpath(const char *path)
|
||||
{
|
||||
const char *res;
|
||||
char strtmp[PATH_MAX];
|
||||
static char strtmp[PATH_MAX];
|
||||
char *dirnp, *basenp, *dir, *base;
|
||||
const char *res;
|
||||
|
||||
dir = strdup(path);
|
||||
if (dir == NULL)
|
||||
|
@ -124,15 +124,15 @@ sanitize_localpath(const char *path)
|
|||
|
||||
base = strdup(path);
|
||||
if (base == NULL)
|
||||
goto fail;
|
||||
goto fail2;
|
||||
|
||||
dirnp = dirname(dir);
|
||||
if (strcmp(dirnp, ".") == 0)
|
||||
goto fail2;
|
||||
goto fail;
|
||||
|
||||
basenp = basename(base);
|
||||
if (strcmp(basenp, base) == 0)
|
||||
goto fail2;
|
||||
goto fail;
|
||||
|
||||
strncpy(strtmp, dirnp, sizeof(strtmp) - 1);
|
||||
strtmp[sizeof(strtmp) - 1] = '\0';
|
||||
|
@ -143,11 +143,12 @@ sanitize_localpath(const char *path)
|
|||
free(dir);
|
||||
free(base);
|
||||
res = strtmp;
|
||||
|
||||
return res;
|
||||
fail:
|
||||
free(dir);
|
||||
fail2:
|
||||
free(base);
|
||||
fail2:
|
||||
free(dir);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
@ -156,7 +157,8 @@ main(int argc, char **argv)
|
|||
{
|
||||
prop_dictionary_t dict;
|
||||
repo_info_t *rinfo = NULL;
|
||||
const char *dpkgidx, *repolist;
|
||||
const char *dpkgidx;
|
||||
char *repolist;
|
||||
|
||||
if (argc < 2)
|
||||
usage();
|
||||
|
@ -179,19 +181,25 @@ main(int argc, char **argv)
|
|||
if (dict == NULL) {
|
||||
printf("Directory %s does not contain any "
|
||||
"xbps pkgindex file.\n", dpkgidx);
|
||||
free(repolist);
|
||||
exit(EINVAL);
|
||||
}
|
||||
|
||||
rinfo = malloc(sizeof(*rinfo));
|
||||
if (rinfo == NULL)
|
||||
if (rinfo == NULL) {
|
||||
free(repolist);
|
||||
exit(ENOMEM);
|
||||
}
|
||||
|
||||
if (!pkgindex_getinfo(dict, rinfo)) {
|
||||
printf("'%s' is incomplete.\n", repolist);
|
||||
free(rinfo);
|
||||
free(repolist);
|
||||
exit(EINVAL);
|
||||
}
|
||||
|
||||
free(repolist);
|
||||
|
||||
if (!xbps_register_repository(dpkgidx)) {
|
||||
printf("ERROR: couldn't register repository (%s)\n",
|
||||
strerror(errno));
|
||||
|
|
|
@ -147,6 +147,6 @@ bool xbps_remove_string_from_array(prop_object_t, void *, bool *);
|
|||
bool xbps_show_pkg_info_from_repolist(prop_object_t obj, void *, bool *);
|
||||
bool xbps_show_pkg_namedesc(prop_object_t, void *, bool *);
|
||||
bool xbps_search_string_in_pkgs(prop_object_t, void *, bool *);
|
||||
const char *xbps_get_pkgidx_string(const char *);
|
||||
char *xbps_get_pkgidx_string(const char *);
|
||||
|
||||
#endif /* !_XBPS_PLIST_H_ */
|
||||
|
|
31
lib/plist.c
31
lib/plist.c
|
@ -155,11 +155,10 @@ xbps_get_array_iter_from_dict(prop_dictionary_t dict, const char *key)
|
|||
return prop_array_iterator(array);
|
||||
}
|
||||
|
||||
const char *
|
||||
char *
|
||||
xbps_get_pkgidx_string(const char *repofile)
|
||||
{
|
||||
const char *res;
|
||||
char plist[PATH_MAX], *len;
|
||||
char plist[PATH_MAX], *len, *result;
|
||||
|
||||
assert(repofile != NULL);
|
||||
|
||||
|
@ -171,9 +170,13 @@ xbps_get_pkgidx_string(const char *repofile)
|
|||
plist[sizeof(plist) - 1] = '\0';
|
||||
strncat(plist, "/", sizeof(plist) - strlen(plist) - 1);
|
||||
strncat(plist, XBPS_PKGINDEX, sizeof(plist) - strlen(plist) - 1);
|
||||
res = plist;
|
||||
|
||||
return res;
|
||||
result = malloc(strlen(plist));
|
||||
if (result == NULL)
|
||||
return NULL;
|
||||
|
||||
strncpy(result, plist, strlen(plist));
|
||||
return result;
|
||||
}
|
||||
|
||||
bool
|
||||
|
@ -459,7 +462,8 @@ bool
|
|||
xbps_search_string_in_pkgs(prop_object_t obj, void *arg, bool *loop_done)
|
||||
{
|
||||
prop_dictionary_t dict;
|
||||
const char *repofile, *plist;
|
||||
const char *repofile;
|
||||
char *plist;
|
||||
|
||||
assert(prop_object_type(obj) == PROP_TYPE_STRING);
|
||||
|
||||
|
@ -473,13 +477,17 @@ xbps_search_string_in_pkgs(prop_object_t obj, void *arg, bool *loop_done)
|
|||
return false;
|
||||
|
||||
dict = prop_dictionary_internalize_from_file(plist);
|
||||
if (dict == NULL || prop_dictionary_count(dict) == 0)
|
||||
if (dict == NULL || prop_dictionary_count(dict) == 0) {
|
||||
free(plist);
|
||||
return false;
|
||||
}
|
||||
|
||||
printf("From %s repository ...\n", repofile);
|
||||
xbps_callback_array_iter_in_dict(dict, "packages",
|
||||
xbps_show_pkg_namedesc, arg);
|
||||
|
||||
free(plist);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -488,7 +496,8 @@ xbps_show_pkg_info_from_repolist(prop_object_t obj, void *arg, bool *loop_done)
|
|||
{
|
||||
prop_dictionary_t dict, pkgdict;
|
||||
prop_string_t oloc;
|
||||
const char *repofile, *repoloc, *plist;
|
||||
const char *repofile, *repoloc;
|
||||
char *plist;
|
||||
|
||||
assert(prop_object_type(obj) == PROP_TYPE_STRING);
|
||||
|
||||
|
@ -501,8 +510,12 @@ xbps_show_pkg_info_from_repolist(prop_object_t obj, void *arg, bool *loop_done)
|
|||
return false;
|
||||
|
||||
dict = prop_dictionary_internalize_from_file(plist);
|
||||
if (dict == NULL || prop_dictionary_count(dict) == 0)
|
||||
if (dict == NULL || prop_dictionary_count(dict) == 0) {
|
||||
free(plist);
|
||||
return false;
|
||||
}
|
||||
|
||||
free(plist);
|
||||
pkgdict = xbps_find_pkg_in_dict(dict, arg);
|
||||
if (pkgdict == NULL)
|
||||
return false;
|
||||
|
|
Loading…
Reference in New Issue