Added support to specify a root directory for xbps.

All xbps metadata files will go into <rootdir>/var/cache/xbps
and package data will go into <rootdir>/<data>.

--HG--
extra : convert_revision : 37007ac4f9b99b31465612a58749713b3164139b
This commit is contained in:
Juan RP 2008-12-27 12:56:51 +01:00
parent 091a8bf618
commit b2abe59c52
9 changed files with 171 additions and 129 deletions

View file

@ -30,6 +30,7 @@
#include <errno.h> #include <errno.h>
#include <limits.h> #include <limits.h>
#include <libgen.h> #include <libgen.h>
#include <unistd.h>
#include <xbps_api.h> #include <xbps_api.h>
@ -41,30 +42,28 @@ typedef struct repository_info {
} repo_info_t; } repo_info_t;
static bool sanitize_localpath(char *, const char *); static bool sanitize_localpath(char *, const char *);
static prop_dictionary_t getrepolist_dict(void); static prop_dictionary_t getrepolist_dict(const char *);
static bool pkgindex_getinfo(prop_dictionary_t, repo_info_t *); static bool pkgindex_getinfo(prop_dictionary_t, repo_info_t *);
static void usage(void); static void usage(void);
static void static void
usage(void) usage(void)
{ {
printf("Usage: xbps-bin [action] [arguments]\n\n" printf("Usage: xbps-bin [options] [action] [arguments]\n\n"
" Available actions:\n" " Available actions:\n"
" install, list, repo-add, repo-list, repo-rm, search, show\n" " install, list, repo-add, repo-list, repo-rm, search, show\n"
" Action arguments:\n" " Actions with arguments:\n"
" install\t[<pkgname>] [<rootdir>]\n" " install\t<pkgname>\n"
" list\n" " repo-add\t<URI>\n"
" repo-add\t[<URI>]\n" " repo-rm\t<URI>\n"
" repo-list\t[none]\n" " search\t<string>\n"
" repo-rm\t[<URI>]\n" " show\t<pkgname>\n"
" search\t[<string>]\n" " Options shared by all actions:\n"
" show\t[<pkgname>]\n" " -r\t\t<rootdir>\n"
" Environment:\n"
" XBPS_META_PATH\tPath to the xbps metadata directory\n"
"\n" "\n"
" Examples:\n" " Examples:\n"
" $ xbps-bin install klibc\n" " $ xbps-bin install klibc\n"
" $ xbps-bin install klibc /path/to/directory\n" " $ xbps-bin -r /path/to/root install klibc\n"
" $ xbps-bin list\n" " $ xbps-bin list\n"
" $ xbps-bin repo-add /path/to/directory\n" " $ xbps-bin repo-add /path/to/directory\n"
" $ xbps-bin repo-add http://www.location.org/xbps-repo\n" " $ xbps-bin repo-add http://www.location.org/xbps-repo\n"
@ -104,12 +103,14 @@ pkgindex_getinfo(prop_dictionary_t dict, repo_info_t *ri)
} }
static prop_dictionary_t static prop_dictionary_t
getrepolist_dict(void) getrepolist_dict(const char *root)
{ {
prop_dictionary_t dict; prop_dictionary_t dict;
char plist[PATH_MAX]; char plist[PATH_MAX];
if (!xbps_append_full_path(plist, NULL, XBPS_REPOLIST)) xbps_set_rootdir(root);
if (!xbps_append_full_path(true, plist, NULL, XBPS_REPOLIST))
exit(1); exit(1);
dict = prop_dictionary_internalize_from_file(plist); dict = prop_dictionary_internalize_from_file(plist);
@ -169,22 +170,41 @@ main(int argc, char **argv)
{ {
prop_dictionary_t dict; prop_dictionary_t dict;
repo_info_t *rinfo = NULL; repo_info_t *rinfo = NULL;
char dpkgidx[PATH_MAX], repolist[PATH_MAX]; char dpkgidx[PATH_MAX], repolist[PATH_MAX], *root = NULL;
int rv = 0; int c, rv = 0;
if (argc < 2) while ((c = getopt(argc, argv, "r:")) != -1) {
switch (c) {
case 'r':
/* To specify the root directory */
root = strdup(optarg);
if (root == NULL)
exit(ENOMEM);
xbps_set_rootdir(root);
break;
case '?':
default:
usage();
}
}
argc -= optind;
argv += optind;
if (argc < 1)
usage(); usage();
if (strcasecmp(argv[1], "repo-add") == 0) { if (strcasecmp(argv[0], "repo-add") == 0) {
/* Adds a new repository to the pool. */ /* Adds a new repository to the pool. */
if (argc != 3) if (argc != 2)
usage(); usage();
if (!sanitize_localpath(dpkgidx, argv[2])) if (!sanitize_localpath(dpkgidx, argv[1]))
exit(EINVAL); exit(EINVAL);
/* Temp buffer to verify pkgindex file. */ /* Temp buffer to verify pkgindex file. */
if (!xbps_append_full_path(repolist, dpkgidx, XBPS_PKGINDEX)) if (!xbps_append_full_path(false, repolist, dpkgidx,
XBPS_PKGINDEX))
exit(EINVAL); exit(EINVAL);
dict = prop_dictionary_internalize_from_file(repolist); dict = prop_dictionary_internalize_from_file(repolist);
@ -222,22 +242,22 @@ main(int argc, char **argv)
prop_object_release(dict); prop_object_release(dict);
free(rinfo); free(rinfo);
} else if (strcasecmp(argv[1], "repo-list") == 0) { } else if (strcasecmp(argv[0], "repo-list") == 0) {
/* Lists all repositories registered in pool. */ /* Lists all repositories registered in pool. */
if (argc != 2) if (argc != 1)
usage(); usage();
dict = getrepolist_dict(); dict = getrepolist_dict(root);
(void)xbps_callback_array_iter_in_dict(dict, (void)xbps_callback_array_iter_in_dict(dict,
"repository-list", xbps_list_strings_in_array, NULL); "repository-list", xbps_list_strings_in_array, NULL);
prop_object_release(dict); prop_object_release(dict);
} else if (strcasecmp(argv[1], "repo-rm") == 0) { } else if (strcasecmp(argv[0], "repo-rm") == 0) {
/* Remove a repository from the pool. */ /* Remove a repository from the pool. */
if (argc != 3) if (argc != 2)
usage(); usage();
if (!sanitize_localpath(dpkgidx, argv[2])) if (!sanitize_localpath(dpkgidx, argv[1]))
exit(EINVAL); exit(EINVAL);
if (!xbps_unregister_repository(dpkgidx)) { if (!xbps_unregister_repository(dpkgidx)) {
@ -250,37 +270,37 @@ main(int argc, char **argv)
exit(EINVAL); exit(EINVAL);
} }
} else if (strcasecmp(argv[1], "search") == 0) { } else if (strcasecmp(argv[0], "search") == 0) {
/* Search for a package by looking at short_desc. */ /* Search for a package by looking at short_desc. */
if (argc != 3) if (argc != 2)
usage(); usage();
dict = getrepolist_dict(); dict = getrepolist_dict(root);
(void)xbps_callback_array_iter_in_dict(dict, (void)xbps_callback_array_iter_in_dict(dict,
"repository-list", xbps_search_string_in_pkgs, argv[2]); "repository-list", xbps_search_string_in_pkgs, argv[1]);
prop_object_release(dict); prop_object_release(dict);
} else if (strcasecmp(argv[1], "show") == 0) { } else if (strcasecmp(argv[0], "show") == 0) {
/* Shows info about a binary package. */ /* Shows info about a binary package. */
if (argc != 3) if (argc != 2)
usage(); usage();
dict = getrepolist_dict(); dict = getrepolist_dict(root);
if (xbps_callback_array_iter_in_dict(dict, "repository-list", if (xbps_callback_array_iter_in_dict(dict, "repository-list",
xbps_show_pkg_info_from_repolist, argv[2]) != 0) { xbps_show_pkg_info_from_repolist, argv[1]) != 0) {
prop_object_release(dict); prop_object_release(dict);
printf("ERROR: unable to locate package '%s'.\n", printf("ERROR: unable to locate package '%s'.\n",
argv[2]); argv[1]);
exit(EINVAL); exit(EINVAL);
} }
prop_object_release(dict); prop_object_release(dict);
} else if (strcasecmp(argv[1], "list") == 0) { } else if (strcasecmp(argv[0], "list") == 0) {
/* Lists packages currently registered in database. */ /* Lists packages currently registered in database. */
if (argc != 2) if (argc != 1)
usage(); usage();
if (!xbps_append_full_path(dpkgidx, NULL, XBPS_REGPKGDB)) if (!xbps_append_full_path(true, dpkgidx, NULL, XBPS_REGPKGDB))
exit(EINVAL); exit(EINVAL);
dict = prop_dictionary_internalize_from_file(dpkgidx); dict = prop_dictionary_internalize_from_file(dpkgidx);
@ -296,21 +316,15 @@ main(int argc, char **argv)
} }
prop_object_release(dict); prop_object_release(dict);
} else if (strcasecmp(argv[1], "install") == 0) { } else if (strcasecmp(argv[0], "install") == 0) {
/* Installs a binary package and required deps. */ /* Installs a binary package and required deps. */
if (argc < 3 || argc > 4) if (argc != 2)
usage(); usage();
if (argc == 3) { /* Install into root directory by default. */
/* Install into root directory by default. */ rv = xbps_install_binary_pkg(argv[1], root);
rv = xbps_install_binary_pkg(argv[2], "/");
} else {
/* install into specified directory. */
rv = xbps_install_binary_pkg(argv[2], argv[3]);
}
if (rv) { if (rv) {
printf("ERROR: unable to install %s.\n", argv[2]); printf("ERROR: unable to install %s.\n", argv[1]);
exit(rv); exit(rv);
} }
} else { } else {

View file

@ -48,16 +48,17 @@ write_plist_file(prop_dictionary_t dict, const char *file)
static void static void
usage(void) usage(void)
{ {
printf("usage: xbps-pkgdb <action> [args]\n\n" printf("usage: xbps-pkgdb [options] [action] [args]\n\n"
" Available actions:\n" " Available actions:\n"
" register, sanitize-plist, unregister, version\n" " register, sanitize-plist, unregister, version\n"
" Action arguments:\n" " Action arguments:\n"
" register\t[<pkgname> <version> <shortdesc>]\n" " register\t\t<pkgname> <version> <shortdesc>\n"
" sanitize-plist\t[<plist>]\n" " sanitize-plist\t<plist>\n"
" unregister\t[<pkgname> <version>]\n" " unregister\t\t<pkgname> <version>\n"
" version\t[<pkgname>]\n" " version\t\t<pkgname>\n"
" Environment:\n" " Options shared by all actions:\n"
" XBPS_META_PATH\tPath to xbps metadata root directory\n\n" " -r\t\t\t<rootdir>\n"
"\n"
" Examples:\n" " Examples:\n"
" $ xbps-pkgdb register pkgname 2.0 \"A short description\"\n" " $ xbps-pkgdb register pkgname 2.0 \"A short description\"\n"
" $ xbps-pkgdb sanitize-plist /blah/foo.plist\n" " $ xbps-pkgdb sanitize-plist /blah/foo.plist\n"
@ -71,14 +72,32 @@ main(int argc, char **argv)
{ {
prop_dictionary_t dbdict = NULL, pkgdict; prop_dictionary_t dbdict = NULL, pkgdict;
const char *version; const char *version;
char dbfile[PATH_MAX], *in_chroot_env; char dbfile[PATH_MAX], *in_chroot_env, *root = NULL;
bool in_chroot = false; bool in_chroot = false;
int rv = 0; int c, rv = 0;
if (argc < 2) while ((c = getopt(argc, argv, "r:")) != -1) {
switch (c) {
case 'r':
/* To specify the root directory */
root = strdup(optarg);
if (root == NULL)
exit(ENOMEM);
xbps_set_rootdir(root);
break;
case '?':
default:
usage();
}
}
argc -= optind;
argv += optind;
if (argc < 1)
usage(); usage();
if (!xbps_append_full_path(dbfile, NULL, XBPS_REGPKGDB)) { if (!xbps_append_full_path(true, dbfile, NULL, XBPS_REGPKGDB)) {
printf("=> ERROR: couldn't find regpkdb file (%s)\n", printf("=> ERROR: couldn't find regpkdb file (%s)\n",
strerror(errno)); strerror(errno));
exit(EINVAL); exit(EINVAL);
@ -88,53 +107,53 @@ main(int argc, char **argv)
if (in_chroot_env != NULL) if (in_chroot_env != NULL)
in_chroot = true; in_chroot = true;
if (strcasecmp(argv[1], "register") == 0) { if (strcasecmp(argv[0], "register") == 0) {
/* Registers a package into the database */ /* Registers a package into the database */
if (argc != 5)
usage();
rv = xbps_register_pkg(argv[2], argv[3], argv[4]);
if (rv == EEXIST) {
printf("%s=> %s-%s already registered.\n",
in_chroot ? "[chroot] " : "", argv[2], argv[3]);
} else if (rv != 0) {
printf("%s=> couldn't register %s-%s (%s).\n",
in_chroot ? "[chroot] " : "" , argv[2], argv[3],
strerror(rv));
} else {
printf("%s=> %s-%s registered successfully.\n",
in_chroot ? "[chroot] " : "", argv[2], argv[3]);
}
} else if (strcasecmp(argv[1], "unregister") == 0) {
/* Unregisters a package from the database */
if (argc != 4) if (argc != 4)
usage(); usage();
if (!xbps_remove_pkg_dict_from_file(argv[2], dbfile)) { rv = xbps_register_pkg(argv[1], argv[2], argv[3]);
if (rv == EEXIST) {
printf("%s=> %s-%s already registered.\n",
in_chroot ? "[chroot] " : "", argv[1], argv[2]);
} else if (rv != 0) {
printf("%s=> couldn't register %s-%s (%s).\n",
in_chroot ? "[chroot] " : "" , argv[1], argv[2],
strerror(rv));
} else {
printf("%s=> %s-%s registered successfully.\n",
in_chroot ? "[chroot] " : "", argv[1], argv[2]);
}
} else if (strcasecmp(argv[0], "unregister") == 0) {
/* Unregisters a package from the database */
if (argc != 3)
usage();
if (!xbps_remove_pkg_dict_from_file(argv[1], dbfile)) {
if (errno == ENODEV) if (errno == ENODEV)
printf("=> ERROR: %s not registered " printf("=> ERROR: %s not registered "
"in database.\n", argv[2]); "in database.\n", argv[1]);
else else
printf("=> ERROR: couldn't unregister %s " printf("=> ERROR: couldn't unregister %s "
"from database (%s)\n", argv[2], "from database (%s)\n", argv[1],
strerror(errno)); strerror(errno));
exit(EINVAL); exit(EINVAL);
} }
printf("%s=> %s-%s unregistered successfully.\n", printf("%s=> %s-%s unregistered successfully.\n",
in_chroot ? "[chroot] " : "", argv[2], argv[3]); in_chroot ? "[chroot] " : "", argv[1], argv[2]);
} else if (strcasecmp(argv[1], "version") == 0) { } else if (strcasecmp(argv[0], "version") == 0) {
/* Prints version of an installed package */ /* Prints version of an installed package */
if (argc != 3) if (argc != 2)
usage(); usage();
dbdict = prop_dictionary_internalize_from_file(dbfile); dbdict = prop_dictionary_internalize_from_file(dbfile);
if (dbdict == NULL) if (dbdict == NULL)
exit(1); exit(1);
pkgdict = xbps_find_pkg_in_dict(dbdict, argv[2]); pkgdict = xbps_find_pkg_in_dict(dbdict, argv[1]);
if (pkgdict == NULL) if (pkgdict == NULL)
exit(1); exit(1);
@ -144,18 +163,18 @@ main(int argc, char **argv)
printf("%s\n", version); printf("%s\n", version);
} else if (strcasecmp(argv[1], "sanitize-plist") == 0) { } else if (strcasecmp(argv[0], "sanitize-plist") == 0) {
/* Sanitize a plist file (indent the file properly) */ /* Sanitize a plist file (indent the file properly) */
if (argc != 3) if (argc != 1)
usage(); usage();
dbdict = prop_dictionary_internalize_from_file(argv[2]); dbdict = prop_dictionary_internalize_from_file(argv[1]);
if (dbdict == NULL) { if (dbdict == NULL) {
printf("=> ERROR: couldn't sanitize %s plist file " printf("=> ERROR: couldn't sanitize %s plist file "
"(%s)\n", argv[2], strerror(errno)); "(%s)\n", argv[1], strerror(errno));
exit(1); exit(1);
} }
write_plist_file(dbdict, argv[2]); write_plist_file(dbdict, argv[1]);
} else { } else {
usage(); usage();

View file

@ -110,8 +110,8 @@ set_defvars()
[ ! -d "$val" ] && msg_error "cannot find $i, aborting." [ ! -d "$val" ] && msg_error "cannot find $i, aborting."
done done
XBPS_REGPKGDB_CMD="env XBPS_META_PATH=$XBPS_META_PATH xbps-pkgdb" XBPS_REGPKGDB_CMD="xbps-pkgdb -r $XBPS_MASTERDIR"
XBPS_BIN_CMD="env XBPS_META_PATH=$XBPS_META_PATH xbps-bin" XBPS_BIN_CMD="xbps-bin -r $XBPS_MASTERDIR"
} }
# #

View file

@ -152,7 +152,8 @@ int xbps_show_pkg_namedesc(prop_object_t, void *, bool *);
int xbps_search_string_in_pkgs(prop_object_t, void *, bool *); int xbps_search_string_in_pkgs(prop_object_t, void *, bool *);
/* Utils */ /* Utils */
bool xbps_append_full_path(char *, const char *, const char *); void xbps_set_rootdir(const char *);
bool xbps_append_full_path(bool, char *, const char *, const char *);
int xbps_check_is_installed_pkg(const char *); int xbps_check_is_installed_pkg(const char *);
int xbps_cmpver_packages(const char *, const char *); int xbps_cmpver_packages(const char *, const char *);
int xbps_cmpver_versions(const char *, const char *); int xbps_cmpver_versions(const char *, const char *);

View file

@ -36,7 +36,7 @@
#include <archive_entry.h> #include <archive_entry.h>
/* Default root PATH for xbps to store metadata info. */ /* Default root PATH for xbps to store metadata info. */
#define XBPS_META_PATH "/var/cache/xbps/" #define XBPS_META_PATH "/var/cache/xbps"
/* Filename for the repositories plist file. */ /* Filename for the repositories plist file. */
#define XBPS_REPOLIST "repositories.plist" #define XBPS_REPOLIST "repositories.plist"

View file

@ -53,7 +53,7 @@ xbps_check_is_installed_pkg(const char *pkg)
assert(pkg != NULL); assert(pkg != NULL);
if (!xbps_append_full_path(plist, NULL, XBPS_REGPKGDB)) if (!xbps_append_full_path(true, plist, NULL, XBPS_REGPKGDB))
return EINVAL; return EINVAL;
pkgname = xbps_get_pkg_name(pkg); pkgname = xbps_get_pkg_name(pkg);
@ -207,7 +207,7 @@ xbps_install_pkg_deps(prop_dictionary_t pkg)
assert(pkg != NULL); assert(pkg != NULL);
if (!xbps_append_full_path(plist, NULL, XBPS_REPOLIST)) if (!xbps_append_full_path(true, plist, NULL, XBPS_REPOLIST))
return EINVAL; return EINVAL;
repolistd = prop_dictionary_internalize_from_file(plist); repolistd = prop_dictionary_internalize_from_file(plist);
@ -229,7 +229,7 @@ xbps_install_pkg_deps(prop_dictionary_t pkg)
*/ */
while ((obj = prop_object_iterator_next(iter)) != NULL) { while ((obj = prop_object_iterator_next(iter)) != NULL) {
memset(plist, 0, sizeof(&plist)); memset(plist, 0, sizeof(&plist));
if (!xbps_append_full_path(plist, if (!xbps_append_full_path(false, plist,
prop_string_cstring_nocopy(obj), XBPS_PKGINDEX)) { prop_string_cstring_nocopy(obj), XBPS_PKGINDEX)) {
xbps_clean_pkg_depslist(); xbps_clean_pkg_depslist();
prop_object_iterator_release(iter); prop_object_iterator_release(iter);

View file

@ -45,7 +45,7 @@ xbps_install_binary_pkg_from_repolist(prop_object_t obj, void *arg,
* Get the dictionary from a repository's index file. * Get the dictionary from a repository's index file.
*/ */
memset(plist, 0, sizeof(&plist)); memset(plist, 0, sizeof(&plist));
if (!xbps_append_full_path(plist, if (!xbps_append_full_path(false, plist,
prop_string_cstring_nocopy(obj), XBPS_PKGINDEX)) prop_string_cstring_nocopy(obj), XBPS_PKGINDEX))
return EINVAL; return EINVAL;
@ -125,7 +125,7 @@ xbps_install_binary_pkg(const char *pkgname, const char *destdir)
* Get the dictionary with the list of registered * Get the dictionary with the list of registered
* repositories. * repositories.
*/ */
if (!xbps_append_full_path(plist, NULL, XBPS_REPOLIST)) if (!xbps_append_full_path(true, plist, NULL, XBPS_REPOLIST))
return EINVAL; return EINVAL;
repolistd = prop_dictionary_internalize_from_file(plist); repolistd = prop_dictionary_internalize_from_file(plist);
@ -170,7 +170,7 @@ xbps_register_pkg(const char *pkgname, const char *version, const char *desc)
assert(version != NULL); assert(version != NULL);
assert(desc != NULL); assert(desc != NULL);
if (!xbps_append_full_path(plist, NULL, XBPS_REGPKGDB)) if (!xbps_append_full_path(true, plist, NULL, XBPS_REGPKGDB))
return EINVAL; return EINVAL;
dict = prop_dictionary_internalize_from_file(plist); dict = prop_dictionary_internalize_from_file(plist);
@ -278,7 +278,7 @@ xbps_unpack_binary_pkg(prop_dictionary_t repo, prop_dictionary_t pkg,
filename = prop_dictionary_get(pkg, "filename"); filename = prop_dictionary_get(pkg, "filename");
repoloc = prop_dictionary_get(repo, "location-local"); repoloc = prop_dictionary_get(repo, "location-local");
if (!xbps_append_full_path(binfile, if (!xbps_append_full_path(false, binfile,
prop_string_cstring_nocopy(repoloc), prop_string_cstring_nocopy(repoloc),
prop_string_cstring_nocopy(filename))) prop_string_cstring_nocopy(filename)))
return EINVAL; return EINVAL;

View file

@ -275,7 +275,7 @@ xbps_register_repository(const char *uri)
assert(uri != NULL); assert(uri != NULL);
if (!xbps_append_full_path(plist, NULL, XBPS_REPOLIST)) { if (!xbps_append_full_path(true, plist, NULL, XBPS_REPOLIST)) {
errno = EINVAL; errno = EINVAL;
return false; return false;
} }
@ -354,7 +354,7 @@ xbps_unregister_repository(const char *uri)
assert(uri != NULL); assert(uri != NULL);
if (!xbps_append_full_path(plist, NULL, XBPS_REPOLIST)) { if (!xbps_append_full_path(true, plist, NULL, XBPS_REPOLIST)) {
errno = EINVAL; errno = EINVAL;
return false; return false;
} }
@ -517,7 +517,7 @@ xbps_search_string_in_pkgs(prop_object_t obj, void *arg, bool *loop_done)
repofile = prop_string_cstring_nocopy(obj); repofile = prop_string_cstring_nocopy(obj);
assert(repofile != NULL); assert(repofile != NULL);
if (!xbps_append_full_path(plist, repofile, XBPS_PKGINDEX)) if (!xbps_append_full_path(false, plist, repofile, XBPS_PKGINDEX))
return EINVAL; return EINVAL;
dict = prop_dictionary_internalize_from_file(plist); dict = prop_dictionary_internalize_from_file(plist);
@ -546,7 +546,7 @@ xbps_show_pkg_info_from_repolist(prop_object_t obj, void *arg, bool *loop_done)
repofile = prop_string_cstring_nocopy(obj); repofile = prop_string_cstring_nocopy(obj);
/* Get string for pkg-index.plist with full path. */ /* Get string for pkg-index.plist with full path. */
if (!xbps_append_full_path(plist, repofile, XBPS_PKGINDEX)) if (!xbps_append_full_path(false, plist, repofile, XBPS_PKGINDEX))
return EINVAL; return EINVAL;
dict = prop_dictionary_internalize_from_file(plist); dict = prop_dictionary_internalize_from_file(plist);

View file

@ -32,6 +32,8 @@
#include <xbps_api.h> #include <xbps_api.h>
static const char *rootdir;
const char * const char *
xbps_get_pkg_version(const char *pkg) xbps_get_pkg_version(const char *pkg)
{ {
@ -80,34 +82,40 @@ xbps_pkg_has_rundeps(prop_dictionary_t pkg)
return false; return false;
} }
bool void
xbps_append_full_path(char *buf, const char *root, const char *plistf) xbps_set_rootdir(const char *dir)
{ {
const char *env, *tmp; assert(dir != NULL);
size_t len = 0; rootdir = dir;
}
bool
xbps_append_full_path(bool use_rootdir, char *buf, const char *basedir,
const char *plistf)
{
const char *env;
assert(buf != NULL); assert(buf != NULL);
assert(plistf != NULL); assert(plistf != NULL);
if (root) if (basedir)
env = root; env = basedir;
else { else
env = getenv("XBPS_META_PATH"); env = XBPS_META_PATH;
if (env == NULL)
env = XBPS_META_PATH;
}
tmp = strncpy(buf, env, PATH_MAX - 1); if (rootdir && use_rootdir) {
if (sizeof(*tmp) >= PATH_MAX) { if (snprintf(buf, PATH_MAX - 1, "%s/%s/%s",
errno = ENOSPC; rootdir, env, plistf) < 0) {
return false; errno = ENOSPC;
return false;
}
} else {
if (snprintf(buf, PATH_MAX - 1, "%s/%s",
env, plistf) < 0) {
errno = ENOSPC;
return false;
}
} }
len = strlen(buf);
buf[len + 1] = '\0';
if (buf[len - 2] != '/')
strncat(buf, "/", 1);
strncat(buf, plistf, sizeof(buf) - strlen(buf) - 1);
return true; return true;
} }