diff options
author | Dan McGee <dan@archlinux.org> | 2007-06-04 21:39:00 +0200 |
---|---|---|
committer | Dan McGee <dan@archlinux.org> | 2007-06-05 05:10:49 +0200 |
commit | 466b79bf8f9a9b3f37a1a754b40320df9f2f1b4e (patch) | |
tree | e43d592d812a8e631dc6155aa5419a78b4d26622 | |
parent | 358cc5804a2df873180e6d9ef2420ab3247f8437 (diff) | |
download | pacman-466b79bf8f9a9b3f37a1a754b40320df9f2f1b4e.tar.gz pacman-466b79bf8f9a9b3f37a1a754b40320df9f2f1b4e.tar.xz |
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>
-rw-r--r-- | lib/libalpm/alpm.c | 2 | ||||
-rw-r--r-- | lib/libalpm/alpm.h | 2 | ||||
-rw-r--r-- | lib/libalpm/db.c | 4 | ||||
-rw-r--r-- | src/pacman/pacman.c | 42 |
4 files changed, 31 insertions, 19 deletions
diff --git a/lib/libalpm/alpm.c b/lib/libalpm/alpm.c index f2a6270f..72b01a61 100644 --- a/lib/libalpm/alpm.c +++ b/lib/libalpm/alpm.c @@ -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; diff --git a/lib/libalpm/alpm.h b/lib/libalpm/alpm.h index 131ead3b..e2814281 100644 --- a/lib/libalpm/alpm.h +++ b/lib/libalpm/alpm.h @@ -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); diff --git a/lib/libalpm/db.c b/lib/libalpm/db.c index e5489973..16b09a47 100644 --- a/lib/libalpm/db.c +++ b/lib/libalpm/db.c @@ -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"), diff --git a/src/pacman/pacman.c b/src/pacman/pacman.c index fdd399fd..d09f9609 100644 --- a/src/pacman/pacman.c +++ b/src/pacman/pacman.c @@ -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,21 +647,19 @@ 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) { - /* let's attempt a replacement for the current repo */ - char *server = strreplace(ptr, "$repo", section); - - if(alpm_db_setserver(db, server) != 0) { - /* pm_errno is set by alpm_db_setserver */ - return(1); - } + } 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); - free(server); - } else { - printf("PM_ERR_CONF_BAD_SYNTAX\n"); + if(alpm_db_setserver(db, server) != 0) { + /* pm_errno is set by alpm_db_setserver */ 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) { - /* 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)); } /** |