index : pacman | |
Archlinux32 fork of pacman | gitolite user |
summaryrefslogtreecommitdiff |
-rw-r--r-- | lib/libalpm/be_files.c | 83 |
diff --git a/lib/libalpm/be_files.c b/lib/libalpm/be_files.c index 31b23172..0765b8db 100644 --- a/lib/libalpm/be_files.c +++ b/lib/libalpm/be_files.c @@ -113,6 +113,26 @@ static int setlastupdate(const pmdb_t *db, time_t time) 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 * @param force if true, then forces the update, otherwise update only in case * 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) { - alpm_list_t *lp; char *dbfile, *dbfilepath; time_t newmtime = 0, lastupdate = 0; const char *dbpath; @@ -176,14 +195,9 @@ int SYMEXPORT alpm_db_update(int force, pmdb_t *db) return(-1); } else { /* remove the old dir */ - _alpm_log(PM_LOG_DEBUG, "flushing database %s\n", db->path); - for(lp = _alpm_db_get_pkgcache(db); lp; lp = lp->next) { - 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); - } + if(_alpm_rmrf(db->path) != 0) { + _alpm_log(PM_LOG_ERROR, _("could not remove database %s\n"), db->treename); + RET_ERR(PM_ERR_DB_REMOVE, -1); } /* Cache needs to be rebuilt */ @@ -195,6 +209,7 @@ int SYMEXPORT alpm_db_update(int force, pmdb_t *db) sprintf(dbfilepath, "%s%s" DBEXT, dbpath, db->treename); /* uncompress the sync database */ + checkdbdir(db); ret = _alpm_unpack(dbfilepath, db->path, NULL); if(ret) { free(dbfilepath); @@ -214,36 +229,6 @@ int SYMEXPORT alpm_db_update(int force, pmdb_t *db) return(0); } -int _alpm_db_open(pmdb_t *db) -{ - ALPM_LOG_FUNC; - - if(db == NULL) { - RET_ERR(PM_ERR_DB_NULL, -1); - } - - _alpm_log(PM_LOG_DEBUG, "opening database from path '%s'\n", db->path); - db->handle = opendir(db->path); - if(db->handle == NULL) { - RET_ERR(PM_ERR_DB_OPEN, -1); - } - - return(0); -} - -void _alpm_db_close(pmdb_t *db) -{ - ALPM_LOG_FUNC; - - if(db == NULL) { - return; - } - - if(db->handle) { - closedir(db->handle); - db->handle = NULL; - } -} static int splitname(const char *target, pmpkg_t *pkg) { @@ -290,13 +275,17 @@ int _alpm_db_populate(pmdb_t *db) struct dirent *ent = NULL; struct stat sbuf; char path[PATH_MAX]; + DIR *dbdir; ALPM_LOG_FUNC; ASSERT(db != NULL, RET_ERR(PM_ERR_DB_NULL, -1)); - rewinddir(db->handle); - while((ent = readdir(db->handle)) != NULL) { + dbdir = opendir(db->path); + if(dbdir == NULL) { + return(0); + } + while((ent = readdir(dbdir)) != NULL) { const char *name = ent->d_name; pmpkg_t *pkg; @@ -311,6 +300,7 @@ int _alpm_db_populate(pmdb_t *db) pkg = _alpm_pkg_new(); if(pkg == NULL) { + closedir(dbdir); return(-1); } /* split the db entry name */ @@ -336,6 +326,7 @@ int _alpm_db_populate(pmdb_t *db) count++; } + closedir(dbdir); db->pkgcache = alpm_list_msort(db->pkgcache, count, _alpm_pkg_cmp); return(count); } @@ -658,12 +649,16 @@ int _alpm_db_prepare(pmdb_t *db, pmpkg_t *info) int retval = 0; char *pkgpath = NULL; - oldmask = umask(0000); + if(checkdbdir(db) != 0) { + return(-1); + } + oldmask = umask(0000); pkgpath = get_pkgpath(db, info); 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); @@ -826,7 +821,7 @@ int _alpm_db_write(pmdb_t *db, pmpkg_t *info, pmdbinfrq_t inforeq) if(info->depends) { fputs("%DEPENDS%\n", fp); for(lp = info->depends; lp; lp = lp->next) { - char *depstring = alpm_dep_get_string(lp->data); + char *depstring = alpm_dep_compute_string(lp->data); fprintf(fp, "%s\n", depstring); free(depstring); } |