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

@@ -53,7 +53,7 @@ xbps_check_is_installed_pkg(const char *pkg)
assert(pkg != NULL);
if (!xbps_append_full_path(plist, NULL, XBPS_REGPKGDB))
if (!xbps_append_full_path(true, plist, NULL, XBPS_REGPKGDB))
return EINVAL;
pkgname = xbps_get_pkg_name(pkg);
@@ -207,7 +207,7 @@ xbps_install_pkg_deps(prop_dictionary_t pkg)
assert(pkg != NULL);
if (!xbps_append_full_path(plist, NULL, XBPS_REPOLIST))
if (!xbps_append_full_path(true, plist, NULL, XBPS_REPOLIST))
return EINVAL;
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) {
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)) {
xbps_clean_pkg_depslist();
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.
*/
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))
return EINVAL;
@@ -125,7 +125,7 @@ xbps_install_binary_pkg(const char *pkgname, const char *destdir)
* Get the dictionary with the list of registered
* repositories.
*/
if (!xbps_append_full_path(plist, NULL, XBPS_REPOLIST))
if (!xbps_append_full_path(true, plist, NULL, XBPS_REPOLIST))
return EINVAL;
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(desc != NULL);
if (!xbps_append_full_path(plist, NULL, XBPS_REGPKGDB))
if (!xbps_append_full_path(true, plist, NULL, XBPS_REGPKGDB))
return EINVAL;
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");
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(filename)))
return EINVAL;

View File

@@ -275,7 +275,7 @@ xbps_register_repository(const char *uri)
assert(uri != NULL);
if (!xbps_append_full_path(plist, NULL, XBPS_REPOLIST)) {
if (!xbps_append_full_path(true, plist, NULL, XBPS_REPOLIST)) {
errno = EINVAL;
return false;
}
@@ -354,7 +354,7 @@ xbps_unregister_repository(const char *uri)
assert(uri != NULL);
if (!xbps_append_full_path(plist, NULL, XBPS_REPOLIST)) {
if (!xbps_append_full_path(true, plist, NULL, XBPS_REPOLIST)) {
errno = EINVAL;
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);
assert(repofile != NULL);
if (!xbps_append_full_path(plist, repofile, XBPS_PKGINDEX))
if (!xbps_append_full_path(false, plist, repofile, XBPS_PKGINDEX))
return EINVAL;
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);
/* 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;
dict = prop_dictionary_internalize_from_file(plist);

View File

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