2010-11-19 18:10:13 +05:30
|
|
|
/*-
|
2014-01-09 16:11:25 +05:30
|
|
|
* Copyright (c) 2011-2014 Juan Romero Pardines.
|
2014-05-06 12:59:26 +05:30
|
|
|
* Copyright (c) 2014 Enno Boland.
|
2010-11-19 18:10:13 +05:30
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
|
|
|
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
|
|
|
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
|
|
|
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|
|
|
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
|
|
|
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
|
|
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
|
|
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
|
|
|
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
*/
|
|
|
|
|
2012-11-19 20:12:24 +05:30
|
|
|
#include <sys/utsname.h>
|
|
|
|
#include <sys/types.h>
|
2010-11-19 18:10:13 +05:30
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
2014-01-08 01:50:42 +05:30
|
|
|
#define _BSD_SOURCE /* required by strlcpy with musl */
|
2010-11-19 18:10:13 +05:30
|
|
|
#include <string.h>
|
2014-01-08 01:50:42 +05:30
|
|
|
#undef _BSD_SOURCE
|
2014-02-25 21:12:52 +05:30
|
|
|
#include <strings.h>
|
2010-11-19 18:10:13 +05:30
|
|
|
#include <errno.h>
|
|
|
|
#include <stdarg.h>
|
2012-11-19 20:12:24 +05:30
|
|
|
#include <dirent.h>
|
2014-02-25 21:12:52 +05:30
|
|
|
#include <ctype.h>
|
2014-05-06 02:40:18 +05:30
|
|
|
#include <glob.h>
|
2014-05-13 15:07:09 +05:30
|
|
|
#include <libgen.h>
|
2010-11-19 18:10:13 +05:30
|
|
|
|
|
|
|
#include "xbps_api_impl.h"
|
|
|
|
|
2014-03-11 13:58:50 +05:30
|
|
|
#ifdef __clang__
|
|
|
|
#pragma clang diagnostic ignored "-Wformat-nonliteral"
|
|
|
|
#endif
|
|
|
|
|
2014-05-06 13:51:44 +05:30
|
|
|
static int parse_file(struct xbps_handle *, const char *, bool, bool);
|
|
|
|
|
2011-01-22 18:54:51 +05:30
|
|
|
/**
|
|
|
|
* @file lib/initend.c
|
|
|
|
* @brief Initialization and finalization routines
|
|
|
|
* @defgroup initend Initialization and finalization functions
|
|
|
|
*
|
2011-02-21 22:12:47 +05:30
|
|
|
* Use these functions to initialize some parameters before start
|
2011-01-22 18:54:51 +05:30
|
|
|
* using libxbps and finalize usage to release resources at the end.
|
|
|
|
*/
|
2014-02-25 21:12:52 +05:30
|
|
|
static void
|
|
|
|
store_vpkg(struct xbps_handle *xhp, const char *path, size_t line, char *vpkg_s)
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
* Append virtual package overrides to our vpkgd dictionary:
|
|
|
|
*
|
|
|
|
* <key>vpkgver</key>
|
|
|
|
* <string>realpkgname</string>
|
|
|
|
*/
|
|
|
|
char *vpkg, *rpkg, *tc;
|
|
|
|
size_t vpkglen;
|
|
|
|
|
|
|
|
if (xhp->vpkgd == NULL)
|
|
|
|
xhp->vpkgd = xbps_dictionary_create();
|
|
|
|
|
|
|
|
/* real pkg after ':' */
|
|
|
|
vpkg = vpkg_s;
|
|
|
|
rpkg = strchr(vpkg_s, ':');
|
|
|
|
if (rpkg == NULL || *rpkg == '\0') {
|
|
|
|
xbps_dbg_printf(xhp, "%s: ignoring invalid "
|
|
|
|
"virtualpkg option at line %zu\n", path, line);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
/* vpkg until ':' */
|
|
|
|
tc = strchr(vpkg_s, ':');
|
|
|
|
vpkglen = strlen(vpkg_s) - strlen(tc);
|
|
|
|
vpkg[vpkglen] = '\0';
|
|
|
|
|
|
|
|
/* skip ':' */
|
|
|
|
rpkg++;
|
|
|
|
xbps_dictionary_set_cstring(xhp->vpkgd, vpkg, rpkg);
|
|
|
|
xbps_dbg_printf(xhp, "%s: added vpkg %s for %s\n", path, vpkg, rpkg);
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool
|
|
|
|
store_repo(struct xbps_handle *xhp, const char *repo)
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
* Append repositories to our proplib array.
|
|
|
|
*/
|
|
|
|
if (xhp->repositories == NULL)
|
|
|
|
xhp->repositories = xbps_array_create();
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Do not add duplicates.
|
|
|
|
*/
|
|
|
|
for (unsigned int i = 0; i < xbps_array_count(xhp->repositories); i++) {
|
|
|
|
const char *srepo;
|
|
|
|
|
|
|
|
xbps_array_get_cstring_nocopy(xhp->repositories, i, &srepo);
|
|
|
|
if (strcmp(repo, srepo) == 0)
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
xbps_array_add_cstring(xhp->repositories, repo);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool
|
|
|
|
parse_option(char *buf, char **k, char **v)
|
|
|
|
{
|
|
|
|
size_t klen;
|
|
|
|
char *key, *value;
|
|
|
|
const char *keys[] = {
|
|
|
|
"rootdir",
|
|
|
|
"cachedir",
|
|
|
|
"syslog",
|
|
|
|
"repository",
|
|
|
|
"virtualpkgdir",
|
|
|
|
"virtualpkg",
|
|
|
|
"include"
|
|
|
|
};
|
|
|
|
bool found = false;
|
|
|
|
|
|
|
|
for (unsigned int i = 0; i < __arraycount(keys); i++) {
|
|
|
|
key = __UNCONST(keys[i]);
|
|
|
|
klen = strlen(key);
|
|
|
|
if (strncmp(buf, key, klen) == 0) {
|
|
|
|
found = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/* non matching option */
|
|
|
|
if (!found)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
/* check if next char is the equal sign */
|
|
|
|
if (buf[klen] != '=')
|
|
|
|
return false;
|
|
|
|
|
|
|
|
/* skip equal sign */
|
|
|
|
value = buf + klen + 1;
|
|
|
|
/* eat blanks */
|
|
|
|
while (isblank((unsigned char)*value))
|
|
|
|
value++;
|
|
|
|
/* eat final newline */
|
|
|
|
value[strlen(value)-1] = '\0';
|
|
|
|
/* option processed successfully */
|
|
|
|
*k = key;
|
|
|
|
*v = value;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2014-05-06 02:40:18 +05:30
|
|
|
static int
|
2014-05-15 20:30:29 +05:30
|
|
|
parse_files_glob(struct xbps_handle *xhp, const char *path, bool nested, bool vpkgconf)
|
|
|
|
{
|
|
|
|
glob_t globbuf;
|
2014-05-06 02:40:18 +05:30
|
|
|
int i, rv = 0;
|
|
|
|
|
|
|
|
glob(path, 0, NULL, &globbuf);
|
2014-05-29 13:00:58 +05:30
|
|
|
for (i = 0; globbuf.gl_pathv; i++) {
|
2014-05-13 15:14:49 +05:30
|
|
|
if ((rv = parse_file(xhp, globbuf.gl_pathv[i], nested, vpkgconf)) != 0)
|
2014-05-06 02:40:18 +05:30
|
|
|
break;
|
|
|
|
}
|
|
|
|
globfree(&globbuf);
|
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2014-02-25 21:12:52 +05:30
|
|
|
static int
|
|
|
|
parse_file(struct xbps_handle *xhp, const char *path, bool nested, bool vpkgconf)
|
|
|
|
{
|
|
|
|
FILE *fp;
|
|
|
|
size_t len, nlines = 0;
|
|
|
|
ssize_t read;
|
|
|
|
char *line = NULL;
|
2014-05-13 15:27:51 +05:30
|
|
|
char ocwd[XBPS_MAXPATH] = { 0 }, tmppath[XBPS_MAXPATH] = { 0 };
|
2014-05-13 15:07:09 +05:30
|
|
|
char *cwd;
|
2014-02-25 21:12:52 +05:30
|
|
|
int rv = 0;
|
|
|
|
|
|
|
|
if ((fp = fopen(path, "r")) == NULL) {
|
|
|
|
rv = errno;
|
|
|
|
xbps_dbg_printf(xhp, "cannot read configuration file %s: %s\n", path, strerror(rv));
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!vpkgconf) {
|
|
|
|
xbps_dbg_printf(xhp, "Parsing configuration file: %s\n", path);
|
|
|
|
}
|
|
|
|
|
2014-05-13 15:07:09 +05:30
|
|
|
/* cwd to the dir containing the config file */
|
2014-05-13 15:27:51 +05:30
|
|
|
strlcpy(tmppath, path, sizeof(tmppath));
|
2014-05-13 15:07:09 +05:30
|
|
|
cwd = dirname(tmppath);
|
2014-05-13 15:14:49 +05:30
|
|
|
if (getcwd(ocwd, sizeof(ocwd)) == NULL) {
|
2014-05-13 15:07:09 +05:30
|
|
|
rv = errno;
|
|
|
|
xbps_dbg_printf(xhp, "cannot get cwd: %s\n", strerror(rv));
|
|
|
|
return rv;
|
|
|
|
}
|
2014-05-13 15:14:49 +05:30
|
|
|
if (chdir(cwd)) {
|
2014-05-13 15:07:09 +05:30
|
|
|
rv = errno;
|
|
|
|
xbps_dbg_printf(xhp, "cannot chdir to %s: %s\n", cwd, strerror(rv));
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2014-02-25 21:12:52 +05:30
|
|
|
while ((read = getline(&line, &len, fp)) != -1) {
|
|
|
|
char *p, *k, *v;
|
|
|
|
|
|
|
|
nlines++;
|
|
|
|
p = line;
|
|
|
|
/* eat blanks */
|
|
|
|
while (isblank((unsigned char)*p))
|
|
|
|
p++;
|
|
|
|
/* ignore comments or empty lines */
|
|
|
|
if (*p == '#' || *p == '\n')
|
|
|
|
continue;
|
|
|
|
if (!parse_option(p, &k, &v)) {
|
|
|
|
xbps_dbg_printf(xhp, "%s: ignoring invalid option at "
|
|
|
|
"line %zu\n", path, nlines);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (strcmp(k, "rootdir") == 0) {
|
|
|
|
xbps_dbg_printf(xhp, "%s: rootdir set to %s\n",
|
|
|
|
path, v);
|
|
|
|
snprintf(xhp->rootdir, sizeof(xhp->rootdir), "%s", v);
|
|
|
|
} else if (strcmp(k, "cachedir") == 0) {
|
|
|
|
xbps_dbg_printf(xhp, "%s: cachedir set to %s\n",
|
|
|
|
path, v);
|
|
|
|
snprintf(xhp->cachedir, sizeof(xhp->cachedir), "%s", v);
|
|
|
|
} else if (strcmp(k, "virtualpkgdir") == 0) {
|
|
|
|
xbps_dbg_printf(xhp, "%s: virtualpkgdir set to %s\n",
|
|
|
|
path, v);
|
|
|
|
snprintf(xhp->virtualpkgdir, sizeof(xhp->virtualpkgdir), "%s", v);
|
|
|
|
} else if (strcmp(k, "syslog") == 0) {
|
|
|
|
if (strcasecmp(v, "true") == 0) {
|
|
|
|
xhp->syslog = true;
|
|
|
|
xbps_dbg_printf(xhp, "%s: syslog enabled\n", path);
|
|
|
|
}
|
|
|
|
} else if (strcmp(k, "repository") == 0) {
|
|
|
|
if (store_repo(xhp, v))
|
|
|
|
xbps_dbg_printf(xhp, "%s: added repository %s\n", path, v);
|
|
|
|
} else if (strcmp(k, "virtualpkg") == 0) {
|
|
|
|
store_vpkg(xhp, path, nlines, v);
|
|
|
|
}
|
|
|
|
/* Avoid double-nested parsing, only allow it once */
|
|
|
|
if (nested)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (strcmp(k, "include"))
|
|
|
|
continue;
|
|
|
|
|
2014-05-06 02:40:18 +05:30
|
|
|
if ((rv = parse_files_glob(xhp, v, true, false)) != 0)
|
2014-02-25 21:12:52 +05:30
|
|
|
break;
|
2014-05-06 02:40:18 +05:30
|
|
|
|
2014-02-25 21:12:52 +05:30
|
|
|
}
|
|
|
|
free(line);
|
|
|
|
fclose(fp);
|
|
|
|
|
2014-05-13 15:07:09 +05:30
|
|
|
/* Going back to old working directory */
|
2014-05-13 15:14:49 +05:30
|
|
|
if (chdir(ocwd)) {
|
2014-05-13 15:07:09 +05:30
|
|
|
rv = errno;
|
|
|
|
xbps_dbg_printf(xhp, "cannot chdir to %s: %s\n", ocwd, strerror(rv));
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2014-02-25 21:12:52 +05:30
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2011-12-15 15:49:20 +05:30
|
|
|
static int
|
2014-02-25 21:12:52 +05:30
|
|
|
parse_vpkgdir(struct xbps_handle *xhp)
|
2011-12-15 15:49:20 +05:30
|
|
|
{
|
2014-02-25 21:12:52 +05:30
|
|
|
DIR *dirp;
|
|
|
|
struct dirent *dp;
|
|
|
|
char *ext;
|
|
|
|
int rv = 0;
|
|
|
|
|
|
|
|
if ((dirp = opendir(xhp->virtualpkgdir)) == NULL)
|
|
|
|
return 0;
|
|
|
|
|
2014-05-30 15:18:10 +05:30
|
|
|
xbps_dbg_printf(xhp, "Processing virtualpkg directory: %s\n", xhp->virtualpkgdir);
|
2014-02-25 21:12:52 +05:30
|
|
|
|
|
|
|
while ((dp = readdir(dirp)) != NULL) {
|
|
|
|
if ((strcmp(dp->d_name, "..") == 0) ||
|
|
|
|
(strcmp(dp->d_name, ".") == 0))
|
|
|
|
continue;
|
|
|
|
/* only process .vpkg files, ignore something else */
|
|
|
|
if ((ext = strrchr(dp->d_name, '.')) == NULL)
|
|
|
|
continue;
|
|
|
|
if (strcmp(ext, ".vpkg") == 0) {
|
|
|
|
char *path;
|
|
|
|
|
|
|
|
path = xbps_xasprintf("%s/%s", xhp->virtualpkgdir, dp->d_name);
|
|
|
|
if ((rv = parse_file(xhp, path, false, true)) != 0) {
|
|
|
|
free(path);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
free(path);
|
2011-12-15 15:49:20 +05:30
|
|
|
}
|
|
|
|
}
|
2014-02-25 21:12:52 +05:30
|
|
|
closedir(dirp);
|
|
|
|
return rv;
|
2011-12-15 15:49:20 +05:30
|
|
|
}
|
2011-10-17 16:07:15 +05:30
|
|
|
|
2014-05-30 15:18:10 +05:30
|
|
|
static int
|
|
|
|
parse_repodir(struct xbps_handle *xhp)
|
|
|
|
{
|
|
|
|
DIR *dirp;
|
|
|
|
struct dirent *dp;
|
|
|
|
char *ext, conf[PATH_MAX];
|
|
|
|
int rv = 0;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Read all repository configuration files stored in the system
|
|
|
|
* repo.d directory.
|
|
|
|
*/
|
|
|
|
if ((dirp = opendir(XBPS_SYS_REPOD_PATH)) == NULL)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
xbps_dbg_printf(xhp, "Processing system repo.d directory: %s\n", XBPS_SYS_REPOD_PATH);
|
|
|
|
|
|
|
|
while ((dp = readdir(dirp)) != NULL) {
|
|
|
|
if ((strcmp(dp->d_name, "..") == 0) ||
|
|
|
|
(strcmp(dp->d_name, ".") == 0))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
/* only process .conf files, ignore something else */
|
|
|
|
if ((ext = strrchr(dp->d_name, '.')) == NULL)
|
|
|
|
continue;
|
|
|
|
if (strcmp(ext, ".conf")) {
|
|
|
|
xbps_dbg_printf(xhp, "%s: ignoring %s\n", XBPS_SYS_REPOD_PATH, dp->d_name);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
/* if the same file exists in configuration directory, ignore it */
|
|
|
|
snprintf(conf, sizeof(conf), "%s/%s", XBPS_REPOD_PATH, dp->d_name);
|
|
|
|
if (access(conf, R_OK) == 0) {
|
|
|
|
xbps_dbg_printf(xhp, "%s: ignoring %s (exists in confdir)\n", XBPS_SYS_REPOD_PATH, dp->d_name);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
/* parse repo conf file */
|
|
|
|
snprintf(conf, sizeof(conf), "%s/%s", XBPS_SYS_REPOD_PATH, dp->d_name);
|
|
|
|
if ((rv = parse_file(xhp, conf, false, false)) != 0) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
closedir(dirp);
|
|
|
|
if (rv != 0)
|
|
|
|
return rv;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Read all repository configuration files stored in the configuration
|
|
|
|
* repo.d directory.
|
|
|
|
*/
|
|
|
|
if ((dirp = opendir(XBPS_REPOD_PATH)) == NULL)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
xbps_dbg_printf(xhp, "Processing configuration repo.d directory: %s\n", XBPS_REPOD_PATH);
|
|
|
|
|
|
|
|
while ((dp = readdir(dirp)) != NULL) {
|
|
|
|
if ((strcmp(dp->d_name, "..") == 0) ||
|
|
|
|
(strcmp(dp->d_name, ".") == 0))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
/* only process .conf files, ignore something else */
|
|
|
|
if ((ext = strrchr(dp->d_name, '.')) == NULL)
|
|
|
|
continue;
|
|
|
|
if (strcmp(ext, ".conf")) {
|
|
|
|
xbps_dbg_printf(xhp, "%s: ignoring %s\n", XBPS_REPOD_PATH, dp->d_name);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
/* parse repo conf file */
|
|
|
|
snprintf(conf, sizeof(conf), "%s/%s", XBPS_REPOD_PATH, dp->d_name);
|
|
|
|
if ((rv = parse_file(xhp, conf, false, false)) != 0) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
closedir(dirp);
|
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2011-06-04 17:07:53 +05:30
|
|
|
int
|
2012-06-14 11:52:11 +05:30
|
|
|
xbps_init(struct xbps_handle *xhp)
|
2010-11-19 18:10:13 +05:30
|
|
|
{
|
2012-06-15 19:03:11 +05:30
|
|
|
struct utsname un;
|
2013-12-16 16:16:39 +05:30
|
|
|
char *buf;
|
2014-01-09 16:11:25 +05:30
|
|
|
const char *repodir, *native_arch;
|
2014-02-25 21:12:52 +05:30
|
|
|
int rv;
|
2011-06-04 17:07:53 +05:30
|
|
|
|
2012-06-14 11:52:11 +05:30
|
|
|
assert(xhp != NULL);
|
2011-02-21 22:12:47 +05:30
|
|
|
|
2011-12-15 15:49:20 +05:30
|
|
|
if (xhp->conffile == NULL)
|
|
|
|
xhp->conffile = XBPS_CONF_DEF;
|
|
|
|
|
2014-05-30 15:18:10 +05:30
|
|
|
/* parse repository configuration files */
|
|
|
|
if ((rv = parse_repodir(xhp)) != 0) {
|
|
|
|
xbps_dbg_printf(xhp, "failed to parse repo.d files: %s\n", strerror(rv));
|
|
|
|
}
|
2011-12-15 15:49:20 +05:30
|
|
|
/* parse configuration file */
|
2014-02-25 21:12:52 +05:30
|
|
|
if ((rv = parse_file(xhp, xhp->conffile, false, false)) != 0) {
|
|
|
|
xbps_dbg_printf(xhp, "failed to read configuration file %s: %s\n",
|
|
|
|
xhp->conffile, strerror(rv));
|
|
|
|
xbps_dbg_printf(xhp, "Using built-in defaults\n");
|
2011-06-04 20:38:44 +05:30
|
|
|
}
|
2013-12-16 16:16:39 +05:30
|
|
|
/* Set rootdir */
|
|
|
|
if (xhp->rootdir[0] == '\0') {
|
2014-02-25 21:12:52 +05:30
|
|
|
xhp->rootdir[0] = '/';
|
|
|
|
xhp->rootdir[1] = '\0';
|
2013-12-16 16:16:39 +05:30
|
|
|
} else if (xhp->rootdir[0] != '/') {
|
|
|
|
/* relative path */
|
|
|
|
char path[PATH_MAX-1];
|
2013-09-18 20:15:05 +05:30
|
|
|
|
2013-12-16 16:16:39 +05:30
|
|
|
if (getcwd(path, sizeof(path)) == NULL)
|
|
|
|
return ENOTSUP;
|
2012-11-19 16:42:38 +05:30
|
|
|
|
2013-12-16 16:16:39 +05:30
|
|
|
buf = strdup(xhp->rootdir);
|
|
|
|
snprintf(xhp->rootdir, sizeof(xhp->rootdir),
|
|
|
|
"%s/%s", path, buf);
|
|
|
|
free(buf);
|
|
|
|
}
|
|
|
|
/* Set cachedir */
|
|
|
|
if (xhp->cachedir[0] == '\0') {
|
|
|
|
snprintf(xhp->cachedir, sizeof(xhp->cachedir),
|
|
|
|
"%s/%s", strcmp(xhp->rootdir, "/") ? xhp->rootdir : "",
|
2014-02-25 21:12:52 +05:30
|
|
|
XBPS_CACHE_PATH);
|
2013-12-16 16:16:39 +05:30
|
|
|
} else if (xhp->cachedir[0] != '/') {
|
|
|
|
/* relative path */
|
|
|
|
buf = strdup(xhp->cachedir);
|
|
|
|
snprintf(xhp->cachedir, sizeof(xhp->cachedir),
|
|
|
|
"%s/%s", strcmp(xhp->rootdir, "/") ? xhp->rootdir : "", buf);
|
|
|
|
free(buf);
|
|
|
|
}
|
|
|
|
/* Set metadir */
|
|
|
|
if (xhp->metadir[0] == '\0') {
|
|
|
|
snprintf(xhp->metadir, sizeof(xhp->metadir),
|
|
|
|
"%s/%s", strcmp(xhp->rootdir, "/") ? xhp->rootdir : "",
|
|
|
|
XBPS_META_PATH);
|
|
|
|
} else if (xhp->metadir[0] != '/') {
|
|
|
|
/* relative path */
|
|
|
|
buf = strdup(xhp->metadir);
|
|
|
|
snprintf(xhp->metadir, sizeof(xhp->metadir),
|
|
|
|
"%s/%s", strcmp(xhp->rootdir, "/") ? xhp->rootdir : "", buf);
|
|
|
|
free(buf);
|
2011-06-04 20:38:44 +05:30
|
|
|
}
|
2014-02-25 21:12:52 +05:30
|
|
|
/* Set virtualpkgdir */
|
|
|
|
if (xhp->virtualpkgdir[0] == '\0') {
|
|
|
|
snprintf(xhp->virtualpkgdir, sizeof(xhp->virtualpkgdir),
|
|
|
|
"%s%s", strcmp(xhp->rootdir, "/") ? xhp->rootdir : "",
|
|
|
|
XBPS_VPKG_PATH);
|
|
|
|
} else if (xhp->virtualpkgdir[0] != '/') {
|
|
|
|
/* relative path */
|
|
|
|
buf = strdup(xhp->virtualpkgdir);
|
|
|
|
snprintf(xhp->virtualpkgdir, sizeof(xhp->virtualpkgdir),
|
|
|
|
"%s/%s", strcmp(xhp->rootdir, "/") ? xhp->rootdir : "", buf);
|
|
|
|
free(buf);
|
|
|
|
}
|
|
|
|
/* parse virtualpkgdir */
|
|
|
|
if ((rv = parse_vpkgdir(xhp)))
|
|
|
|
return rv;
|
2012-03-13 14:52:35 +05:30
|
|
|
|
2013-03-07 22:38:12 +05:30
|
|
|
xhp->target_arch = getenv("XBPS_TARGET_ARCH");
|
2014-01-09 16:11:25 +05:30
|
|
|
if ((native_arch = getenv("XBPS_ARCH")) != NULL) {
|
|
|
|
strlcpy(xhp->native_arch, native_arch, sizeof(xhp->native_arch));
|
|
|
|
} else {
|
|
|
|
uname(&un);
|
|
|
|
strlcpy(xhp->native_arch, un.machine, sizeof(xhp->native_arch));
|
|
|
|
}
|
2013-03-07 22:38:12 +05:30
|
|
|
assert(xhp->native_arch);
|
2012-06-15 19:03:11 +05:30
|
|
|
|
2014-02-25 21:12:52 +05:30
|
|
|
xbps_fetch_set_cache_connection(XBPS_FETCH_CACHECONN, XBPS_FETCH_CACHECONN_HOST);
|
|
|
|
|
|
|
|
xbps_dbg_printf(xhp, "rootdir=%s\n", xhp->rootdir);
|
|
|
|
xbps_dbg_printf(xhp, "metadir=%s\n", xhp->metadir);
|
|
|
|
xbps_dbg_printf(xhp, "cachedir=%s\n", xhp->cachedir);
|
|
|
|
xbps_dbg_printf(xhp, "virtualpkgdir=%s\n", xhp->virtualpkgdir);
|
|
|
|
xbps_dbg_printf(xhp, "syslog=%s\n", xhp->syslog ? "true" : "false");
|
2013-03-07 22:38:12 +05:30
|
|
|
xbps_dbg_printf(xhp, "Architecture: %s\n", xhp->native_arch);
|
|
|
|
xbps_dbg_printf(xhp, "Target Architecture: %s\n", xhp->target_arch);
|
2011-10-17 17:54:30 +05:30
|
|
|
|
2013-09-18 20:15:05 +05:30
|
|
|
if (xhp->flags & XBPS_FLAG_DEBUG) {
|
|
|
|
for (unsigned int i = 0; i < xbps_array_count(xhp->repositories); i++) {
|
|
|
|
xbps_array_get_cstring_nocopy(xhp->repositories, i, &repodir);
|
|
|
|
xbps_dbg_printf(xhp, "Repository[%u]=%s\n", i, repodir);
|
|
|
|
}
|
|
|
|
}
|
2011-06-04 17:07:53 +05:30
|
|
|
return 0;
|
2010-11-19 18:10:13 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2012-06-14 11:52:11 +05:30
|
|
|
xbps_end(struct xbps_handle *xhp)
|
2010-11-19 18:10:13 +05:30
|
|
|
{
|
2012-09-24 14:20:23 +05:30
|
|
|
assert(xhp);
|
|
|
|
|
2012-01-20 15:40:52 +05:30
|
|
|
xbps_pkgdb_release(xhp);
|
2013-10-09 13:43:07 +05:30
|
|
|
xbps_fetch_unset_cache_connection();
|
2011-02-21 18:08:44 +05:30
|
|
|
}
|
|
|
|
|
2011-01-22 17:10:19 +05:30
|
|
|
static void
|
|
|
|
common_printf(FILE *f, const char *msg, const char *fmt, va_list ap)
|
|
|
|
{
|
|
|
|
if (msg != NULL)
|
|
|
|
fprintf(f, "%s", msg);
|
|
|
|
|
|
|
|
vfprintf(f, fmt, ap);
|
|
|
|
}
|
|
|
|
|
2010-11-19 18:10:13 +05:30
|
|
|
void
|
2012-06-14 11:52:11 +05:30
|
|
|
xbps_dbg_printf_append(struct xbps_handle *xhp, const char *fmt, ...)
|
2010-11-19 18:10:13 +05:30
|
|
|
{
|
|
|
|
va_list ap;
|
|
|
|
|
2012-06-14 11:52:11 +05:30
|
|
|
if ((xhp->flags & XBPS_FLAG_DEBUG) == 0)
|
2010-11-19 18:10:13 +05:30
|
|
|
return;
|
|
|
|
|
|
|
|
va_start(ap, fmt);
|
2011-01-22 17:10:19 +05:30
|
|
|
common_printf(stderr, NULL, fmt, ap);
|
2010-11-19 18:10:13 +05:30
|
|
|
va_end(ap);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2012-06-14 11:52:11 +05:30
|
|
|
xbps_dbg_printf(struct xbps_handle *xhp, const char *fmt, ...)
|
2010-11-19 18:10:13 +05:30
|
|
|
{
|
|
|
|
va_list ap;
|
|
|
|
|
2012-06-14 11:52:11 +05:30
|
|
|
if ((xhp->flags & XBPS_FLAG_DEBUG) == 0)
|
2010-11-19 18:10:13 +05:30
|
|
|
return;
|
|
|
|
|
|
|
|
va_start(ap, fmt);
|
2011-01-22 17:10:19 +05:30
|
|
|
common_printf(stderr, "[DEBUG] ", fmt, ap);
|
2010-11-19 18:10:13 +05:30
|
|
|
va_end(ap);
|
|
|
|
}
|
2011-01-21 21:46:58 +05:30
|
|
|
|
|
|
|
void
|
|
|
|
xbps_error_printf(const char *fmt, ...)
|
|
|
|
{
|
|
|
|
va_list ap;
|
|
|
|
|
|
|
|
va_start(ap, fmt);
|
2011-01-22 17:10:19 +05:30
|
|
|
common_printf(stderr, "ERROR: ", fmt, ap);
|
|
|
|
va_end(ap);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
xbps_warn_printf(const char *fmt, ...)
|
|
|
|
{
|
|
|
|
va_list ap;
|
|
|
|
|
|
|
|
va_start(ap, fmt);
|
|
|
|
common_printf(stderr, "WARNING: ", fmt, ap);
|
|
|
|
va_end(ap);
|
|
|
|
}
|