#include "config.h"
#include <sys/stat.h>
#include <archive.h>
#include <archive_entry.h>
#include "util.h"
#include "log.h"
#include "alpm.h"
#include "alpm_list.h"
#include "package.h"
#include "handle.h"
#include "delta.h"
#include "deps.h"
#include "dload.h"
int SYMEXPORT alpm_db_update(int force, pmdb_t *db)
{
char *syncpath;
const char *dbpath;
alpm_list_t *i;
struct stat buf;
size_t len;
int ret = -1;
mode_t oldmask;
pgp_verify_t check_sig;
ASSERT(db != NULL && db != db->handle->db_local, RET_ERR(PM_ERR_WRONG_ARGS, -1));
ASSERT(db->servers != NULL, RET_ERR(PM_ERR_SERVER_NONE, -1));
dbpath = alpm_option_get_dbpath();
len = strlen(dbpath) + 6;
MALLOC(syncpath, len, RET_ERR(PM_ERR_MEMORY, -1));
sprintf(syncpath, "%s%s", dbpath, "sync/");
oldmask = umask(0022);
if(stat(syncpath, &buf) != 0) {
_alpm_log(PM_LOG_DEBUG, "database dir '%s' does not exist, creating it\n",
syncpath);
if(_alpm_makepath(syncpath) != 0) {
free(syncpath);
RET_ERR(PM_ERR_SYSTEM, -1);
}
} else if(!S_ISDIR(buf.st_mode)) {
_alpm_log(PM_LOG_WARNING, _("removing invalid file: %s\n"), syncpath);
if(unlink(syncpath) != 0 || _alpm_makepath(syncpath) != 0) {
free(syncpath);
RET_ERR(PM_ERR_SYSTEM, -1);
}
}
check_sig = _alpm_db_get_sigverify_level(db);
for(i = db->servers; i; i = i-&
|