Populate sync db from archive
Read in list of packages for sync db from tar archive. Breaks reading in _alpm_sync_db_read and a lot of pactests (which is expected as they do not handle sync db in archives...). Signed-off-by: Allan McRae <allan@archlinux.org>
This commit is contained in:
parent
fc32faaa6a
commit
5e61f07735
3 changed files with 42 additions and 27 deletions
|
@ -358,6 +358,7 @@ int _alpm_local_db_populate(pmdb_t *db)
|
||||||
}
|
}
|
||||||
while((ent = readdir(dbdir)) != NULL) {
|
while((ent = readdir(dbdir)) != NULL) {
|
||||||
const char *name = ent->d_name;
|
const char *name = ent->d_name;
|
||||||
|
|
||||||
pmpkg_t *pkg;
|
pmpkg_t *pkg;
|
||||||
|
|
||||||
if(strcmp(name, ".") == 0 || strcmp(name, "..") == 0) {
|
if(strcmp(name, ".") == 0 || strcmp(name, "..") == 0) {
|
||||||
|
|
|
@ -23,6 +23,7 @@
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <dirent.h>
|
#include <dirent.h>
|
||||||
#include <ctype.h>
|
#include <ctype.h>
|
||||||
|
#include <locale.h>
|
||||||
|
|
||||||
/* libarchive */
|
/* libarchive */
|
||||||
#include <archive.h>
|
#include <archive.h>
|
||||||
|
@ -500,40 +501,53 @@ cleanup:
|
||||||
return(0);
|
return(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int _alpm_sync_db_populate(pmdb_t *db)
|
int _alpm_sync_db_populate(pmdb_t *db)
|
||||||
{
|
{
|
||||||
int count = 0;
|
int count = 0;
|
||||||
struct dirent *ent = NULL;
|
struct archive *archive;
|
||||||
const char *dbpath;
|
struct archive_entry *entry;
|
||||||
DIR *dbdir;
|
const char * archive_path;
|
||||||
|
|
||||||
ALPM_LOG_FUNC;
|
ALPM_LOG_FUNC;
|
||||||
|
|
||||||
ASSERT(db != NULL, RET_ERR(PM_ERR_DB_NULL, -1));
|
ASSERT(db != NULL, RET_ERR(PM_ERR_DB_NULL, -1));
|
||||||
|
|
||||||
dbpath = _alpm_db_path(db);
|
if((archive = archive_read_new()) == NULL)
|
||||||
dbdir = opendir(dbpath);
|
RET_ERR(PM_ERR_LIBARCHIVE, 1);
|
||||||
if(dbdir == NULL) {
|
|
||||||
return(0);
|
archive_read_support_compression_all(archive);
|
||||||
|
archive_read_support_format_all(archive);
|
||||||
|
|
||||||
|
if(archive_read_open_filename(archive, _alpm_db_path(db),
|
||||||
|
ARCHIVE_DEFAULT_BYTES_PER_BLOCK) != ARCHIVE_OK) {
|
||||||
|
_alpm_log(PM_LOG_ERROR, _("could not open %s: %s\n"), _alpm_db_path(db),
|
||||||
|
archive_error_string(archive));
|
||||||
|
RET_ERR(PM_ERR_PKG_OPEN, 1);
|
||||||
}
|
}
|
||||||
while((ent = readdir(dbdir)) != NULL) {
|
|
||||||
const char *name = ent->d_name;
|
while(archive_read_next_header(archive, &entry) == ARCHIVE_OK) {
|
||||||
|
const struct stat *st;
|
||||||
|
const char *name;
|
||||||
pmpkg_t *pkg;
|
pmpkg_t *pkg;
|
||||||
|
|
||||||
if(strcmp(name, ".") == 0 || strcmp(name, "..") == 0) {
|
st = archive_entry_stat(entry);
|
||||||
continue;
|
|
||||||
}
|
/* only parse directory names */
|
||||||
if(!is_dir(dbpath, ent)) {
|
if(S_ISREG(st->st_mode)) {
|
||||||
|
/* we have desc or depends or something else */
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
archive_path = archive_entry_pathname(entry);
|
||||||
|
|
||||||
pkg = _alpm_pkg_new();
|
pkg = _alpm_pkg_new();
|
||||||
if(pkg == NULL) {
|
if(pkg == NULL) {
|
||||||
closedir(dbdir);
|
archive_read_finish(archive);
|
||||||
return(-1);
|
return(-1);
|
||||||
}
|
}
|
||||||
/* split the db entry name */
|
|
||||||
|
name = archive_entry_pathname(entry);
|
||||||
|
|
||||||
if(splitname(name, pkg) != 0) {
|
if(splitname(name, pkg) != 0) {
|
||||||
_alpm_log(PM_LOG_ERROR, _("invalid name for database entry '%s'\n"),
|
_alpm_log(PM_LOG_ERROR, _("invalid name for database entry '%s'\n"),
|
||||||
name);
|
name);
|
||||||
|
@ -548,17 +562,10 @@ int _alpm_sync_db_populate(pmdb_t *db)
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* explicitly read with only 'BASE' data, accessors will handle the rest */
|
|
||||||
if(_alpm_sync_db_read(db, pkg, INFRQ_BASE) == -1) {
|
|
||||||
_alpm_log(PM_LOG_ERROR, _("corrupted database entry '%s'\n"), name);
|
|
||||||
_alpm_pkg_free(pkg);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
pkg->origin = PKG_FROM_SYNCDB;
|
pkg->origin = PKG_FROM_SYNCDB;
|
||||||
pkg->ops = &sync_pkg_ops;
|
pkg->ops = &sync_pkg_ops;
|
||||||
|
|
||||||
pkg->origin_data.db = db;
|
pkg->origin_data.db = db;
|
||||||
|
|
||||||
/* add to the collection */
|
/* add to the collection */
|
||||||
_alpm_log(PM_LOG_FUNCTION, "adding '%s' to package cache for db '%s'\n",
|
_alpm_log(PM_LOG_FUNCTION, "adding '%s' to package cache for db '%s'\n",
|
||||||
pkg->name, db->treename);
|
pkg->name, db->treename);
|
||||||
|
@ -566,8 +573,9 @@ int _alpm_sync_db_populate(pmdb_t *db)
|
||||||
count++;
|
count++;
|
||||||
}
|
}
|
||||||
|
|
||||||
closedir(dbdir);
|
|
||||||
db->pkgcache = alpm_list_msort(db->pkgcache, count, _alpm_pkg_cmp);
|
db->pkgcache = alpm_list_msort(db->pkgcache, count, _alpm_pkg_cmp);
|
||||||
|
archive_read_finish(archive);
|
||||||
|
|
||||||
return(count);
|
return(count);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -414,10 +414,10 @@ const char *_alpm_db_path(pmdb_t *db)
|
||||||
CALLOC(db->_path, 1, pathsize, RET_ERR(PM_ERR_MEMORY, NULL));
|
CALLOC(db->_path, 1, pathsize, RET_ERR(PM_ERR_MEMORY, NULL));
|
||||||
sprintf(db->_path, "%s%s/", dbpath, db->treename);
|
sprintf(db->_path, "%s%s/", dbpath, db->treename);
|
||||||
} else {
|
} else {
|
||||||
pathsize = strlen(dbpath) + 5 + strlen(db->treename) + 2;
|
pathsize = strlen(dbpath) + 5 + strlen(db->treename) + 4;
|
||||||
CALLOC(db->_path, 1, pathsize, RET_ERR(PM_ERR_MEMORY, NULL));
|
CALLOC(db->_path, 1, pathsize, RET_ERR(PM_ERR_MEMORY, 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 */
|
||||||
sprintf(db->_path, "%ssync/%s/", dbpath, db->treename);
|
sprintf(db->_path, "%ssync/%s.db", dbpath, db->treename);
|
||||||
}
|
}
|
||||||
_alpm_log(PM_LOG_DEBUG, "database path for tree %s set to %s\n",
|
_alpm_log(PM_LOG_DEBUG, "database path for tree %s set to %s\n",
|
||||||
db->treename, db->_path);
|
db->treename, db->_path);
|
||||||
|
@ -766,6 +766,12 @@ int splitname(const char *target, pmpkg_t *pkg)
|
||||||
STRDUP(tmp, target, RET_ERR(PM_ERR_MEMORY, -1));
|
STRDUP(tmp, target, RET_ERR(PM_ERR_MEMORY, -1));
|
||||||
p = tmp + strlen(tmp);
|
p = tmp + strlen(tmp);
|
||||||
|
|
||||||
|
/* remove any trailing '/' */
|
||||||
|
while (*(p - 1) == '/') {
|
||||||
|
--p;
|
||||||
|
*p = '\0';
|
||||||
|
}
|
||||||
|
|
||||||
/* do the magic parsing- find the beginning of the version string
|
/* do the magic parsing- find the beginning of the version string
|
||||||
* by doing two iterations of same loop to lop off two hyphens */
|
* by doing two iterations of same loop to lop off two hyphens */
|
||||||
for(q = --p; *q && *q != '-'; q--);
|
for(q = --p; *q && *q != '-'; q--);
|
||||||
|
|
Loading…
Add table
Reference in a new issue