mirror of
https://github.com/moparisthebest/pacman
synced 2024-12-23 00:08:50 -05:00
separate local from sync dbs on filesystem
Introduce two new methods into the API - alpm_db_register_sync and alpm_db_register_local, which replace the functionality of alpm_db_register. db_register_local always returns the local DB, and db_register_sync will always try to register a sync DB. This conceptually separates the local DB from sync DBs in the code. Also updated the pacman frontend to use the new functions. In addition, this changes the location of all sync DBs in the filesystem from $DBPATH/$REPO to $DBPATH/sync/$REPO, This removes the silly limitation that a sync DB couldn't be named 'local', along with structurally separating sync DBs and the local DB in the filesystem. Signed-off-by: Travis Willard <travis@archlinux.org> Signed-off-by: Dan McGee <dan@archlinux.org>
This commit is contained in:
parent
26441cf65c
commit
b6f89f03af
@ -31,6 +31,8 @@ extern "C" {
|
|||||||
#include <time.h> /* for time_t */
|
#include <time.h> /* for time_t */
|
||||||
#include <stdarg.h> /* for va_list */
|
#include <stdarg.h> /* for va_list */
|
||||||
|
|
||||||
|
#define DEPRECATED __attribute__((deprecated))
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Arch Linux Package Management library
|
* Arch Linux Package Management library
|
||||||
*/
|
*/
|
||||||
@ -143,7 +145,9 @@ alpm_list_t *alpm_option_get_syncdbs();
|
|||||||
* Databases
|
* Databases
|
||||||
*/
|
*/
|
||||||
|
|
||||||
pmdb_t *alpm_db_register(const char *treename);
|
/* Preferred interfaces db_register_local and db_register_sync */
|
||||||
|
pmdb_t *alpm_db_register_local(void);
|
||||||
|
pmdb_t *alpm_db_register_sync(const char *treename);
|
||||||
int alpm_db_unregister(pmdb_t *db);
|
int alpm_db_unregister(pmdb_t *db);
|
||||||
int alpm_db_unregister_all(void);
|
int alpm_db_unregister_all(void);
|
||||||
|
|
||||||
|
105
lib/libalpm/db.c
105
lib/libalpm/db.c
@ -53,11 +53,11 @@
|
|||||||
* @{
|
* @{
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/** Register a package database
|
/** Register a sync database of packages.
|
||||||
* @param treename the name of the repository
|
* @param treename the name of the sync 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(const char *treename)
|
pmdb_t SYMEXPORT *alpm_db_register_sync(const char *treename)
|
||||||
{
|
{
|
||||||
ALPM_LOG_FUNC;
|
ALPM_LOG_FUNC;
|
||||||
|
|
||||||
@ -67,7 +67,22 @@ pmdb_t SYMEXPORT *alpm_db_register(const char *treename)
|
|||||||
/* Do not register a database if a transaction is on-going */
|
/* Do not register a database if a transaction is on-going */
|
||||||
ASSERT(handle->trans == NULL, RET_ERR(PM_ERR_TRANS_NOT_NULL, NULL));
|
ASSERT(handle->trans == NULL, RET_ERR(PM_ERR_TRANS_NOT_NULL, NULL));
|
||||||
|
|
||||||
return(_alpm_db_register(treename));
|
return(_alpm_db_register_sync(treename));
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Register the local package database.
|
||||||
|
* @return a pmdb_t* representing the local database, or NULL on error
|
||||||
|
*/
|
||||||
|
pmdb_t SYMEXPORT *alpm_db_register_local(void)
|
||||||
|
{
|
||||||
|
ALPM_LOG_FUNC;
|
||||||
|
|
||||||
|
/* Sanity checks */
|
||||||
|
ASSERT(handle != NULL, RET_ERR(PM_ERR_HANDLE_NULL, NULL));
|
||||||
|
/* Do not register a database if a transaction is on-going */
|
||||||
|
ASSERT(handle->trans == NULL, RET_ERR(PM_ERR_TRANS_NOT_NULL, NULL));
|
||||||
|
|
||||||
|
return(_alpm_db_register_local());
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Helper function for alpm_db_unregister{_all} */
|
/* Helper function for alpm_db_unregister{_all} */
|
||||||
@ -161,6 +176,7 @@ int SYMEXPORT alpm_db_unregister(pmdb_t *db)
|
|||||||
*/
|
*/
|
||||||
int SYMEXPORT alpm_db_setserver(pmdb_t *db, const char *url)
|
int SYMEXPORT alpm_db_setserver(pmdb_t *db, const char *url)
|
||||||
{
|
{
|
||||||
|
alpm_list_t *i;
|
||||||
int found = 0;
|
int found = 0;
|
||||||
|
|
||||||
ALPM_LOG_FUNC;
|
ALPM_LOG_FUNC;
|
||||||
@ -168,19 +184,12 @@ int SYMEXPORT alpm_db_setserver(pmdb_t *db, const char *url)
|
|||||||
/* Sanity checks */
|
/* Sanity checks */
|
||||||
ASSERT(db != NULL, RET_ERR(PM_ERR_DB_NULL, -1));
|
ASSERT(db != NULL, RET_ERR(PM_ERR_DB_NULL, -1));
|
||||||
|
|
||||||
if(strcmp(db->treename, "local") == 0) {
|
|
||||||
if(handle->db_local != NULL) {
|
|
||||||
found = 1;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
alpm_list_t *i;
|
|
||||||
for(i = handle->dbs_sync; i && !found; i = i->next) {
|
for(i = handle->dbs_sync; i && !found; i = i->next) {
|
||||||
pmdb_t *sdb = i->data;
|
pmdb_t *sdb = i->data;
|
||||||
if(strcmp(db->treename, sdb->treename) == 0) {
|
if(strcmp(db->treename, sdb->treename) == 0) {
|
||||||
found = 1;
|
found = 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
if(!found) {
|
if(!found) {
|
||||||
RET_ERR(PM_ERR_DB_NOT_FOUND, -1);
|
RET_ERR(PM_ERR_DB_NOT_FOUND, -1);
|
||||||
}
|
}
|
||||||
@ -690,7 +699,7 @@ alpm_list_t *_alpm_db_search(pmdb_t *db, const alpm_list_t *needles)
|
|||||||
return(ret);
|
return(ret);
|
||||||
}
|
}
|
||||||
|
|
||||||
pmdb_t *_alpm_db_register(const char *treename)
|
pmdb_t *_alpm_db_register_local(void)
|
||||||
{
|
{
|
||||||
struct stat buf;
|
struct stat buf;
|
||||||
pmdb_t *db;
|
pmdb_t *db;
|
||||||
@ -699,23 +708,12 @@ pmdb_t *_alpm_db_register(const char *treename)
|
|||||||
|
|
||||||
ALPM_LOG_FUNC;
|
ALPM_LOG_FUNC;
|
||||||
|
|
||||||
if(strcmp(treename, "local") == 0) {
|
|
||||||
if(handle->db_local != NULL) {
|
if(handle->db_local != NULL) {
|
||||||
_alpm_log(PM_LOG_WARNING, _("attempt to re-register the 'local' DB\n"));
|
_alpm_log(PM_LOG_WARNING, _("attempt to re-register the 'local' DB\n"));
|
||||||
RET_ERR(PM_ERR_DB_NOT_NULL, NULL);
|
RET_ERR(PM_ERR_DB_NOT_NULL, NULL);
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
alpm_list_t *i;
|
|
||||||
for(i = handle->dbs_sync; i; i = i->next) {
|
|
||||||
pmdb_t *sdb = i->data;
|
|
||||||
if(strcmp(treename, sdb->treename) == 0) {
|
|
||||||
_alpm_log(PM_LOG_DEBUG, "attempt to re-register the '%s' database, using existing\n", sdb->treename);
|
|
||||||
return sdb;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
_alpm_log(PM_LOG_DEBUG, "registering database '%s'\n", treename);
|
_alpm_log(PM_LOG_DEBUG, "registering local database\n");
|
||||||
|
|
||||||
/* make sure the database directory exists */
|
/* make sure the database directory exists */
|
||||||
dbpath = alpm_option_get_dbpath();
|
dbpath = alpm_option_get_dbpath();
|
||||||
@ -723,7 +721,59 @@ pmdb_t *_alpm_db_register(const char *treename)
|
|||||||
_alpm_log(PM_LOG_WARNING, _("database path is undefined\n"));
|
_alpm_log(PM_LOG_WARNING, _("database path is undefined\n"));
|
||||||
RET_ERR(PM_ERR_DB_OPEN, NULL);
|
RET_ERR(PM_ERR_DB_OPEN, NULL);
|
||||||
}
|
}
|
||||||
snprintf(path, PATH_MAX, "%s%s", dbpath, treename);
|
snprintf(path, PATH_MAX, "%slocal", dbpath);
|
||||||
|
/* TODO this is rediculous, we try to do this even if we can't */
|
||||||
|
if(stat(path, &buf) != 0 || !S_ISDIR(buf.st_mode)) {
|
||||||
|
_alpm_log(PM_LOG_DEBUG, "database dir '%s' does not exist, creating it\n",
|
||||||
|
path);
|
||||||
|
if(_alpm_makepath(path) != 0) {
|
||||||
|
RET_ERR(PM_ERR_SYSTEM, NULL);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
db = _alpm_db_new(dbpath, "local");
|
||||||
|
if(db == NULL) {
|
||||||
|
RET_ERR(PM_ERR_DB_CREATE, NULL);
|
||||||
|
}
|
||||||
|
|
||||||
|
_alpm_log(PM_LOG_DEBUG, "opening database '%s'\n", db->treename);
|
||||||
|
if(_alpm_db_open(db) == -1) {
|
||||||
|
_alpm_db_free(db);
|
||||||
|
RET_ERR(PM_ERR_DB_OPEN, NULL);
|
||||||
|
}
|
||||||
|
|
||||||
|
handle->db_local = db;
|
||||||
|
return(db);
|
||||||
|
}
|
||||||
|
|
||||||
|
pmdb_t *_alpm_db_register_sync(const char *treename)
|
||||||
|
{
|
||||||
|
struct stat buf;
|
||||||
|
pmdb_t *db;
|
||||||
|
const char *dbpath;
|
||||||
|
char path[PATH_MAX];
|
||||||
|
alpm_list_t *i;
|
||||||
|
|
||||||
|
ALPM_LOG_FUNC;
|
||||||
|
|
||||||
|
for(i = handle->dbs_sync; i; i = i->next) {
|
||||||
|
pmdb_t *sdb = i->data;
|
||||||
|
if(strcmp(treename, sdb->treename) == 0) {
|
||||||
|
_alpm_log(PM_LOG_DEBUG, "attempt to re-register the '%s' database, using existing\n", sdb->treename);
|
||||||
|
return sdb;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
_alpm_log(PM_LOG_DEBUG, "registering sync database '%s'\n", treename);
|
||||||
|
|
||||||
|
/* make sure the database directory exists */
|
||||||
|
dbpath = alpm_option_get_dbpath();
|
||||||
|
if(!dbpath) {
|
||||||
|
_alpm_log(PM_LOG_WARNING, _("database path is undefined\n"));
|
||||||
|
RET_ERR(PM_ERR_DB_OPEN, NULL);
|
||||||
|
}
|
||||||
|
/* all sync DBs now reside in the sync/ subdir of the dbpath */
|
||||||
|
snprintf(path, PATH_MAX, "%ssync/%s", dbpath, treename);
|
||||||
/* TODO this is rediculous, we try to do this even if we can't */
|
/* TODO this is rediculous, we try to do this even if we can't */
|
||||||
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 dir '%s' does not exist, creating it\n",
|
_alpm_log(PM_LOG_DEBUG, "database dir '%s' does not exist, creating it\n",
|
||||||
@ -744,12 +794,7 @@ pmdb_t *_alpm_db_register(const char *treename)
|
|||||||
RET_ERR(PM_ERR_DB_OPEN, NULL);
|
RET_ERR(PM_ERR_DB_OPEN, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(strcmp(treename, "local") == 0) {
|
|
||||||
handle->db_local = db;
|
|
||||||
} else {
|
|
||||||
handle->dbs_sync = alpm_list_add(handle->dbs_sync, db);
|
handle->dbs_sync = alpm_list_add(handle->dbs_sync, db);
|
||||||
}
|
|
||||||
|
|
||||||
return(db);
|
return(db);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -52,7 +52,8 @@ pmdb_t *_alpm_db_new(const char *dbpath, const char *treename);
|
|||||||
void _alpm_db_free(pmdb_t *db);
|
void _alpm_db_free(pmdb_t *db);
|
||||||
int _alpm_db_cmp(const void *db1, const void *db2);
|
int _alpm_db_cmp(const void *db1, const void *db2);
|
||||||
alpm_list_t *_alpm_db_search(pmdb_t *db, const alpm_list_t *needles);
|
alpm_list_t *_alpm_db_search(pmdb_t *db, const alpm_list_t *needles);
|
||||||
pmdb_t *_alpm_db_register(const char *treename);
|
pmdb_t *_alpm_db_register_local(void);
|
||||||
|
pmdb_t *_alpm_db_register_sync(const char *treename);
|
||||||
|
|
||||||
/* be.c, backend specific calls */
|
/* be.c, backend specific calls */
|
||||||
int _alpm_db_install(pmdb_t *db, const char *dbfile);
|
int _alpm_db_install(pmdb_t *db, const char *dbfile);
|
||||||
|
@ -495,15 +495,9 @@ static int _parseconfig(const char *file, const char *givensection,
|
|||||||
file, linenum);
|
file, linenum);
|
||||||
return(1);
|
return(1);
|
||||||
}
|
}
|
||||||
/* a section/database named local is not allowed */
|
|
||||||
if(!strcmp(section, "local")) {
|
|
||||||
pm_printf(PM_LOG_ERROR, _("config file %s, line %d: 'local' cannot be used as section name.\n"),
|
|
||||||
file, linenum);
|
|
||||||
return(1);
|
|
||||||
}
|
|
||||||
/* 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) {
|
||||||
db = alpm_db_register(section);
|
db = alpm_db_register_sync(section);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
/* directive */
|
/* directive */
|
||||||
@ -815,7 +809,7 @@ int main(int argc, char *argv[])
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Opening local database */
|
/* Opening local database */
|
||||||
db_local = alpm_db_register("local");
|
db_local = alpm_db_register_local();
|
||||||
if(db_local == NULL) {
|
if(db_local == NULL) {
|
||||||
pm_printf(PM_LOG_ERROR, _("could not register 'local' database (%s)\n"),
|
pm_printf(PM_LOG_ERROR, _("could not register 'local' database (%s)\n"),
|
||||||
alpm_strerror(pm_errno));
|
alpm_strerror(pm_errno));
|
||||||
|
Loading…
Reference in New Issue
Block a user