Add a alpm_db_test() function to the backend for checking DB consistency

Signed-off-by: Dan McGee <dan@archlinux.org>
This commit is contained in:
VMiklos 2007-05-31 15:18:24 -04:00 committed by Dan McGee
parent 25c5b39d05
commit dfc85cb5f5
4 changed files with 46 additions and 0 deletions

View File

@ -157,6 +157,7 @@ alpm_list_t *alpm_db_whatprovides(pmdb_t *db, const char *name);
pmgrp_t *alpm_db_readgrp(pmdb_t *db, const char *name);
alpm_list_t *alpm_db_getgrpcache(pmdb_t *db);
alpm_list_t *alpm_db_test(pmdb_t *db);
alpm_list_t *alpm_db_search(pmdb_t *db, const alpm_list_t* needles);
alpm_list_t *alpm_db_get_upgrades();

View File

@ -65,6 +65,37 @@ int _alpm_db_install(pmdb_t *db, const char *dbfile)
return unlink(dbfile);
}
alpm_list_t *_alpm_db_test(pmdb_t *db)
{
struct dirent *ent;
char path[PATH_MAX];
struct stat buf;
alpm_list_t *ret = NULL;
while ((ent = readdir(db->handle)) != NULL) {
if(!strcmp(ent->d_name, ".") || !strcmp(ent->d_name, "..")) {
continue;
}
/* check for desc, depends, and files */
snprintf(path, PATH_MAX, "%s/%s/desc", db->path, ent->d_name);
if(stat(path, &buf)) {
snprintf(path, LOG_STR_LEN, _("%s: description file is missing"), ent->d_name);
ret = alpm_list_add(ret, strdup(path));
}
snprintf(path, PATH_MAX, "%s/%s/depends", db->path, ent->d_name);
if(stat(path, &buf)) {
snprintf(path, LOG_STR_LEN, _("%s: dependency file is missing"), ent->d_name);
ret = alpm_list_add(ret, strdup(path));
}
snprintf(path, PATH_MAX, "%s/%s/files", db->path, ent->d_name);
if(stat(path, &buf)) {
snprintf(path, LOG_STR_LEN, _("%s: file list is missing"), ent->d_name);
ret = alpm_list_add(ret, strdup(path));
}
}
return(ret);
}
int _alpm_db_open(pmdb_t *db)
{
ALPM_LOG_FUNC;

View File

@ -368,6 +368,19 @@ alpm_list_t SYMEXPORT *alpm_db_getgrpcache(pmdb_t *db)
return(_alpm_db_get_grpcache(db));
}
/** Tests a database
* @param db pointer to the package database to search in
* @return the list of problems found on success, NULL on error
*/
alpm_list_t SYMEXPORT *alpm_db_test(pmdb_t *db)
{
/* Sanity checks */
ASSERT(handle != NULL, return(NULL));
ASSERT(db != NULL, return(NULL));
return(_alpm_db_test(db));
}
/** Searches a database
* @param db pointer to the package database to search in
* @param needles the list of strings to search for

View File

@ -56,6 +56,7 @@ pmdb_t *_alpm_db_register(const char *treename);
/* be.c, backend specific calls */
int _alpm_db_install(pmdb_t *db, const char *dbfile);
alpm_list_t *_alpm_db_test(pmdb_t *db);
int _alpm_db_open(pmdb_t *db);
void _alpm_db_close(pmdb_t *db);
void _alpm_db_rewind(pmdb_t *db);