diff options
author | Dan McGee <dan@archlinux.org> | 2011-06-07 23:06:16 +0200 |
---|---|---|
committer | Dan McGee <dan@archlinux.org> | 2011-06-14 02:38:38 +0200 |
commit | e2aa952689da8763d534d1c19310eb97009f4f76 (patch) | |
tree | 7d022d67801bc01c24fef985feb9a617c48d316a /src | |
parent | 8b62d9bc0ade64897990b8fc6a1b6a54b629cb5b (diff) | |
download | pacman-e2aa952689da8763d534d1c19310eb97009f4f76.tar.gz pacman-e2aa952689da8763d534d1c19310eb97009f4f76.tar.xz |
Move pm_errno onto the handle
This involves some serious changes and a very messy diff, unfortunately.
Signed-off-by: Dan McGee <dan@archlinux.org>
Diffstat (limited to 'src')
-rw-r--r-- | src/pacman/conf.c | 10 | ||||
-rw-r--r-- | src/pacman/database.c | 2 | ||||
-rw-r--r-- | src/pacman/remove.c | 13 | ||||
-rw-r--r-- | src/pacman/sync.c | 28 | ||||
-rw-r--r-- | src/pacman/upgrade.c | 20 | ||||
-rw-r--r-- | src/pacman/util.c | 9 | ||||
-rw-r--r-- | src/util/cleanupdelta.c | 2 | ||||
-rw-r--r-- | src/util/pactree.c | 30 | ||||
-rw-r--r-- | src/util/testdb.c | 2 | ||||
-rw-r--r-- | src/util/testpkg.c | 5 |
10 files changed, 62 insertions, 59 deletions
diff --git a/src/pacman/conf.c b/src/pacman/conf.c index 1ee0444d..3b9dff78 100644 --- a/src/pacman/conf.c +++ b/src/pacman/conf.c @@ -402,7 +402,7 @@ static int _add_mirror(pmdb_t *db, char *value) if(alpm_db_add_server(db, server) != 0) { /* pm_errno is set by alpm_db_setserver */ pm_printf(PM_LOG_ERROR, _("could not add server URL to database '%s': %s (%s)\n"), - dbname, server, alpm_strerrorlast()); + dbname, server, alpm_strerror(alpm_errno(config->handle))); free(server); return 1; } @@ -460,7 +460,7 @@ static int setup_libalpm(void) ret = alpm_option_set_logfile(handle, config->logfile); if(ret != 0) { pm_printf(PM_LOG_ERROR, _("problem setting logfile '%s' (%s)\n"), - config->logfile, alpm_strerrorlast()); + config->logfile, alpm_strerror(alpm_errno(config->handle))); return ret; } @@ -470,7 +470,7 @@ static int setup_libalpm(void) ret = alpm_option_set_signaturedir(handle, config->gpgdir); if(ret != 0) { pm_printf(PM_LOG_ERROR, _("problem setting gpgdir '%s' (%s)\n"), - config->gpgdir, alpm_strerrorlast()); + config->gpgdir, alpm_strerror(alpm_errno(config->handle))); return ret; } @@ -567,7 +567,7 @@ static int _parseconfig(const char *file, int parse_options, db = alpm_db_register_sync(config->handle, name); if(db == NULL) { pm_printf(PM_LOG_ERROR, _("could not register '%s' database (%s)\n"), - name, alpm_strerrorlast()); + name, alpm_strerror(alpm_errno(config->handle))); ret = 1; goto cleanup; } @@ -665,7 +665,7 @@ static int _parseconfig(const char *file, int parse_options, ret = alpm_db_set_pgp_verify(db, level); if(ret != 0) { pm_printf(PM_LOG_ERROR, _("could not add set verify option for database '%s': %s (%s)\n"), - alpm_db_get_name(db), value, alpm_strerrorlast()); + alpm_db_get_name(db), value, alpm_strerror(alpm_errno(config->handle))); goto cleanup; } } else { diff --git a/src/pacman/database.c b/src/pacman/database.c index 33cd49e3..292fa54a 100644 --- a/src/pacman/database.c +++ b/src/pacman/database.c @@ -68,7 +68,7 @@ int pacman_database(alpm_list_t *targets) char *pkgname = i->data; if(alpm_db_set_pkgreason(db_local, pkgname, reason) == -1) { pm_printf(PM_LOG_ERROR, _("could not set install reason for package %s (%s)\n"), - pkgname, alpm_strerrorlast()); + pkgname, alpm_strerror(alpm_errno(config->handle))); retval = 1; } else { if(reason == PM_PKG_REASON_DEPEND) { diff --git a/src/pacman/remove.c b/src/pacman/remove.c index 6da3b044..8de538c8 100644 --- a/src/pacman/remove.c +++ b/src/pacman/remove.c @@ -39,7 +39,8 @@ static int remove_target(const char *target) if((info = alpm_db_get_pkg(db_local, target)) != NULL) { if(alpm_remove_pkg(config->handle, info) == -1) { - pm_fprintf(stderr, PM_LOG_ERROR, "'%s': %s\n", target, alpm_strerrorlast()); + pm_fprintf(stderr, PM_LOG_ERROR, "'%s': %s\n", target, + alpm_strerror(alpm_errno(config->handle))); return -1; } return 0; @@ -54,7 +55,8 @@ static int remove_target(const char *target) for(p = alpm_grp_get_pkgs(grp); p; p = alpm_list_next(p)) { pmpkg_t *pkg = alpm_list_getdata(p); if(alpm_remove_pkg(config->handle, pkg) == -1) { - pm_fprintf(stderr, PM_LOG_ERROR, "'%s': %s\n", target, alpm_strerrorlast()); + pm_fprintf(stderr, PM_LOG_ERROR, "'%s': %s\n", target, + alpm_strerror(alpm_errno(config->handle))); return -1; } } @@ -100,9 +102,10 @@ int pacman_remove(alpm_list_t *targets) /* Step 2: prepare the transaction based on its type, targets and flags */ if(alpm_trans_prepare(config->handle, &data) == -1) { + enum _pmerrno_t err = alpm_errno(config->handle); pm_fprintf(stderr, PM_LOG_ERROR, _("failed to prepare transaction (%s)\n"), - alpm_strerrorlast()); - switch(pm_errno) { + alpm_strerror(err)); + switch(err) { case PM_ERR_PKG_INVALID_ARCH: for(i = data; i; i = alpm_list_next(i)) { char *pkg = alpm_list_getdata(i); @@ -164,7 +167,7 @@ int pacman_remove(alpm_list_t *targets) if(alpm_trans_commit(config->handle, NULL) == -1) { pm_fprintf(stderr, PM_LOG_ERROR, _("failed to commit transaction (%s)\n"), - alpm_strerrorlast()); + alpm_strerror(alpm_errno(config->handle))); retval = 1; } diff --git a/src/pacman/sync.c b/src/pacman/sync.c index 77f6c45b..37b9d6e3 100644 --- a/src/pacman/sync.c +++ b/src/pacman/sync.c @@ -293,7 +293,7 @@ static int sync_synctree(int level, alpm_list_t *syncs) 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()); + 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++; @@ -623,14 +623,15 @@ static int process_pkg(pmpkg_t *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 _pmerrno_t err = alpm_errno(config->handle); + if(err == PM_ERR_TRANS_DUP_TARGET + || err == PM_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; } else { pm_fprintf(stderr, PM_LOG_ERROR, "'%s': %s\n", alpm_pkg_get_name(pkg), - alpm_strerrorlast()); + alpm_strerror(err)); return 1; } } @@ -687,10 +688,11 @@ static int process_targname(alpm_list_t *dblist, char *targname) { pmpkg_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) { + /* #FS#23342 - skip ignored packages when user says no */ + if(alpm_errno(config->handle) == PM_ERR_PKG_IGNORED) { pm_printf(PM_LOG_WARNING, _("skipping target: %s\n"), targname); - pm_errno = 0; + /* TODO how to do this, we shouldn't be fucking with it from the frontend */ + /* pm_errno = 0; */ return 0; } @@ -761,7 +763,7 @@ static int sync_trans(alpm_list_t *targets) printf(_(":: Starting full system upgrade...\n")); alpm_logaction(config->handle, "starting full system upgrade\n"); if(alpm_sync_sysupgrade(config->handle, config->op_s_upgrade >= 2) == -1) { - pm_fprintf(stderr, PM_LOG_ERROR, "%s\n", alpm_strerrorlast()); + pm_fprintf(stderr, PM_LOG_ERROR, "%s\n", alpm_strerror(alpm_errno(config->handle))); retval = 1; goto cleanup; } @@ -769,9 +771,10 @@ static int sync_trans(alpm_list_t *targets) /* Step 2: "compute" the transaction based on targets and flags */ if(alpm_trans_prepare(config->handle, &data) == -1) { + enum _pmerrno_t err = alpm_errno(config->handle); pm_fprintf(stderr, PM_LOG_ERROR, _("failed to prepare transaction (%s)\n"), - alpm_strerrorlast()); - switch(pm_errno) { + alpm_strerror(err)); + switch(err) { alpm_list_t *i; case PM_ERR_PKG_INVALID_ARCH: for(i = data; i; i = alpm_list_next(i)) { @@ -838,9 +841,10 @@ static int sync_trans(alpm_list_t *targets) } if(alpm_trans_commit(config->handle, &data) == -1) { + enum _pmerrno_t err = alpm_errno(config->handle); pm_fprintf(stderr, PM_LOG_ERROR, _("failed to commit transaction (%s)\n"), - alpm_strerrorlast()); - switch(pm_errno) { + alpm_strerror(err)); + switch(err) { alpm_list_t *i; case PM_ERR_FILE_CONFLICTS: for(i = data; i; i = alpm_list_next(i)) { diff --git a/src/pacman/upgrade.c b/src/pacman/upgrade.c index 8db88265..c0466456 100644 --- a/src/pacman/upgrade.c +++ b/src/pacman/upgrade.c @@ -57,7 +57,7 @@ int pacman_upgrade(alpm_list_t *targets) char *str = alpm_fetch_pkgurl(config->handle, i->data); if(str == NULL) { pm_fprintf(stderr, PM_LOG_ERROR, "'%s': %s\n", - (char *)i->data, alpm_strerrorlast()); + (char *)i->data, alpm_strerror(alpm_errno(config->handle))); return 1; } else { free(i->data); @@ -78,13 +78,13 @@ int pacman_upgrade(alpm_list_t *targets) if(alpm_pkg_load(config->handle, targ, 1, check_sig, &pkg) != 0) { pm_fprintf(stderr, PM_LOG_ERROR, "'%s': %s\n", - targ, alpm_strerrorlast()); + targ, alpm_strerror(alpm_errno(config->handle))); trans_release(); return 1; } if(alpm_add_pkg(config->handle, pkg) == -1) { pm_fprintf(stderr, PM_LOG_ERROR, "'%s': %s\n", - targ, alpm_strerrorlast()); + targ, alpm_strerror(alpm_errno(config->handle))); alpm_pkg_free(pkg); trans_release(); return 1; @@ -94,9 +94,10 @@ int pacman_upgrade(alpm_list_t *targets) /* Step 2: "compute" the transaction based on targets and flags */ /* TODO: No, compute nothing. This is stupid. */ if(alpm_trans_prepare(config->handle, &data) == -1) { + enum _pmerrno_t err = alpm_errno(config->handle); pm_fprintf(stderr, PM_LOG_ERROR, _("failed to prepare transaction (%s)\n"), - alpm_strerrorlast()); - switch(pm_errno) { + alpm_strerror(err)); + switch(err) { case PM_ERR_PKG_INVALID_ARCH: for(i = data; i; i = alpm_list_next(i)) { char *pkg = alpm_list_getdata(i); @@ -140,15 +141,15 @@ int pacman_upgrade(alpm_list_t *targets) } /* Step 3: perform the installation */ + alpm_list_t *packages = alpm_trans_get_add(config->handle); if(config->print) { - print_packages(alpm_trans_get_add(config->handle)); + print_packages(packages); trans_release(); return 0; } /* print targets and ask user confirmation */ - alpm_list_t *packages = alpm_trans_get_add(config->handle); if(packages == NULL) { /* we are done */ printf(_(" there is nothing to do\n")); trans_release(); @@ -164,9 +165,10 @@ int pacman_upgrade(alpm_list_t *targets) } if(alpm_trans_commit(config->handle, &data) == -1) { + enum _pmerrno_t err = alpm_errno(config->handle); pm_fprintf(stderr, PM_LOG_ERROR, _("failed to commit transaction (%s)\n"), - alpm_strerrorlast()); - switch(pm_errno) { + alpm_strerror(err)); + switch(err) { alpm_list_t *i; case PM_ERR_FILE_CONFLICTS: for(i = data; i; i = alpm_list_next(i)) { diff --git a/src/pacman/util.c b/src/pacman/util.c index af422fe9..a71c3cfd 100644 --- a/src/pacman/util.c +++ b/src/pacman/util.c @@ -60,14 +60,15 @@ int trans_init(pmtransflag_t flags) } if(ret == -1) { + enum _pmerrno_t err = alpm_errno(config->handle); pm_fprintf(stderr, PM_LOG_ERROR, _("failed to init transaction (%s)\n"), - alpm_strerrorlast()); - if(pm_errno == PM_ERR_HANDLE_LOCK) { + alpm_strerror(err)); + if(err == PM_ERR_HANDLE_LOCK) { fprintf(stderr, _(" if you're sure a package manager is not already\n" " running, you can remove %s\n"), alpm_option_get_lockfile(config->handle)); } - else if(pm_errno == PM_ERR_DB_VERSION) { + else if(err == PM_ERR_DB_VERSION) { fprintf(stderr, _(" try running pacman-db-upgrade\n")); } @@ -80,7 +81,7 @@ int trans_release(void) { if(alpm_trans_release(config->handle) == -1) { pm_fprintf(stderr, PM_LOG_ERROR, _("failed to release transaction (%s)\n"), - alpm_strerrorlast()); + alpm_strerror(alpm_errno(config->handle))); return -1; } return 0; diff --git a/src/util/cleanupdelta.c b/src/util/cleanupdelta.c index 5112b1a8..98291706 100644 --- a/src/util/cleanupdelta.c +++ b/src/util/cleanupdelta.c @@ -78,7 +78,7 @@ static void checkdbs(const char *dbpath, alpm_list_t *dbnames) { db = alpm_db_register_sync(handle, dbname); if(db == NULL) { fprintf(stderr, "error: could not register sync database (%s)\n", - alpm_strerrorlast()); + alpm_strerror(alpm_errno(handle))); return; } checkpkgs(alpm_db_get_pkgcache(db)); diff --git a/src/util/pactree.c b/src/util/pactree.c index 6c869426..1dee61bf 100644 --- a/src/util/pactree.c +++ b/src/util/pactree.c @@ -88,19 +88,6 @@ int reverse = 0; int unique = 0; const char *dbpath = DBPATH; -static int alpm_local_init(void) -{ - enum _pmerrno_t err; - - handle = alpm_initialize(ROOTDIR, dbpath, &err); - if(!handle) { - return -1; - } - - db_local = alpm_option_get_localdb(handle); - return 0; -} - static int parse_options(int argc, char *argv[]) { int opt, option_index = 0; @@ -327,22 +314,27 @@ static void walk_deps(pmpkg_t *pkg, int depth) int main(int argc, char *argv[]) { - int ret; + int ret = 0; + enum _pmerrno_t err; const char *target_name; pmpkg_t *pkg; - ret = parse_options(argc, argv); - if(ret != 0) { + if(parse_options(argc, argv) != 0) { usage(); + ret = 1; goto finish; } - ret = alpm_local_init(); - if(ret != 0) { - fprintf(stderr, "error: cannot initialize alpm: %s\n", alpm_strerrorlast()); + handle = alpm_initialize(ROOTDIR, dbpath, &err); + if(!handle) { + fprintf(stderr, "error: cannot initialize alpm: %s\n", + alpm_strerror(err)); + ret = 1; goto finish; } + db_local = alpm_option_get_localdb(handle); + /* we only care about the first non option arg for walking */ target_name = argv[optind]; diff --git a/src/util/testdb.c b/src/util/testdb.c index bda67d52..0bd78202 100644 --- a/src/util/testdb.c +++ b/src/util/testdb.c @@ -155,7 +155,7 @@ static int check_syncdbs(alpm_list_t *dbnames) { db = alpm_db_register_sync(handle, dbname); if(db == NULL) { fprintf(stderr, "error: could not register sync database (%s)\n", - alpm_strerrorlast()); + alpm_strerror(alpm_errno(handle))); ret = 1; goto cleanup; } diff --git a/src/util/testpkg.c b/src/util/testpkg.c index 5b8831de..c6f02e34 100644 --- a/src/util/testpkg.c +++ b/src/util/testpkg.c @@ -60,7 +60,8 @@ int main(int argc, char *argv[]) if(alpm_pkg_load(handle, argv[1], 1, PM_PGP_VERIFY_OPTIONAL, &pkg) == -1 || pkg == NULL) { - switch(pm_errno) { + enum _pmerrno_t err = alpm_errno(handle); + switch(err) { case PM_ERR_PKG_OPEN: printf("Cannot open the given file.\n"); break; @@ -69,7 +70,7 @@ int main(int argc, char *argv[]) printf("Package is invalid.\n"); break; default: - printf("libalpm error: %s\n", alpm_strerrorlast()); + printf("libalpm error: %s\n", alpm_strerror(err)); break; } retval = 1; |