From 34e1413d756269dcd71a32dd5d2dbb263a943051 Mon Sep 17 00:00:00 2001 From: Xavier Chantry Date: Mon, 19 Jan 2009 22:54:00 +0100 Subject: Delay the creation of local and sync db dir. We don't need to create the directories when local or sync dbs are registered. For example, if a sync db does not exist, we cannot even do "pacman -Q" as an user. Instead, we can create the local db if needed during the db_prepare operation, and sync dbs on db_update. Also remove some more useless abstractions in db_update and switch to a much more efficient way to remove a sync db : rm -rf. Signed-off-by: Xavier Chantry --- lib/libalpm/db.c | 26 -------------------------- 1 file changed, 26 deletions(-) (limited to 'lib/libalpm/db.c') diff --git a/lib/libalpm/db.c b/lib/libalpm/db.c index a639b1fb..561967ce 100644 --- a/lib/libalpm/db.c +++ b/lib/libalpm/db.c @@ -428,10 +428,8 @@ alpm_list_t *_alpm_db_search(pmdb_t *db, const alpm_list_t *needles) pmdb_t *_alpm_db_register_local(void) { - struct stat buf; pmdb_t *db; const char *dbpath; - char path[PATH_MAX]; ALPM_LOG_FUNC; @@ -442,21 +440,11 @@ pmdb_t *_alpm_db_register_local(void) _alpm_log(PM_LOG_DEBUG, "registering local database\n"); - /* make sure the database directory exists */ dbpath = alpm_option_get_dbpath(); if(!dbpath) { _alpm_log(PM_LOG_ERROR, _("database path is undefined\n")); RET_ERR(PM_ERR_DB_OPEN, NULL); } - 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) { @@ -469,7 +457,6 @@ pmdb_t *_alpm_db_register_local(void) pmdb_t *_alpm_db_register_sync(const char *treename) { - struct stat buf; pmdb_t *db; const char *dbpath; char path[PATH_MAX]; @@ -487,25 +474,12 @@ pmdb_t *_alpm_db_register_sync(const char *treename) _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_ERROR, _("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 */ - 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); - } - } - - /* Ensure the db gets the real path. */ - path[0] = '\0'; snprintf(path, PATH_MAX, "%ssync/", dbpath); db = _alpm_db_new(path, treename); -- cgit v1.2.3-24-g4f1b