Checkpoint for installation of binary packages.
--HG-- extra : convert_revision : 0bc55ebae04b2e1e5ab20feca786b649fc2e0335
This commit is contained in:
parent
9bb392de51
commit
26c054d773
12 changed files with 510 additions and 185 deletions
|
@ -40,7 +40,7 @@ typedef struct repository_info {
|
|||
uint64_t total_pkgs;
|
||||
} repo_info_t;
|
||||
|
||||
static const char *sanitize_localpath(const char *);
|
||||
static bool sanitize_localpath(char *, const char *);
|
||||
static prop_dictionary_t getrepolist_dict(void);
|
||||
static bool pkgindex_getinfo(prop_dictionary_t, repo_info_t *);
|
||||
static void usage(void);
|
||||
|
@ -100,8 +100,12 @@ static prop_dictionary_t
|
|||
getrepolist_dict(void)
|
||||
{
|
||||
prop_dictionary_t dict;
|
||||
char plist[PATH_MAX];
|
||||
|
||||
dict = prop_dictionary_internalize_from_file(XBPS_REPOLIST_PATH);
|
||||
if (!xbps_append_full_path(plist, NULL, XBPS_REPOLIST))
|
||||
exit(1);
|
||||
|
||||
dict = prop_dictionary_internalize_from_file(plist);
|
||||
if (dict == NULL) {
|
||||
printf("ERROR: cannot find repository plist file (%s).\n",
|
||||
strerror(errno));
|
||||
|
@ -111,45 +115,46 @@ getrepolist_dict(void)
|
|||
return dict;
|
||||
}
|
||||
|
||||
static const char *
|
||||
sanitize_localpath(const char *path)
|
||||
static bool
|
||||
sanitize_localpath(char *buf, const char *path)
|
||||
{
|
||||
static char strtmp[PATH_MAX];
|
||||
char *dirnp, *basenp, *dir, *base;
|
||||
const char *res;
|
||||
char *dirnp, *basenp, *dir, *base, *tmp;
|
||||
|
||||
dir = strdup(path);
|
||||
if (dir == NULL)
|
||||
return NULL;
|
||||
return false;
|
||||
|
||||
base = strdup(path);
|
||||
if (base == NULL)
|
||||
goto fail2;
|
||||
if (base == NULL) {
|
||||
free(dir);
|
||||
return false;
|
||||
}
|
||||
|
||||
dirnp = dirname(dir);
|
||||
if (strcmp(dirnp, ".") == 0)
|
||||
goto fail;
|
||||
goto error;
|
||||
|
||||
basenp = basename(base);
|
||||
if (strcmp(basenp, base) == 0)
|
||||
goto fail;
|
||||
goto error;
|
||||
|
||||
strncpy(strtmp, dirnp, sizeof(strtmp) - 1);
|
||||
strtmp[sizeof(strtmp) - 1] = '\0';
|
||||
tmp = strncpy(buf, dirnp, PATH_MAX - 1);
|
||||
if (sizeof(*tmp) >= PATH_MAX)
|
||||
goto error;
|
||||
|
||||
buf[strlen(buf) + 1] = '\0';
|
||||
if (strcmp(dirnp, "/"))
|
||||
strncat(strtmp, "/", sizeof(strtmp) - strlen(strtmp) - 1);
|
||||
strncat(strtmp, basenp, sizeof(strtmp) - strlen(strtmp) -1);
|
||||
|
||||
strncat(buf, "/", 1);
|
||||
strncat(buf, basenp, PATH_MAX - strlen(buf) - 1);
|
||||
free(dir);
|
||||
free(base);
|
||||
res = strtmp;
|
||||
|
||||
return res;
|
||||
fail:
|
||||
return true;
|
||||
|
||||
error:
|
||||
free(base);
|
||||
fail2:
|
||||
free(dir);
|
||||
return NULL;
|
||||
return false;
|
||||
}
|
||||
|
||||
int
|
||||
|
@ -157,8 +162,8 @@ main(int argc, char **argv)
|
|||
{
|
||||
prop_dictionary_t dict;
|
||||
repo_info_t *rinfo = NULL;
|
||||
const char *dpkgidx;
|
||||
char *repolist;
|
||||
char dpkgidx[PATH_MAX], repolist[PATH_MAX];
|
||||
int rv = 0;
|
||||
|
||||
if (argc < 2)
|
||||
usage();
|
||||
|
@ -168,41 +173,37 @@ main(int argc, char **argv)
|
|||
if (argc != 3)
|
||||
usage();
|
||||
|
||||
dpkgidx = sanitize_localpath(argv[2]);
|
||||
if (dpkgidx == NULL)
|
||||
if (!sanitize_localpath(dpkgidx, argv[2]))
|
||||
exit(EINVAL);
|
||||
|
||||
/* Temp buffer to verify pkgindex file. */
|
||||
repolist = xbps_get_pkgidx_string(dpkgidx);
|
||||
if (repolist == NULL)
|
||||
if (!xbps_append_full_path(repolist, dpkgidx, XBPS_PKGINDEX))
|
||||
exit(EINVAL);
|
||||
|
||||
dict = prop_dictionary_internalize_from_file(repolist);
|
||||
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) {
|
||||
free(repolist);
|
||||
prop_object_release(dict);
|
||||
exit(ENOMEM);
|
||||
}
|
||||
|
||||
if (!pkgindex_getinfo(dict, rinfo)) {
|
||||
printf("'%s' is incomplete.\n", repolist);
|
||||
prop_object_release(dict);
|
||||
free(rinfo);
|
||||
free(repolist);
|
||||
exit(EINVAL);
|
||||
}
|
||||
|
||||
free(repolist);
|
||||
|
||||
if (!xbps_register_repository(dpkgidx)) {
|
||||
printf("ERROR: couldn't register repository (%s)\n",
|
||||
strerror(errno));
|
||||
prop_object_release(dict);
|
||||
free(rinfo);
|
||||
exit(EINVAL);
|
||||
}
|
||||
|
@ -210,6 +211,7 @@ main(int argc, char **argv)
|
|||
printf("Added repository at %s (%s) with %ju packages.\n",
|
||||
rinfo->location_local, rinfo->index_version,
|
||||
rinfo->total_pkgs);
|
||||
prop_object_release(dict);
|
||||
free(rinfo);
|
||||
|
||||
} else if (strcasecmp(argv[1], "repo-list") == 0) {
|
||||
|
@ -217,16 +219,17 @@ main(int argc, char **argv)
|
|||
if (argc != 2)
|
||||
usage();
|
||||
|
||||
xbps_callback_array_iter_in_dict(getrepolist_dict(),
|
||||
dict = getrepolist_dict();
|
||||
xbps_callback_array_iter_in_dict(dict,
|
||||
"repository-list", xbps_list_strings_in_array, NULL);
|
||||
prop_object_release(dict);
|
||||
|
||||
} else if (strcasecmp(argv[1], "repo-rm") == 0) {
|
||||
/* Remove a repository from the pool. */
|
||||
if (argc != 3)
|
||||
usage();
|
||||
|
||||
dpkgidx = sanitize_localpath(argv[2]);
|
||||
if (dpkgidx == NULL)
|
||||
if (!sanitize_localpath(dpkgidx, argv[2]))
|
||||
exit(EINVAL);
|
||||
|
||||
if (!xbps_unregister_repository(dpkgidx)) {
|
||||
|
@ -244,27 +247,33 @@ main(int argc, char **argv)
|
|||
if (argc != 3)
|
||||
usage();
|
||||
|
||||
xbps_callback_array_iter_in_dict(getrepolist_dict(),
|
||||
dict = getrepolist_dict();
|
||||
xbps_callback_array_iter_in_dict(dict,
|
||||
"repository-list", xbps_search_string_in_pkgs, argv[2]);
|
||||
prop_object_release(dict);
|
||||
|
||||
} else if (strcasecmp(argv[1], "show") == 0) {
|
||||
/* Shows info about a binary package. */
|
||||
if (argc != 3)
|
||||
usage();
|
||||
|
||||
if (!xbps_callback_array_iter_in_dict(getrepolist_dict(),
|
||||
"repository-list",
|
||||
dict = getrepolist_dict();
|
||||
if (!xbps_callback_array_iter_in_dict(dict, "repository-list",
|
||||
xbps_show_pkg_info_from_repolist, argv[2])) {
|
||||
printf("ERROR: unable to locate package '%s'.\n",
|
||||
argv[2]);
|
||||
exit(EINVAL);
|
||||
}
|
||||
prop_object_release(dict);
|
||||
|
||||
} else if (strcasecmp(argv[1], "install") == 0) {
|
||||
/* Installs a binary package and required deps. */
|
||||
if (argc != 3)
|
||||
usage();
|
||||
|
||||
rv = xbps_install_binary_pkg(argv[2], "/home/juan/root_xbps");
|
||||
if (rv)
|
||||
exit(rv);
|
||||
} else {
|
||||
usage();
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue