mirror of
https://github.com/moparisthebest/pacman
synced 2024-12-23 08:18:51 -05:00
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 <shiningxc@gmail.com>
This commit is contained in:
parent
14230869e6
commit
34e1413d75
@ -113,6 +113,26 @@ static int setlastupdate(const pmdb_t *db, time_t time)
|
|||||||
return(ret);
|
return(ret);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int checkdbdir(pmdb_t *db)
|
||||||
|
{
|
||||||
|
struct stat buf;
|
||||||
|
char *path = db->path;
|
||||||
|
|
||||||
|
if(stat(path, &buf) != 0) {
|
||||||
|
_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, -1);
|
||||||
|
}
|
||||||
|
} else if(!S_ISDIR(buf.st_mode)) {
|
||||||
|
_alpm_log(PM_LOG_WARNING, "removing bogus database: %s\n", path);
|
||||||
|
if(unlink(path) != 0 || _alpm_makepath(path) != 0) {
|
||||||
|
RET_ERR(PM_ERR_SYSTEM, -1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return(0);
|
||||||
|
}
|
||||||
|
|
||||||
/** Update a package database
|
/** Update a package database
|
||||||
* @param force if true, then forces the update, otherwise update only in case
|
* @param force if true, then forces the update, otherwise update only in case
|
||||||
* the database isn't up to date
|
* the database isn't up to date
|
||||||
@ -122,7 +142,6 @@ static int setlastupdate(const pmdb_t *db, time_t time)
|
|||||||
*/
|
*/
|
||||||
int SYMEXPORT alpm_db_update(int force, pmdb_t *db)
|
int SYMEXPORT alpm_db_update(int force, pmdb_t *db)
|
||||||
{
|
{
|
||||||
alpm_list_t *lp;
|
|
||||||
char *dbfile, *dbfilepath;
|
char *dbfile, *dbfilepath;
|
||||||
time_t newmtime = 0, lastupdate = 0;
|
time_t newmtime = 0, lastupdate = 0;
|
||||||
const char *dbpath;
|
const char *dbpath;
|
||||||
@ -176,15 +195,10 @@ int SYMEXPORT alpm_db_update(int force, pmdb_t *db)
|
|||||||
return(-1);
|
return(-1);
|
||||||
} else {
|
} else {
|
||||||
/* remove the old dir */
|
/* remove the old dir */
|
||||||
_alpm_log(PM_LOG_DEBUG, "flushing database %s\n", db->path);
|
if(_alpm_rmrf(db->path) != 0) {
|
||||||
for(lp = _alpm_db_get_pkgcache(db); lp; lp = lp->next) {
|
_alpm_log(PM_LOG_ERROR, _("could not remove database %s\n"), db->treename);
|
||||||
pmpkg_t *pkg = lp->data;
|
|
||||||
if(pkg && _alpm_db_remove(db, pkg) == -1) {
|
|
||||||
_alpm_log(PM_LOG_ERROR, _("could not remove database entry %s%s\n"),
|
|
||||||
db->treename, pkg->name);
|
|
||||||
RET_ERR(PM_ERR_DB_REMOVE, -1);
|
RET_ERR(PM_ERR_DB_REMOVE, -1);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
/* Cache needs to be rebuilt */
|
/* Cache needs to be rebuilt */
|
||||||
_alpm_db_free_pkgcache(db);
|
_alpm_db_free_pkgcache(db);
|
||||||
@ -195,6 +209,7 @@ int SYMEXPORT alpm_db_update(int force, pmdb_t *db)
|
|||||||
sprintf(dbfilepath, "%s%s" DBEXT, dbpath, db->treename);
|
sprintf(dbfilepath, "%s%s" DBEXT, dbpath, db->treename);
|
||||||
|
|
||||||
/* uncompress the sync database */
|
/* uncompress the sync database */
|
||||||
|
checkdbdir(db);
|
||||||
ret = _alpm_unpack(dbfilepath, db->path, NULL);
|
ret = _alpm_unpack(dbfilepath, db->path, NULL);
|
||||||
if(ret) {
|
if(ret) {
|
||||||
free(dbfilepath);
|
free(dbfilepath);
|
||||||
@ -268,7 +283,7 @@ int _alpm_db_populate(pmdb_t *db)
|
|||||||
|
|
||||||
dbdir = opendir(db->path);
|
dbdir = opendir(db->path);
|
||||||
if(dbdir == NULL) {
|
if(dbdir == NULL) {
|
||||||
RET_ERR(PM_ERR_DB_OPEN, -1);
|
return(0);
|
||||||
}
|
}
|
||||||
while((ent = readdir(dbdir)) != NULL) {
|
while((ent = readdir(dbdir)) != NULL) {
|
||||||
const char *name = ent->d_name;
|
const char *name = ent->d_name;
|
||||||
@ -634,12 +649,16 @@ int _alpm_db_prepare(pmdb_t *db, pmpkg_t *info)
|
|||||||
int retval = 0;
|
int retval = 0;
|
||||||
char *pkgpath = NULL;
|
char *pkgpath = NULL;
|
||||||
|
|
||||||
oldmask = umask(0000);
|
if(checkdbdir(db) != 0) {
|
||||||
|
return(-1);
|
||||||
|
}
|
||||||
|
|
||||||
|
oldmask = umask(0000);
|
||||||
pkgpath = get_pkgpath(db, info);
|
pkgpath = get_pkgpath(db, info);
|
||||||
|
|
||||||
if((retval = mkdir(pkgpath, 0755)) != 0) {
|
if((retval = mkdir(pkgpath, 0755)) != 0) {
|
||||||
_alpm_log(PM_LOG_ERROR, _("could not create directory %s: %s\n"), pkgpath, strerror(errno));
|
_alpm_log(PM_LOG_ERROR, _("could not create directory %s: %s\n"),
|
||||||
|
pkgpath, strerror(errno));
|
||||||
}
|
}
|
||||||
|
|
||||||
free(pkgpath);
|
free(pkgpath);
|
||||||
|
@ -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)
|
pmdb_t *_alpm_db_register_local(void)
|
||||||
{
|
{
|
||||||
struct stat buf;
|
|
||||||
pmdb_t *db;
|
pmdb_t *db;
|
||||||
const char *dbpath;
|
const char *dbpath;
|
||||||
char path[PATH_MAX];
|
|
||||||
|
|
||||||
ALPM_LOG_FUNC;
|
ALPM_LOG_FUNC;
|
||||||
|
|
||||||
@ -442,21 +440,11 @@ pmdb_t *_alpm_db_register_local(void)
|
|||||||
|
|
||||||
_alpm_log(PM_LOG_DEBUG, "registering local database\n");
|
_alpm_log(PM_LOG_DEBUG, "registering local database\n");
|
||||||
|
|
||||||
/* make sure the database directory exists */
|
|
||||||
dbpath = alpm_option_get_dbpath();
|
dbpath = alpm_option_get_dbpath();
|
||||||
if(!dbpath) {
|
if(!dbpath) {
|
||||||
_alpm_log(PM_LOG_ERROR, _("database path is undefined\n"));
|
_alpm_log(PM_LOG_ERROR, _("database path is undefined\n"));
|
||||||
RET_ERR(PM_ERR_DB_OPEN, NULL);
|
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");
|
db = _alpm_db_new(dbpath, "local");
|
||||||
if(db == NULL) {
|
if(db == NULL) {
|
||||||
@ -469,7 +457,6 @@ pmdb_t *_alpm_db_register_local(void)
|
|||||||
|
|
||||||
pmdb_t *_alpm_db_register_sync(const char *treename)
|
pmdb_t *_alpm_db_register_sync(const char *treename)
|
||||||
{
|
{
|
||||||
struct stat buf;
|
|
||||||
pmdb_t *db;
|
pmdb_t *db;
|
||||||
const char *dbpath;
|
const char *dbpath;
|
||||||
char path[PATH_MAX];
|
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);
|
_alpm_log(PM_LOG_DEBUG, "registering sync database '%s'\n", treename);
|
||||||
|
|
||||||
/* make sure the database directory exists */
|
|
||||||
dbpath = alpm_option_get_dbpath();
|
dbpath = alpm_option_get_dbpath();
|
||||||
if(!dbpath) {
|
if(!dbpath) {
|
||||||
_alpm_log(PM_LOG_ERROR, _("database path is undefined\n"));
|
_alpm_log(PM_LOG_ERROR, _("database path is undefined\n"));
|
||||||
RET_ERR(PM_ERR_DB_OPEN, NULL);
|
RET_ERR(PM_ERR_DB_OPEN, NULL);
|
||||||
}
|
}
|
||||||
/* all sync DBs now reside in the sync/ subdir of the dbpath */
|
/* 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);
|
snprintf(path, PATH_MAX, "%ssync/", dbpath);
|
||||||
|
|
||||||
db = _alpm_db_new(path, treename);
|
db = _alpm_db_new(path, treename);
|
||||||
|
Loading…
Reference in New Issue
Block a user