[pacman-dev] [PATCH] db.c: require unique database names
Allowing multiple databases with the same name causes conflicts as they both point to the same database file but may use different servers, usages, or siglevels. Signed-off-by: Andrew Gregory <andrew.gregory.8@gmail.com> --- doc/pacman.conf.5.txt | 9 +++++---- lib/libalpm/db.c | 13 +++++++++++++ 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/doc/pacman.conf.5.txt b/doc/pacman.conf.5.txt index 8cd2d0e..9c3dffe 100644 --- a/doc/pacman.conf.5.txt +++ b/doc/pacman.conf.5.txt @@ -202,10 +202,11 @@ Repository Sections ------------------- Each repository section defines a section name and at least one location where the packages can be found. The section name is defined by the string within -square brackets (the two above are 'current' and 'custom'). Locations are -defined with the 'Server' directive and follow a URL naming structure. If you -want to use a local directory, you can specify the full path with a ``file://'' -prefix, as shown above. +square brackets (the two above are 'core' and 'custom'). Repository names +must be unique and the name 'local' is reserved for the database of installed +packages. Locations are defined with the 'Server' directive and follow a URL +naming structure. If you want to use a local directory, you can specify the +full path with a ``file://'' prefix, as shown above. A common way to define DB locations utilizes the 'Include' directive. For each repository defined in the configuration file, a single 'Include' directive can diff --git a/lib/libalpm/db.c b/lib/libalpm/db.c index 528b04b..2069a7b 100644 --- a/lib/libalpm/db.c +++ b/lib/libalpm/db.c @@ -46,6 +46,8 @@ alpm_db_t SYMEXPORT *alpm_register_syncdb(alpm_handle_t *handle, const char *treename, alpm_siglevel_t level) { + alpm_list_t *i; + /* Sanity checks */ CHECK_HANDLE(handle, return NULL); ASSERT(treename != NULL && strlen(treename) != 0, @@ -53,6 +55,17 @@ alpm_db_t SYMEXPORT *alpm_register_syncdb(alpm_handle_t *handle, /* Do not register a database if a transaction is on-going */ ASSERT(handle->trans == NULL, RET_ERR(handle, ALPM_ERR_TRANS_NOT_NULL, NULL)); + /* ensure database name is unique */ + if(strcmp(treename, "local") == 0) { + RET_ERR(handle, ALPM_ERR_DB_NOT_NULL, NULL); + } + for(i = handle->dbs_sync; i; i = i->next) { + alpm_db_t *d = i->data; + if(strcmp(treename, d->treename) == 0) { + RET_ERR(handle, ALPM_ERR_DB_NOT_NULL, NULL); + } + } + return _alpm_db_register_sync(handle, treename, level); } -- 1.8.4.2
On 01/12/13 11:45, Andrew Gregory wrote:
Allowing multiple databases with the same name causes conflicts as they both point to the same database file but may use different servers, usages, or siglevels.
Signed-off-by: Andrew Gregory <andrew.gregory.8@gmail.com>
Ack.
participants (2)
-
Allan McRae
-
Andrew Gregory