Fix up outstanding parseconfig issues

The db variable was left unset when calling alpm_db_register, leading
to a failure to ever register a sync db. Also added a check to ensure
DBPath was set when trying to register a database.

Signed-off-by: Dan McGee <dan@archlinux.org>
This commit is contained in:
Dan McGee 2007-06-04 15:39:00 -04:00
parent 358cc5804a
commit 466b79bf8f
4 changed files with 31 additions and 19 deletions

View file

@ -128,7 +128,7 @@ int SYMEXPORT alpm_release()
* @param treename the name of the repository * @param treename the name of the repository
* @return a pmdb_t* on success (the value), NULL on error * @return a pmdb_t* on success (the value), NULL on error
*/ */
pmdb_t SYMEXPORT *alpm_db_register(char *treename) pmdb_t SYMEXPORT *alpm_db_register(const char *treename)
{ {
ALPM_LOG_FUNC; ALPM_LOG_FUNC;

View file

@ -148,7 +148,7 @@ alpm_list_t *alpm_option_get_syncdbs();
* Databases * Databases
*/ */
pmdb_t *alpm_db_register(char *treename); pmdb_t *alpm_db_register(const char *treename);
int alpm_db_unregister(pmdb_t *db); int alpm_db_unregister(pmdb_t *db);
const char *alpm_db_get_name(pmdb_t *db); const char *alpm_db_get_name(pmdb_t *db);

View file

@ -186,6 +186,10 @@ pmdb_t *_alpm_db_register(const char *treename)
/* make sure the database directory exists */ /* make sure the database directory exists */
dbpath = alpm_option_get_dbpath(); dbpath = alpm_option_get_dbpath();
if(!dbpath) {
_alpm_log(PM_LOG_WARNING, _("database path is undefined"));
RET_ERR(PM_ERR_DB_OPEN, NULL);
}
snprintf(path, PATH_MAX, "%s%s", dbpath, treename); snprintf(path, PATH_MAX, "%s%s", dbpath, treename);
if(stat(path, &buf) != 0 || !S_ISDIR(buf.st_mode)) { if(stat(path, &buf) != 0 || !S_ISDIR(buf.st_mode)) {
_alpm_log(PM_LOG_DEBUG, _("database directory '%s' does not exist, creating it"), _alpm_log(PM_LOG_DEBUG, _("database directory '%s' does not exist, creating it"),

View file

@ -458,7 +458,8 @@ static int parseargs(int argc, char *argv[])
/* The real parseconfig. Called with a null section argument by the publicly /* The real parseconfig. Called with a null section argument by the publicly
* visible parseconfig so we can recall from within ourself on an include */ * visible parseconfig so we can recall from within ourself on an include */
static int _parseconfig(const char *file, const char *givensection) static int _parseconfig(const char *file, const char *givensection,
pmdb_t * const givendb)
{ {
FILE *fp = NULL; FILE *fp = NULL;
char line[PATH_MAX+1]; char line[PATH_MAX+1];
@ -471,9 +472,14 @@ static int _parseconfig(const char *file, const char *givensection)
return(1); return(1);
} }
/* if we are passed a section, use it as our starting point */
if(givensection != NULL) { if(givensection != NULL) {
section = strdup(givensection); section = strdup(givensection);
} }
/* if we are passed a db, use it as our starting point */
if(givendb != NULL) {
db = givendb;
}
while(fgets(line, PATH_MAX, fp)) { while(fgets(line, PATH_MAX, fp)) {
linenum++; linenum++;
@ -507,7 +513,7 @@ static int _parseconfig(const char *file, const char *givensection)
} }
/* if we are not looking at the options section, register a db */ /* if we are not looking at the options section, register a db */
if(strcmp(section, "options") != 0) { if(strcmp(section, "options") != 0) {
alpm_db_register(section); db = alpm_db_register(section);
} }
} else { } else {
/* directive */ /* directive */
@ -554,8 +560,12 @@ static int _parseconfig(const char *file, const char *givensection)
} else { } else {
/* directives with settings */ /* directives with settings */
if(strcmp(key, "Include") == 0 || strcmp(upperkey, "INCLUDE") == 0) { if(strcmp(key, "Include") == 0 || strcmp(upperkey, "INCLUDE") == 0) {
int ret;
printf(_("config: including %s\n"), ptr); printf(_("config: including %s\n"), ptr);
_parseconfig(ptr, section); ret = _parseconfig(ptr, section, db);
if(ret != 0) {
return(ret);
}
} else if(strcmp(section, "options") == 0) { } else if(strcmp(section, "options") == 0) {
if(strcmp(key, "NoUpgrade") == 0 || strcmp(upperkey, "NOUPGRADE") == 0) { if(strcmp(key, "NoUpgrade") == 0 || strcmp(upperkey, "NOUPGRADE") == 0) {
/* TODO functionalize this */ /* TODO functionalize this */
@ -637,21 +647,19 @@ static int _parseconfig(const char *file, const char *givensection)
printf("PM_ERR_CONF_BAD_SYNTAX\n"); printf("PM_ERR_CONF_BAD_SYNTAX\n");
return(1); return(1);
} }
} else { } else if(strcmp(key, "Server") == 0 || strcmp(upperkey, "SERVER") == 0) {
if(strcmp(key, "Server") == 0 || strcmp(upperkey, "SERVER") == 0) { /* let's attempt a replacement for the current repo */
/* let's attempt a replacement for the current repo */ char *server = strreplace(ptr, "$repo", section);
char *server = strreplace(ptr, "$repo", section);
if(alpm_db_setserver(db, server) != 0) { if(alpm_db_setserver(db, server) != 0) {
/* pm_errno is set by alpm_db_setserver */ /* pm_errno is set by alpm_db_setserver */
return(1);
}
free(server);
} else {
printf("PM_ERR_CONF_BAD_SYNTAX\n");
return(1); return(1);
} }
free(server);
} else {
printf("PM_ERR_CONF_BAD_SYNTAX\n");
return(1);
} }
} }
} }
@ -667,8 +675,8 @@ static int _parseconfig(const char *file, const char *givensection)
*/ */
int parseconfig(const char *file) int parseconfig(const char *file)
{ {
/* call the real parseconfig function with a null section argument */ /* call the real parseconfig function with a null section & db argument */
return(_parseconfig(file, NULL)); return(_parseconfig(file, NULL, NULL));
} }
/** /**