Implemented GH #39

The system repository directory set to <prefix>/share/xbps/repo.d contains
system repository configuration files (.conf) that can be overrided by the admin
in <sysconfdir>/xbps/repo.d bearing the same file name.
This commit is contained in:
Juan RP
2014-05-30 11:48:10 +02:00
parent b9e44009d9
commit 23fef46e9e
4 changed files with 107 additions and 4 deletions

View File

@@ -283,7 +283,7 @@ parse_vpkgdir(struct xbps_handle *xhp)
if ((dirp = opendir(xhp->virtualpkgdir)) == NULL)
return 0;
xbps_dbg_printf(xhp, "Parsing virtualpkg directory: %s\n", xhp->virtualpkgdir);
xbps_dbg_printf(xhp, "Processing virtualpkg directory: %s\n", xhp->virtualpkgdir);
while ((dp = readdir(dirp)) != NULL) {
if ((strcmp(dp->d_name, "..") == 0) ||
@@ -307,6 +307,83 @@ parse_vpkgdir(struct xbps_handle *xhp)
return rv;
}
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;
}
int
xbps_init(struct xbps_handle *xhp)
{
@@ -320,6 +397,10 @@ xbps_init(struct xbps_handle *xhp)
if (xhp->conffile == NULL)
xhp->conffile = XBPS_CONF_DEF;
/* parse repository configuration files */
if ((rv = parse_repodir(xhp)) != 0) {
xbps_dbg_printf(xhp, "failed to parse repo.d files: %s\n", strerror(rv));
}
/* parse configuration file */
if ((rv = parse_file(xhp, xhp->conffile, false, false)) != 0) {
xbps_dbg_printf(xhp, "failed to read configuration file %s: %s\n",