summaryrefslogtreecommitdiffstats
path: root/src/pacman/sync.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/pacman/sync.c')
-rw-r--r--src/pacman/sync.c472
1 files changed, 230 insertions, 242 deletions
diff --git a/src/pacman/sync.c b/src/pacman/sync.c
index 6962306a..3846b303 100644
--- a/src/pacman/sync.c
+++ b/src/pacman/sync.c
@@ -39,18 +39,19 @@
/* if keep_used != 0, then the db files which match an used syncdb
* will be kept */
-static int sync_cleandb(const char *dbpath, int keep_used) {
+static int sync_cleandb(const char *dbpath, int keep_used)
+{
DIR *dir;
struct dirent *ent;
alpm_list_t *syncdbs;
dir = opendir(dbpath);
if(dir == NULL) {
- pm_fprintf(stderr, PM_LOG_ERROR, _("could not access database directory\n"));
- return(1);
+ pm_fprintf(stderr, ALPM_LOG_ERROR, _("could not access database directory\n"));
+ return 1;
}
- syncdbs = alpm_option_get_syncdbs();
+ syncdbs = alpm_option_get_syncdbs(config->handle);
rewinddir(dir);
/* step through the directory one file at a time */
@@ -81,10 +82,10 @@ static int sync_cleandb(const char *dbpath, int keep_used) {
len = strlen(path);
if(S_ISDIR(buf.st_mode) || strcmp(path + len - 3, ".db") != 0) {
if(rmrf(path)) {
- pm_fprintf(stderr, PM_LOG_ERROR,
+ pm_fprintf(stderr, ALPM_LOG_ERROR,
_("could not remove %s\n"), path);
closedir(dir);
- return(1);
+ return 1;
}
continue;
}
@@ -94,7 +95,7 @@ static int sync_cleandb(const char *dbpath, int keep_used) {
len = strlen(dname);
char *dbname = strndup(dname, len - 3);
for(i = syncdbs; i && !found; i = alpm_list_next(i)) {
- pmdb_t *db = alpm_list_getdata(i);
+ alpm_db_t *db = alpm_list_getdata(i);
found = !strcmp(dbname, alpm_db_get_name(db));
}
free(dbname);
@@ -107,26 +108,27 @@ static int sync_cleandb(const char *dbpath, int keep_used) {
}
if(rmrf(path)) {
- pm_fprintf(stderr, PM_LOG_ERROR,
+ pm_fprintf(stderr, ALPM_LOG_ERROR,
_("could not remove %s\n"), path);
closedir(dir);
- return(1);
+ return 1;
}
}
}
closedir(dir);
- return(0);
+ return 0;
}
-static int sync_cleandb_all(void) {
+static int sync_cleandb_all(void)
+{
const char *dbpath;
char newdbpath[PATH_MAX];
int ret = 0;
- dbpath = alpm_option_get_dbpath();
+ dbpath = alpm_option_get_dbpath(config->handle);
printf(_("Database directory: %s\n"), dbpath);
if(!yesno(_("Do you want to remove unused repositories?"))) {
- return(0);
+ return 0;
}
/* The sync dbs were previously put in dbpath/ but are now in dbpath/sync/.
* We will clean everything in dbpath/ except local/, sync/ and db.lck, and
@@ -137,18 +139,19 @@ static int sync_cleandb_all(void) {
ret += sync_cleandb(newdbpath, 1);
printf(_("Database directory cleaned up\n"));
- return(ret);
+ return ret;
}
static int sync_cleancache(int level)
{
alpm_list_t *i;
- alpm_list_t *sync_dbs = alpm_option_get_syncdbs();
- pmdb_t *db_local = alpm_option_get_localdb();
+ alpm_list_t *sync_dbs = alpm_option_get_syncdbs(config->handle);
+ alpm_db_t *db_local = alpm_option_get_localdb(config->handle);
+ alpm_list_t *cachedirs = alpm_option_get_cachedirs(config->handle);
int ret = 0;
- for(i = alpm_option_get_cachedirs(); i; i = alpm_list_next(i)) {
- printf(_("Cache directory: %s\n"), (char*)alpm_list_getdata(i));
+ for(i = cachedirs; i; i = alpm_list_next(i)) {
+ printf(_("Cache directory: %s\n"), (char *)alpm_list_getdata(i));
}
if(!config->cleanmethod) {
@@ -165,23 +168,23 @@ static int sync_cleancache(int level)
printf(_(" All current sync database packages\n"));
}
if(!yesno(_("Do you want to remove all other packages from cache?"))) {
- return(0);
+ return 0;
}
printf(_("removing old packages from cache...\n"));
} else {
if(!noyes(_("Do you want to remove ALL files from cache?"))) {
- return(0);
+ return 0;
}
printf(_("removing all files from cache...\n"));
}
- for(i = alpm_option_get_cachedirs(); i; i = alpm_list_next(i)) {
+ for(i = cachedirs; i; i = alpm_list_next(i)) {
const char *cachedir = alpm_list_getdata(i);
DIR *dir = opendir(cachedir);
struct dirent *ent;
if(dir == NULL) {
- pm_fprintf(stderr, PM_LOG_ERROR,
+ pm_fprintf(stderr, ALPM_LOG_ERROR,
_("could not access cache directory %s\n"), cachedir);
ret++;
continue;
@@ -191,10 +194,10 @@ static int sync_cleancache(int level)
/* step through the directory one file at a time */
while((ent = readdir(dir)) != NULL) {
char path[PATH_MAX];
+ size_t pathlen;
int delete = 1;
- pmpkg_t *localpkg = NULL, *pkg = NULL;
+ alpm_pkg_t *localpkg = NULL, *pkg = NULL;
const char *local_name, *local_version;
- alpm_list_t *j;
if(strcmp(ent->d_name, ".") == 0 || strcmp(ent->d_name, "..") == 0) {
continue;
@@ -208,11 +211,19 @@ static int sync_cleancache(int level)
continue;
}
+ /* we handle .sig files with packages, not separately */
+ pathlen = strlen(path);
+ if(strcmp(path + pathlen - 4, ".sig") == 0) {
+ continue;
+ }
+
/* attempt to load the package, prompt removal on failures as we may have
* files here that aren't valid packages. we also don't need a full
* load of the package, just the metadata. */
- if(alpm_pkg_load(path, 0, &localpkg) != 0 || localpkg == NULL) {
- if(yesno(_("File %s does not seem to be a valid package, remove it?"), path)) {
+ if(alpm_pkg_load(config->handle, path, 0, 0, &localpkg) != 0
+ || localpkg == NULL) {
+ if(yesno(_("File %s does not seem to be a valid package, remove it?"),
+ path)) {
if(localpkg) {
alpm_pkg_free(localpkg);
}
@@ -229,20 +240,21 @@ static int sync_cleancache(int level)
if(pkg != NULL && alpm_pkg_vercmp(local_version,
alpm_pkg_get_version(pkg)) == 0) {
/* package was found in local DB and version matches, keep it */
- pm_printf(PM_LOG_DEBUG, "pkg %s-%s found in local db\n",
+ pm_printf(ALPM_LOG_DEBUG, "pkg %s-%s found in local db\n",
local_name, local_version);
delete = 0;
}
}
if(config->cleanmethod & PM_CLEAN_KEEPCUR) {
+ alpm_list_t *j;
/* check if this package is in a sync DB */
for(j = sync_dbs; j && delete; j = alpm_list_next(j)) {
- pmdb_t *db = alpm_list_getdata(j);
+ alpm_db_t *db = alpm_list_getdata(j);
pkg = alpm_db_get_pkg(db, local_name);
if(pkg != NULL && alpm_pkg_vercmp(local_version,
alpm_pkg_get_version(pkg)) == 0) {
/* package was found in a sync DB and version matches, keep it */
- pm_printf(PM_LOG_DEBUG, "pkg %s-%s found in sync db\n",
+ pm_printf(ALPM_LOG_DEBUG, "pkg %s-%s found in sync db\n",
local_name, local_version);
delete = 0;
}
@@ -253,12 +265,17 @@ static int sync_cleancache(int level)
if(delete) {
unlink(path);
+ /* unlink a signature file if present too */
+ if(PATH_MAX - 5 >= pathlen) {
+ strcpy(path + pathlen, ".sig");
+ unlink(path);
+ }
}
}
closedir(dir);
}
- return(ret);
+ return ret;
}
static int sync_synctree(int level, alpm_list_t *syncs)
@@ -266,17 +283,13 @@ static int sync_synctree(int level, alpm_list_t *syncs)
alpm_list_t *i;
int success = 0, ret;
- if(trans_init(0) == -1) {
- return(0);
- }
-
for(i = syncs; i; i = alpm_list_next(i)) {
- pmdb_t *db = alpm_list_getdata(i);
+ alpm_db_t *db = alpm_list_getdata(i);
ret = alpm_db_update((level < 2 ? 0 : 1), db);
if(ret < 0) {
- pm_fprintf(stderr, PM_LOG_ERROR, _("failed to update %s (%s)\n"),
- alpm_db_get_name(db), alpm_strerrorlast());
+ pm_fprintf(stderr, ALPM_LOG_ERROR, _("failed to update %s (%s)\n"),
+ alpm_db_get_name(db), alpm_strerror(alpm_errno(config->handle)));
} else if(ret == 1) {
printf(_(" %s is up to date\n"), alpm_db_get_name(db));
success++;
@@ -285,24 +298,21 @@ static int sync_synctree(int level, alpm_list_t *syncs)
}
}
- if(trans_release() == -1) {
- return(0);
- }
/* We should always succeed if at least one DB was upgraded - we may possibly
* fail later with unresolved deps, but that should be rare, and would be
* expected
*/
if(!success) {
- pm_fprintf(stderr, PM_LOG_ERROR, _("failed to synchronize any databases\n"));
+ pm_fprintf(stderr, ALPM_LOG_ERROR, _("failed to synchronize any databases\n"));
}
- return(success > 0);
+ return (success > 0);
}
-static void print_installed(pmdb_t *db_local, pmpkg_t *pkg)
+static void print_installed(alpm_db_t *db_local, alpm_pkg_t *pkg)
{
const char *pkgname = alpm_pkg_get_name(pkg);
const char *pkgver = alpm_pkg_get_version(pkg);
- pmpkg_t *lpkg = alpm_db_get_pkg(db_local, pkgname);
+ alpm_pkg_t *lpkg = alpm_db_get_pkg(db_local, pkgname);
if(lpkg) {
const char *lpkgver = alpm_pkg_get_version(lpkg);
if(strcmp(lpkgver,pkgver) == 0) {
@@ -319,10 +329,10 @@ static int sync_search(alpm_list_t *syncs, alpm_list_t *targets)
alpm_list_t *i, *j, *ret;
int freelist;
int found = 0;
- pmdb_t *db_local = alpm_option_get_localdb();
+ alpm_db_t *db_local = alpm_option_get_localdb(config->handle);
for(i = syncs; i; i = alpm_list_next(i)) {
- pmdb_t *db = alpm_list_getdata(i);
+ alpm_db_t *db = alpm_list_getdata(i);
/* if we have a targets list, search for packages matching it */
if(targets) {
ret = alpm_db_search(db, targets);
@@ -338,24 +348,16 @@ static int sync_search(alpm_list_t *syncs, alpm_list_t *targets)
}
for(j = ret; j; j = alpm_list_next(j)) {
alpm_list_t *grp;
- pmpkg_t *pkg = alpm_list_getdata(j);
+ alpm_pkg_t *pkg = alpm_list_getdata(j);
- if (!config->quiet) {
+ if(!config->quiet) {
printf("%s/%s %s", alpm_db_get_name(db), alpm_pkg_get_name(pkg),
alpm_pkg_get_version(pkg));
} else {
printf("%s", alpm_pkg_get_name(pkg));
}
- /* print the package size with the output if ShowSize option set */
- if(!config->quiet && config->showsize) {
- /* Convert byte size to MB */
- double mbsize = (double)alpm_pkg_get_size(pkg) / (1024.0 * 1024.0);
-
- printf(" [%.2f MB]", mbsize);
- }
-
- if (!config->quiet) {
+ if(!config->quiet) {
if((grp = alpm_pkg_get_groups(pkg)) != NULL) {
alpm_list_t *k;
printf(" (");
@@ -384,7 +386,7 @@ static int sync_search(alpm_list_t *syncs, alpm_list_t *targets)
}
}
- return(!found);
+ return !found;
}
static int sync_group(int level, alpm_list_t *syncs, alpm_list_t *targets)
@@ -395,12 +397,12 @@ static int sync_group(int level, alpm_list_t *syncs, alpm_list_t *targets)
for(i = targets; i; i = alpm_list_next(i)) {
const char *grpname = alpm_list_getdata(i);
for(j = syncs; j; j = alpm_list_next(j)) {
- pmdb_t *db = alpm_list_getdata(j);
- pmgrp_t *grp = alpm_db_readgrp(db, grpname);
+ alpm_db_t *db = alpm_list_getdata(j);
+ alpm_group_t *grp = alpm_db_readgroup(db, grpname);
if(grp) {
/* get names of packages in group */
- for(k = alpm_grp_get_pkgs(grp); k; k = alpm_list_next(k)) {
+ for(k = grp->packages; k; k = alpm_list_next(k)) {
if(!config->quiet) {
printf("%s %s\n", grpname,
alpm_pkg_get_name(alpm_list_getdata(k)));
@@ -413,26 +415,25 @@ static int sync_group(int level, alpm_list_t *syncs, alpm_list_t *targets)
}
} else {
for(i = syncs; i; i = alpm_list_next(i)) {
- pmdb_t *db = alpm_list_getdata(i);
+ alpm_db_t *db = alpm_list_getdata(i);
- for(j = alpm_db_get_grpcache(db); j; j = alpm_list_next(j)) {
- pmgrp_t *grp = alpm_list_getdata(j);
- const char *grpname = alpm_grp_get_name(grp);
+ for(j = alpm_db_get_groupcache(db); j; j = alpm_list_next(j)) {
+ alpm_group_t *grp = alpm_list_getdata(j);
if(level > 1) {
- for(k = alpm_grp_get_pkgs(grp); k; k = alpm_list_next(k)) {
- printf("%s %s\n", grpname,
+ for(k = grp->packages; k; k = alpm_list_next(k)) {
+ printf("%s %s\n", grp->name,
alpm_pkg_get_name(alpm_list_getdata(k)));
}
} else {
/* print grp names only, no package names */
- printf("%s\n", grpname);
+ printf("%s\n", grp->name);
}
}
}
}
- return(0);
+ return 0;
}
static int sync_info(alpm_list_t *syncs, alpm_list_t *targets)
@@ -442,96 +443,77 @@ static int sync_info(alpm_list_t *syncs, alpm_list_t *targets)
if(targets) {
for(i = targets; i; i = alpm_list_next(i)) {
- pmdb_t *db = NULL;
- int foundpkg = 0;
-
- char target[512]; /* TODO is this enough space? */
- char *repo = NULL, *pkgstr = NULL;
+ const char *target = alpm_list_getdata(i);
+ char *name = strdup(target);
+ char *repo, *pkgstr;
+ int foundpkg = 0, founddb = 0;
- strncpy(target, i->data, 512);
- pkgstr = strchr(target, '/');
+ pkgstr = strchr(name, '/');
if(pkgstr) {
- repo = target;
+ repo = name;
*pkgstr = '\0';
++pkgstr;
+ } else {
+ repo = NULL;
+ pkgstr = name;
+ }
- for(j = syncs; j; j = alpm_list_next(j)) {
- db = alpm_list_getdata(j);
- if(strcmp(repo, alpm_db_get_name(db)) == 0) {
- break;
- }
- db = NULL;
- }
-
- if(!db) {
- pm_fprintf(stderr, PM_LOG_ERROR,
- _("repository '%s' does not exist\n"), repo);
- return(1);
+ for(j = syncs; j; j = alpm_list_next(j)) {
+ alpm_db_t *db = alpm_list_getdata(j);
+ if(repo && strcmp(repo, alpm_db_get_name(db)) != 0) {
+ continue;
}
+ founddb = 1;
for(k = alpm_db_get_pkgcache(db); k; k = alpm_list_next(k)) {
- pmpkg_t *pkg = alpm_list_getdata(k);
+ alpm_pkg_t *pkg = alpm_list_getdata(k);
if(strcmp(alpm_pkg_get_name(pkg), pkgstr) == 0) {
- dump_pkg_sync(pkg, alpm_db_get_name(db), config->op_s_info);
+ dump_pkg_full(pkg, PKG_FROM_SYNCDB, config->op_s_info > 1);
foundpkg = 1;
break;
}
}
+ }
- if(!foundpkg) {
- pm_fprintf(stderr, PM_LOG_ERROR,
- _("package '%s' was not found in repository '%s'\n"), pkgstr, repo);
- ret++;
- }
- } else {
- pkgstr = target;
-
- for(j = syncs; j; j = alpm_list_next(j)) {
- pmdb_t *db = alpm_list_getdata(j);
-
- for(k = alpm_db_get_pkgcache(db); k; k = alpm_list_next(k)) {
- pmpkg_t *pkg = alpm_list_getdata(k);
-
- if(strcmp(alpm_pkg_get_name(pkg), pkgstr) == 0) {
- dump_pkg_sync(pkg, alpm_db_get_name(db), config->op_s_info);
- foundpkg = 1;
- break;
- }
- }
- }
- if(!foundpkg) {
- pm_fprintf(stderr, PM_LOG_ERROR,
- _("package '%s' was not found\n"), pkgstr);
- ret++;
- }
+ if(!founddb) {
+ pm_fprintf(stderr, ALPM_LOG_ERROR,
+ _("repository '%s' does not exist\n"), repo);
+ ret++;
+ }
+ if(!foundpkg) {
+ pm_fprintf(stderr, ALPM_LOG_ERROR,
+ _("package '%s' was not found\n"), target);
+ ret++;
}
+ free(name);
}
} else {
for(i = syncs; i; i = alpm_list_next(i)) {
- pmdb_t *db = alpm_list_getdata(i);
+ alpm_db_t *db = alpm_list_getdata(i);
for(j = alpm_db_get_pkgcache(db); j; j = alpm_list_next(j)) {
- dump_pkg_sync(alpm_list_getdata(j), alpm_db_get_name(db), config->op_s_info);
+ alpm_pkg_t *pkg = alpm_list_getdata(j);
+ dump_pkg_full(pkg, PKG_FROM_SYNCDB, config->op_s_info > 1);
}
}
}
- return(ret);
+ return ret;
}
static int sync_list(alpm_list_t *syncs, alpm_list_t *targets)
{
alpm_list_t *i, *j, *ls = NULL;
- pmdb_t *db_local = alpm_option_get_localdb();
+ alpm_db_t *db_local = alpm_option_get_localdb(config->handle);
if(targets) {
for(i = targets; i; i = alpm_list_next(i)) {
const char *repo = alpm_list_getdata(i);
- pmdb_t *db = NULL;
+ alpm_db_t *db = NULL;
for(j = syncs; j; j = alpm_list_next(j)) {
- pmdb_t *d = alpm_list_getdata(j);
+ alpm_db_t *d = alpm_list_getdata(j);
if(strcmp(repo, alpm_db_get_name(d)) == 0) {
db = d;
@@ -540,10 +522,10 @@ static int sync_list(alpm_list_t *syncs, alpm_list_t *targets)
}
if(db == NULL) {
- pm_fprintf(stderr, PM_LOG_ERROR,
+ pm_fprintf(stderr, ALPM_LOG_ERROR,
_("repository \"%s\" was not found.\n"),repo);
alpm_list_free(ls);
- return(1);
+ return 1;
}
ls = alpm_list_add(ls, db);
@@ -553,12 +535,12 @@ static int sync_list(alpm_list_t *syncs, alpm_list_t *targets)
}
for(i = ls; i; i = alpm_list_next(i)) {
- pmdb_t *db = alpm_list_getdata(i);
+ alpm_db_t *db = alpm_list_getdata(i);
for(j = alpm_db_get_pkgcache(db); j; j = alpm_list_next(j)) {
- pmpkg_t *pkg = alpm_list_getdata(j);
+ alpm_pkg_t *pkg = alpm_list_getdata(j);
- if (!config->quiet) {
+ if(!config->quiet) {
printf("%s %s %s", alpm_db_get_name(db), alpm_pkg_get_name(pkg),
alpm_pkg_get_version(pkg));
print_installed(db_local, pkg);
@@ -573,69 +555,71 @@ static int sync_list(alpm_list_t *syncs, alpm_list_t *targets)
alpm_list_free(ls);
}
- return(0);
+ return 0;
}
static alpm_list_t *syncfirst(void) {
alpm_list_t *i, *res = NULL;
- pmdb_t *db_local = alpm_option_get_localdb();
+ alpm_db_t *db_local = alpm_option_get_localdb(config->handle);
+ alpm_list_t *syncdbs = alpm_option_get_syncdbs(config->handle);
for(i = config->syncfirst; i; i = alpm_list_next(i)) {
char *pkgname = alpm_list_getdata(i);
- pmpkg_t *pkg = alpm_db_get_pkg(db_local, pkgname);
+ alpm_pkg_t *pkg = alpm_db_get_pkg(db_local, pkgname);
if(pkg == NULL) {
continue;
}
- if(alpm_sync_newversion(pkg, alpm_option_get_syncdbs())) {
+ if(alpm_sync_newversion(pkg, syncdbs)) {
res = alpm_list_add(res, strdup(pkgname));
}
}
- return(res);
+ return res;
}
-static pmdb_t *get_db(const char *dbname)
+static alpm_db_t *get_db(const char *dbname)
{
alpm_list_t *i;
- for(i = alpm_option_get_syncdbs(); i; i = i->next) {
- pmdb_t *db = i->data;
+ for(i = alpm_option_get_syncdbs(config->handle); i; i = i->next) {
+ alpm_db_t *db = i->data;
if(strcmp(alpm_db_get_name(db), dbname) == 0) {
- return(db);
+ return db;
}
}
- return(NULL);
+ return NULL;
}
-static int process_pkg(pmpkg_t *pkg)
+static int process_pkg(alpm_pkg_t *pkg)
{
- int ret = alpm_add_pkg(pkg);
+ int ret = alpm_add_pkg(config->handle, pkg);
if(ret == -1) {
- if(pm_errno == PM_ERR_TRANS_DUP_TARGET
- || pm_errno == PM_ERR_PKG_IGNORED) {
+ enum _alpm_errno_t err = alpm_errno(config->handle);
+ if(err == ALPM_ERR_TRANS_DUP_TARGET
+ || err == ALPM_ERR_PKG_IGNORED) {
/* just skip duplicate or ignored targets */
- pm_printf(PM_LOG_WARNING, _("skipping target: %s\n"), alpm_pkg_get_name(pkg));
- return(0);
+ pm_printf(ALPM_LOG_WARNING, _("skipping target: %s\n"), alpm_pkg_get_name(pkg));
+ return 0;
} else {
- pm_fprintf(stderr, PM_LOG_ERROR, "'%s': %s\n", alpm_pkg_get_name(pkg),
- alpm_strerrorlast());
- return(1);
+ pm_fprintf(stderr, ALPM_LOG_ERROR, "'%s': %s\n", alpm_pkg_get_name(pkg),
+ alpm_strerror(err));
+ return 1;
}
}
- return(0);
+ return 0;
}
-static int process_group(alpm_list_t *dbs, char *group)
+static int process_group(alpm_list_t *dbs, const char *group)
{
int ret = 0;
alpm_list_t *i;
- alpm_list_t *pkgs = alpm_find_grp_pkgs(dbs, group);
+ alpm_list_t *pkgs = alpm_find_group_pkgs(dbs, group);
int count = alpm_list_count(pkgs);
if(!count) {
- pm_fprintf(stderr, PM_LOG_ERROR, _("target not found: %s\n"), group);
- return(1);
+ pm_fprintf(stderr, ALPM_LOG_ERROR, _("target not found: %s\n"), group);
+ return 1;
}
@@ -657,7 +641,7 @@ static int process_group(alpm_list_t *dbs, char *group)
for(i = pkgs; i; i = alpm_list_next(i)) {
if(array[n++] == 0)
continue;
- pmpkg_t *pkg = alpm_list_getdata(i);
+ alpm_pkg_t *pkg = alpm_list_getdata(i);
if(process_pkg(pkg) == 1) {
ret = 1;
@@ -668,7 +652,7 @@ static int process_group(alpm_list_t *dbs, char *group)
free(array);
} else {
for(i = pkgs; i; i = alpm_list_next(i)) {
- pmpkg_t *pkg = alpm_list_getdata(i);
+ alpm_pkg_t *pkg = alpm_list_getdata(i);
if(process_pkg(pkg) == 1) {
ret = 1;
@@ -678,28 +662,29 @@ static int process_group(alpm_list_t *dbs, char *group)
}
cleanup:
alpm_list_free(pkgs);
- return(ret);
+ return ret;
}
-static int process_targname(alpm_list_t *dblist, char *targname)
+static int process_targname(alpm_list_t *dblist, const char *targname)
{
- pmpkg_t *pkg = alpm_find_dbs_satisfier(dblist, targname);
+ alpm_pkg_t *pkg = alpm_find_dbs_satisfier(config->handle, dblist, targname);
- /* #FS23342 - skip ignored packages when user says no */
- if(pm_errno == PM_ERR_PKG_IGNORED) {
- pm_printf(PM_LOG_WARNING, _("skipping target: %s\n"), targname);
- pm_errno = 0;
- return(0);
+ /* #FS#23342 - skip ignored packages when user says no */
+ if(alpm_errno(config->handle) == ALPM_ERR_PKG_IGNORED) {
+ pm_printf(ALPM_LOG_WARNING, _("skipping target: %s\n"), targname);
+ /* TODO how to do this, we shouldn't be fucking with it from the frontend */
+ /* pm_errno = 0; */
+ return 0;
}
if(pkg) {
- return(process_pkg(pkg));
+ return process_pkg(pkg);
}
/* fallback on group */
- return(process_group(dblist, targname));
+ return process_group(dblist, targname);
}
-static int process_target(char *target)
+static int process_target(const char *target)
{
/* process targets */
char *targstring = strdup(target);
@@ -709,14 +694,14 @@ static int process_target(char *target)
alpm_list_t *dblist = NULL;
if(targname) {
- pmdb_t *db = NULL;
+ alpm_db_t *db = NULL;
*targname = '\0';
targname++;
dbname = targstring;
db = get_db(dbname);
if(!db) {
- pm_fprintf(stderr, PM_LOG_ERROR, _("database not found: %s\n"),
+ pm_fprintf(stderr, ALPM_LOG_ERROR, _("database not found: %s\n"),
dbname);
ret = 1;
goto cleanup;
@@ -726,78 +711,81 @@ static int process_target(char *target)
alpm_list_free(dblist);
} else {
targname = targstring;
- dblist = alpm_option_get_syncdbs();
+ dblist = alpm_option_get_syncdbs(config->handle);
ret = process_targname(dblist, targname);
}
cleanup:
free(targstring);
- return(ret);
+ return ret;
}
static int sync_trans(alpm_list_t *targets)
{
- int retval = 0;
- alpm_list_t *data = NULL;
- alpm_list_t *packages = NULL;
alpm_list_t *i;
/* Step 1: create a new transaction... */
- if(trans_init(config->flags) == -1) {
- return(1);
+ if(trans_init(config->flags, 1) == -1) {
+ return 1;
}
/* process targets */
for(i = targets; i; i = alpm_list_next(i)) {
char *targ = alpm_list_getdata(i);
if(process_target(targ) == 1) {
- retval = 1;
- goto cleanup;
+ trans_release();
+ return 1;
}
}
if(config->op_s_upgrade) {
printf(_(":: Starting full system upgrade...\n"));
- alpm_logaction("starting full system upgrade\n");
- if(alpm_sync_sysupgrade(config->op_s_upgrade >= 2) == -1) {
- pm_fprintf(stderr, PM_LOG_ERROR, "%s\n", alpm_strerrorlast());
- retval = 1;
- goto cleanup;
+ alpm_logaction(config->handle, "starting full system upgrade\n");
+ if(alpm_sync_sysupgrade(config->handle, config->op_s_upgrade >= 2) == -1) {
+ pm_fprintf(stderr, ALPM_LOG_ERROR, "%s\n", alpm_strerror(alpm_errno(config->handle)));
+ trans_release();
+ return 1;
}
}
+ return sync_prepare_execute();
+}
+
+int sync_prepare_execute(void)
+{
+ alpm_list_t *i, *packages, *data = NULL;
+ int retval = 0;
+
/* Step 2: "compute" the transaction based on targets and flags */
- if(alpm_trans_prepare(&data) == -1) {
- pm_fprintf(stderr, PM_LOG_ERROR, _("failed to prepare transaction (%s)\n"),
- alpm_strerrorlast());
- switch(pm_errno) {
- alpm_list_t *i;
- case PM_ERR_PKG_INVALID_ARCH:
+ if(alpm_trans_prepare(config->handle, &data) == -1) {
+ enum _alpm_errno_t err = alpm_errno(config->handle);
+ pm_fprintf(stderr, ALPM_LOG_ERROR, _("failed to prepare transaction (%s)\n"),
+ alpm_strerror(err));
+ switch(err) {
+ case ALPM_ERR_PKG_INVALID_ARCH:
for(i = data; i; i = alpm_list_next(i)) {
char *pkg = alpm_list_getdata(i);
printf(_(":: package %s does not have a valid architecture\n"), pkg);
}
break;
- case PM_ERR_UNSATISFIED_DEPS:
+ case ALPM_ERR_UNSATISFIED_DEPS:
for(i = data; i; i = alpm_list_next(i)) {
- pmdepmissing_t *miss = alpm_list_getdata(i);
- pmdepend_t *dep = alpm_miss_get_dep(miss);
- char *depstring = alpm_dep_compute_string(dep);
- printf(_(":: %s: requires %s\n"), alpm_miss_get_target(miss),
- depstring);
+ alpm_depmissing_t *miss = alpm_list_getdata(i);
+ char *depstring = alpm_dep_compute_string(miss->depend);
+ printf(_(":: %s: requires %s\n"), miss->target, depstring);
free(depstring);
}
break;
- case PM_ERR_CONFLICTING_DEPS:
+ case ALPM_ERR_CONFLICTING_DEPS:
for(i = data; i; i = alpm_list_next(i)) {
- pmconflict_t *conflict = alpm_list_getdata(i);
- const char *package1 = alpm_conflict_get_package1(conflict);
- const char *package2 = alpm_conflict_get_package2(conflict);
- const char *reason = alpm_conflict_get_reason(conflict);
+ alpm_conflict_t *conflict = alpm_list_getdata(i);
/* only print reason if it contains new information */
- if(strcmp(package1, reason) == 0 || strcmp(package2, reason) == 0) {
- printf(_(":: %s and %s are in conflict\n"), package1, package2);
+ if(strcmp(conflict->package1, conflict->reason) == 0 ||
+ strcmp(conflict->package2, conflict->reason) == 0) {
+ printf(_(":: %s and %s are in conflict\n"),
+ conflict->package1, conflict->package2);
} else {
- printf(_(":: %s and %s are in conflict (%s)\n"), package1, package2, reason);
+ printf(_(":: %s and %s are in conflict (%s)\n"),
+ conflict->package1, conflict->package2, conflict->reason);
}
}
break;
@@ -808,7 +796,7 @@ static int sync_trans(alpm_list_t *targets)
goto cleanup;
}
- packages = alpm_trans_get_add();
+ packages = alpm_trans_get_add(config->handle);
if(packages == NULL) {
/* nothing to do: just exit without complaining */
printf(_(" there is nothing to do\n"));
@@ -821,8 +809,8 @@ static int sync_trans(alpm_list_t *targets)
goto cleanup;
}
- display_targets(alpm_trans_get_remove(), 0);
- display_targets(alpm_trans_get_add(), 1);
+ display_targets(alpm_trans_get_remove(config->handle), 0);
+ display_targets(alpm_trans_get_add(config->handle), 1);
printf("\n");
int confirm;
@@ -835,31 +823,28 @@ static int sync_trans(alpm_list_t *targets)
goto cleanup;
}
- if(alpm_trans_commit(&data) == -1) {
- pm_fprintf(stderr, PM_LOG_ERROR, _("failed to commit transaction (%s)\n"),
- alpm_strerrorlast());
- switch(pm_errno) {
- alpm_list_t *i;
- case PM_ERR_FILE_CONFLICTS:
+ if(alpm_trans_commit(config->handle, &data) == -1) {
+ enum _alpm_errno_t err = alpm_errno(config->handle);
+ pm_fprintf(stderr, ALPM_LOG_ERROR, _("failed to commit transaction (%s)\n"),
+ alpm_strerror(err));
+ switch(err) {
+ case ALPM_ERR_FILE_CONFLICTS:
for(i = data; i; i = alpm_list_next(i)) {
- pmfileconflict_t *conflict = alpm_list_getdata(i);
- switch(alpm_fileconflict_get_type(conflict)) {
- case PM_FILECONFLICT_TARGET:
+ alpm_fileconflict_t *conflict = alpm_list_getdata(i);
+ switch(conflict->type) {
+ case ALPM_FILECONFLICT_TARGET:
printf(_("%s exists in both '%s' and '%s'\n"),
- alpm_fileconflict_get_file(conflict),
- alpm_fileconflict_get_target(conflict),
- alpm_fileconflict_get_ctarget(conflict));
+ conflict->file, conflict->target, conflict->ctarget);
break;
- case PM_FILECONFLICT_FILESYSTEM:
+ case ALPM_FILECONFLICT_FILESYSTEM:
printf(_("%s: %s exists in filesystem\n"),
- alpm_fileconflict_get_target(conflict),
- alpm_fileconflict_get_file(conflict));
+ conflict->target, conflict->file);
break;
}
}
break;
- case PM_ERR_PKG_INVALID:
- case PM_ERR_DLT_INVALID:
+ case ALPM_ERR_PKG_INVALID:
+ case ALPM_ERR_DLT_INVALID:
for(i = data; i; i = alpm_list_next(i)) {
char *filename = alpm_list_getdata(i);
printf(_("%s is invalid or corrupted\n"), filename);
@@ -883,7 +868,7 @@ cleanup:
retval = 1;
}
- return(retval);
+ return retval;
}
int pacman_sync(alpm_list_t *targets)
@@ -894,8 +879,8 @@ int pacman_sync(alpm_list_t *targets)
if(config->op_s_clean) {
int ret = 0;
- if(trans_init(0) == -1) {
- return(1);
+ if(trans_init(0, 0) == -1) {
+ return 1;
}
ret += sync_cleancache(config->op_s_clean);
@@ -906,60 +891,63 @@ int pacman_sync(alpm_list_t *targets)
ret++;
}
- return(ret);
+ return ret;
}
- /* ensure we have at least one valid sync db set up */
- sync_dbs = alpm_option_get_syncdbs();
- if(sync_dbs == NULL || alpm_list_count(sync_dbs) == 0) {
- pm_printf(PM_LOG_ERROR, _("no usable package repositories configured.\n"));
- return(1);
+ if(check_syncdbs(1, 0)) {
+ return 1;
}
+ sync_dbs = alpm_option_get_syncdbs(config->handle);
+
if(config->op_s_sync) {
/* grab a fresh package list */
printf(_(":: Synchronizing package databases...\n"));
- alpm_logaction("synchronizing package lists\n");
+ alpm_logaction(config->handle, "synchronizing package lists\n");
if(!sync_synctree(config->op_s_sync, sync_dbs)) {
- return(1);
+ return 1;
}
}
+ if(check_syncdbs(1, 1)) {
+ return 1;
+ }
+
/* search for a package */
if(config->op_s_search) {
- return(sync_search(sync_dbs, targets));
+ return sync_search(sync_dbs, targets);
}
/* look for groups */
if(config->group) {
- return(sync_group(config->group, sync_dbs, targets));
+ return sync_group(config->group, sync_dbs, targets);
}
/* get package info */
if(config->op_s_info) {
- return(sync_info(sync_dbs, targets));
+ return sync_info(sync_dbs, targets);
}
/* get a listing of files in sync DBs */
if(config->op_q_list) {
- return(sync_list(sync_dbs, targets));
+ return sync_list(sync_dbs, targets);
}
if(targets == NULL) {
if(config->op_s_upgrade) {
/* proceed */
} else if(config->op_s_sync) {
- return(0);
+ return 0;
} else {
/* don't proceed here unless we have an operation that doesn't require a
* target list */
- pm_printf(PM_LOG_ERROR, _("no targets specified (use -h for help)\n"));
- return(1);
+ pm_printf(ALPM_LOG_ERROR, _("no targets specified (use -h for help)\n"));
+ return 1;
}
}
alpm_list_t *targs = alpm_list_strdup(targets);
- if(!(config->flags & PM_TRANS_FLAG_DOWNLOADONLY) && !config->print) {
+ if(!(config->flags & ALPM_TRANS_FLAG_DOWNLOADONLY) && !config->print) {
/* check for newer versions of packages to be upgraded first */
alpm_list_t *packages = syncfirst();
if(packages) {
@@ -980,7 +968,7 @@ int pacman_sync(alpm_list_t *targets)
}
printf("\n");
} else {
- pm_printf(PM_LOG_DEBUG, "skipping SyncFirst dialog\n");
+ pm_printf(ALPM_LOG_DEBUG, "skipping SyncFirst dialog\n");
FREELIST(packages);
}
}
@@ -989,7 +977,7 @@ int pacman_sync(alpm_list_t *targets)
int ret = sync_trans(targs);
FREELIST(targs);
- return(ret);
+ return ret;
}
/* vim: set ts=2 sw=2 noet: */