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:
parent
358cc5804a
commit
466b79bf8f
4 changed files with 31 additions and 19 deletions
|
@ -128,7 +128,7 @@ int SYMEXPORT alpm_release()
|
|||
* @param treename the name of the repository
|
||||
* @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;
|
||||
|
||||
|
|
|
@ -148,7 +148,7 @@ alpm_list_t *alpm_option_get_syncdbs();
|
|||
* Databases
|
||||
*/
|
||||
|
||||
pmdb_t *alpm_db_register(char *treename);
|
||||
pmdb_t *alpm_db_register(const char *treename);
|
||||
int alpm_db_unregister(pmdb_t *db);
|
||||
|
||||
const char *alpm_db_get_name(pmdb_t *db);
|
||||
|
|
|
@ -186,6 +186,10 @@ pmdb_t *_alpm_db_register(const char *treename)
|
|||
|
||||
/* make sure the database directory exists */
|
||||
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);
|
||||
if(stat(path, &buf) != 0 || !S_ISDIR(buf.st_mode)) {
|
||||
_alpm_log(PM_LOG_DEBUG, _("database directory '%s' does not exist, creating it"),
|
||||
|
|
|
@ -458,7 +458,8 @@ static int parseargs(int argc, char *argv[])
|
|||
|
||||
/* The real parseconfig. Called with a null section argument by the publicly
|
||||
* 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;
|
||||
char line[PATH_MAX+1];
|
||||
|
@ -471,9 +472,14 @@ static int _parseconfig(const char *file, const char *givensection)
|
|||
return(1);
|
||||
}
|
||||
|
||||
/* if we are passed a section, use it as our starting point */
|
||||
if(givensection != NULL) {
|
||||
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)) {
|
||||
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(strcmp(section, "options") != 0) {
|
||||
alpm_db_register(section);
|
||||
db = alpm_db_register(section);
|
||||
}
|
||||
} else {
|
||||
/* directive */
|
||||
|
@ -554,8 +560,12 @@ static int _parseconfig(const char *file, const char *givensection)
|
|||
} else {
|
||||
/* directives with settings */
|
||||
if(strcmp(key, "Include") == 0 || strcmp(upperkey, "INCLUDE") == 0) {
|
||||
int ret;
|
||||
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) {
|
||||
if(strcmp(key, "NoUpgrade") == 0 || strcmp(upperkey, "NOUPGRADE") == 0) {
|
||||
/* TODO functionalize this */
|
||||
|
@ -637,8 +647,7 @@ static int _parseconfig(const char *file, const char *givensection)
|
|||
printf("PM_ERR_CONF_BAD_SYNTAX\n");
|
||||
return(1);
|
||||
}
|
||||
} else {
|
||||
if(strcmp(key, "Server") == 0 || strcmp(upperkey, "SERVER") == 0) {
|
||||
} else if(strcmp(key, "Server") == 0 || strcmp(upperkey, "SERVER") == 0) {
|
||||
/* let's attempt a replacement for the current repo */
|
||||
char *server = strreplace(ptr, "$repo", section);
|
||||
|
||||
|
@ -655,7 +664,6 @@ static int _parseconfig(const char *file, const char *givensection)
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
fclose(fp);
|
||||
|
||||
return(0);
|
||||
|
@ -667,8 +675,8 @@ static int _parseconfig(const char *file, const char *givensection)
|
|||
*/
|
||||
int parseconfig(const char *file)
|
||||
{
|
||||
/* call the real parseconfig function with a null section argument */
|
||||
return(_parseconfig(file, NULL));
|
||||
/* call the real parseconfig function with a null section & db argument */
|
||||
return(_parseconfig(file, NULL, NULL));
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Add table
Reference in a new issue