Git-Url: http://git.frugalware.org/gitweb/gitweb.cgi?p=pacman-g2.git;a=commitdiff;h=455cd1d1a5d9e8ab4c8ed137802baa933413e1aa
commit 455cd1d1a5d9e8ab4c8ed137802baa933413e1aa Author: Michel Hermier <[email protected]> Date: Wed Aug 13 17:39:20 2014 +0200 pacman-g2: Move addpkg from add.c to trans.c diff --git a/src/pacman-g2/CMakeLists.txt b/src/pacman-g2/CMakeLists.txt index d9cf71c..f091dcf 100644 --- a/src/pacman-g2/CMakeLists.txt +++ b/src/pacman-g2/CMakeLists.txt @@ -1,5 +1,4 @@ set(PACMAN_SOURCES - add.c conf.c deptest.c download.c diff --git a/src/pacman-g2/add.c b/src/pacman-g2/add.c deleted file mode 100644 index 63058d6..0000000 --- a/src/pacman-g2/add.c +++ /dev/null @@ -1,174 +0,0 @@ -/* - * add.c - * - * Copyright (c) 2002-2006 by Judd Vinet <[email protected]> - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, - * USA. - */ - -#include "config.h" - -#include <stdlib.h> -#include <stdio.h> -#include <string.h> -#include <libintl.h> - -#include <pacman.h> - -/* pacman-g2 */ -#include "log.h" -#include "list.h" -#include "download.h" -#include "trans.h" -#include "add.h" -#include "conf.h" -#include "util.h" - -extern config_t *config; - -int addpkg(list_t *targets) -{ - PM_LIST *data; - list_t *i; - int retval = 0; - - if(targets == NULL) { - return(0); - } - - /* Check for URL targets and process them - */ - for(i = targets; i; i = i->next) { - if(strstr(i->data, "://")) { - char *str = pacman_fetch_pkgurl(i->data); - if(str == NULL) { - return(1); - } else { - free(i->data); - i->data = str; - } - } - } - - /* Step 1: create a new transaction - */ - if(pacman_trans_init((config->upgrade == 0) ? PM_TRANS_TYPE_ADD : PM_TRANS_TYPE_UPGRADE, - config->flags, cb_trans_evt, cb_trans_conv, cb_trans_progress) == -1) { - ERR(NL, "%s\n", pacman_strerror(pm_errno)); - if(pm_errno == PM_ERR_HANDLE_LOCK) { - MSG(NL, _(" if you're sure a package manager is not already running,\n" - " you can remove %s%s\n"), config->root, PM_LOCK); - } - return(1); - } - - /* and add targets to it */ - MSG(NL, _("loading package data... ")); - for(i = targets; i; i = i->next) { - if(pacman_trans_addtarget(i->data) == -1) { - ERR(NL, _("failed to add target '%s' (%s)\n"), (char *)i->data, pacman_strerror(pm_errno)); - retval = 1; - goto cleanup; - } - } - MSG(CL, _("done.\n")); - - /* Step 2: "compute" the transaction based on targets and flags - */ - if(pacman_trans_prepare(&data) == -1) { - long long *pkgsize, *freespace; - PM_LIST *lp; - - ERR(NL, _("failed to prepare transaction (%s)\n"), pacman_strerror(pm_errno)); - switch(pm_errno) { - case PM_ERR_UNSATISFIED_DEPS: - for(lp = pacman_list_first(data); lp; lp = pacman_list_next(lp)) { - PM_DEPMISS *miss = pacman_list_getdata(lp); - MSG(NL, _(":: %s: requires %s"), pacman_dep_getinfo(miss, PM_DEP_TARGET), - pacman_dep_getinfo(miss, PM_DEP_NAME)); - switch((long)pacman_dep_getinfo(miss, PM_DEP_MOD)) { - case PM_DEP_MOD_EQ: MSG(CL, "=%s", pacman_dep_getinfo(miss, PM_DEP_VERSION)); break; - case PM_DEP_MOD_GE: MSG(CL, ">=%s", pacman_dep_getinfo(miss, PM_DEP_VERSION)); break; - case PM_DEP_MOD_LE: MSG(CL, "<=%s", pacman_dep_getinfo(miss, PM_DEP_VERSION)); break; - } - MSG(CL, "\n"); - } - pacman_list_free(data); - break; - case PM_ERR_CONFLICTING_DEPS: - for(lp = pacman_list_first(data); lp; lp = pacman_list_next(lp)) { - PM_DEPMISS *miss = pacman_list_getdata(lp); - MSG(NL, _(":: %s: conflicts with %s"), - pacman_dep_getinfo(miss, PM_DEP_TARGET), pacman_dep_getinfo(miss, PM_DEP_NAME)); - } - pacman_list_free(data); - break; - case PM_ERR_FILE_CONFLICTS: - for(lp = pacman_list_first(data); lp; lp = pacman_list_next(lp)) { - PM_CONFLICT *conflict = pacman_list_getdata(lp); - switch((long)pacman_conflict_getinfo(conflict, PM_CONFLICT_TYPE)) { - case PM_CONFLICT_TYPE_TARGET: - MSG(NL, _("%s%s exists in \"%s\" (target) and \"%s\" (target)"), - config->root, - (char *)pacman_conflict_getinfo(conflict, PM_CONFLICT_FILE), - (char *)pacman_conflict_getinfo(conflict, PM_CONFLICT_TARGET), - (char *)pacman_conflict_getinfo(conflict, PM_CONFLICT_CTARGET)); - break; - case PM_CONFLICT_TYPE_FILE: - MSG(NL, _("%s: %s%s exists in filesystem"), - (char *)pacman_conflict_getinfo(conflict, PM_CONFLICT_TARGET), - config->root, - (char *)pacman_conflict_getinfo(conflict, PM_CONFLICT_FILE)); - break; - } - } - pacman_list_free(data); - MSG(NL, _("\nerrors occurred, no packages were upgraded.\n")); - break; - case PM_ERR_DISK_FULL: - lp = pacman_list_first(data); - pkgsize = pacman_list_getdata(lp); - lp = pacman_list_next(lp); - freespace = pacman_list_getdata(lp); - MSG(NL, _(":: %.1f MB required, have %.1f MB"), - (double)(*pkgsize / 1048576.0), (double)(*freespace / 1048576.0)); - pacman_list_free(data); - break; - default: - break; - } - retval=1; - goto cleanup; - } - - /* Step 3: actually perform the installation - */ - if(pacman_trans_commit(NULL) == -1) { - ERR(NL, _("failed to commit transaction (%s)\n"), pacman_strerror(pm_errno)); - retval=1; - goto cleanup; - } - -cleanup: - if(pacman_trans_release() == -1) { - ERR(NL, _("failed to release transaction (%s)\n"), pacman_strerror(pm_errno)); - retval=1; - } - - return(retval); -} - -/* vim: set ts=2 sw=2 noet: */ diff --git a/src/pacman-g2/add.h b/src/pacman-g2/add.h deleted file mode 100644 index 311bf98..0000000 --- a/src/pacman-g2/add.h +++ /dev/null @@ -1,28 +0,0 @@ -/* - * add.h - * - * Copyright (c) 2002-2006 by Judd Vinet <[email protected]> - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, - * USA. - */ -#ifndef _PM_ADD_H -#define _PM_ADD_H - -int addpkg(list_t *targets); - -#endif /* _PM_ADD_H */ - -/* vim: set ts=2 sw=2 noet: */ diff --git a/src/pacman-g2/pacman-g2.c b/src/pacman-g2/pacman-g2.c index 547f578..e463da8 100644 --- a/src/pacman-g2/pacman-g2.c +++ b/src/pacman-g2/pacman-g2.c @@ -41,7 +41,6 @@ #include "download.h" #include "conf.h" #include "package.h" -#include "add.h" #include "remove.h" #include "upgrade.h" #include "query.h" diff --git a/src/pacman-g2/trans.c b/src/pacman-g2/trans.c index ea6699b..0713786 100644 --- a/src/pacman-g2/trans.c +++ b/src/pacman-g2/trans.c @@ -378,4 +378,136 @@ cleanup: FREE(pkgname_short); } +int addpkg(list_t *targets) +{ + PM_LIST *data; + list_t *i; + int retval = 0; + + if(targets == NULL) { + return(0); + } + + /* Check for URL targets and process them + */ + for(i = targets; i; i = i->next) { + if(strstr(i->data, "://")) { + char *str = pacman_fetch_pkgurl(i->data); + if(str == NULL) { + return(1); + } else { + free(i->data); + i->data = str; + } + } + } + + /* Step 1: create a new transaction + */ + if(pacman_trans_init((config->upgrade == 0) ? PM_TRANS_TYPE_ADD : PM_TRANS_TYPE_UPGRADE, + config->flags, cb_trans_evt, cb_trans_conv, cb_trans_progress) == -1) { + ERR(NL, "%s\n", pacman_strerror(pm_errno)); + if(pm_errno == PM_ERR_HANDLE_LOCK) { + MSG(NL, _(" if you're sure a package manager is not already running,\n" + " you can remove %s%s\n"), config->root, PM_LOCK); + } + return(1); + } + + /* and add targets to it */ + MSG(NL, _("loading package data... ")); + for(i = targets; i; i = i->next) { + if(pacman_trans_addtarget(i->data) == -1) { + ERR(NL, _("failed to add target '%s' (%s)\n"), (char *)i->data, pacman_strerror(pm_errno)); + retval = 1; + goto cleanup; + } + } + MSG(CL, _("done.\n")); + + /* Step 2: "compute" the transaction based on targets and flags + */ + if(pacman_trans_prepare(&data) == -1) { + long long *pkgsize, *freespace; + PM_LIST *lp; + + ERR(NL, _("failed to prepare transaction (%s)\n"), pacman_strerror(pm_errno)); + switch(pm_errno) { + case PM_ERR_UNSATISFIED_DEPS: + for(lp = pacman_list_first(data); lp; lp = pacman_list_next(lp)) { + PM_DEPMISS *miss = pacman_list_getdata(lp); + MSG(NL, _(":: %s: requires %s"), pacman_dep_getinfo(miss, PM_DEP_TARGET), + pacman_dep_getinfo(miss, PM_DEP_NAME)); + switch((long)pacman_dep_getinfo(miss, PM_DEP_MOD)) { + case PM_DEP_MOD_EQ: MSG(CL, "=%s", pacman_dep_getinfo(miss, PM_DEP_VERSION)); break; + case PM_DEP_MOD_GE: MSG(CL, ">=%s", pacman_dep_getinfo(miss, PM_DEP_VERSION)); break; + case PM_DEP_MOD_LE: MSG(CL, "<=%s", pacman_dep_getinfo(miss, PM_DEP_VERSION)); break; + } + MSG(CL, "\n"); + } + pacman_list_free(data); + break; + case PM_ERR_CONFLICTING_DEPS: + for(lp = pacman_list_first(data); lp; lp = pacman_list_next(lp)) { + PM_DEPMISS *miss = pacman_list_getdata(lp); + MSG(NL, _(":: %s: conflicts with %s"), + pacman_dep_getinfo(miss, PM_DEP_TARGET), pacman_dep_getinfo(miss, PM_DEP_NAME)); + } + pacman_list_free(data); + break; + case PM_ERR_FILE_CONFLICTS: + for(lp = pacman_list_first(data); lp; lp = pacman_list_next(lp)) { + PM_CONFLICT *conflict = pacman_list_getdata(lp); + switch((long)pacman_conflict_getinfo(conflict, PM_CONFLICT_TYPE)) { + case PM_CONFLICT_TYPE_TARGET: + MSG(NL, _("%s%s exists in \"%s\" (target) and \"%s\" (target)"), + config->root, + (char *)pacman_conflict_getinfo(conflict, PM_CONFLICT_FILE), + (char *)pacman_conflict_getinfo(conflict, PM_CONFLICT_TARGET), + (char *)pacman_conflict_getinfo(conflict, PM_CONFLICT_CTARGET)); + break; + case PM_CONFLICT_TYPE_FILE: + MSG(NL, _("%s: %s%s exists in filesystem"), + (char *)pacman_conflict_getinfo(conflict, PM_CONFLICT_TARGET), + config->root, + (char *)pacman_conflict_getinfo(conflict, PM_CONFLICT_FILE)); + break; + } + } + pacman_list_free(data); + MSG(NL, _("\nerrors occurred, no packages were upgraded.\n")); + break; + case PM_ERR_DISK_FULL: + lp = pacman_list_first(data); + pkgsize = pacman_list_getdata(lp); + lp = pacman_list_next(lp); + freespace = pacman_list_getdata(lp); + MSG(NL, _(":: %.1f MB required, have %.1f MB"), + (double)(*pkgsize / 1048576.0), (double)(*freespace / 1048576.0)); + pacman_list_free(data); + break; + default: + break; + } + retval=1; + goto cleanup; + } + + /* Step 3: actually perform the installation + */ + if(pacman_trans_commit(NULL) == -1) { + ERR(NL, _("failed to commit transaction (%s)\n"), pacman_strerror(pm_errno)); + retval=1; + goto cleanup; + } + +cleanup: + if(pacman_trans_release() == -1) { + ERR(NL, _("failed to release transaction (%s)\n"), pacman_strerror(pm_errno)); + retval=1; + } + + return(retval); +} + /* vim: set ts=2 sw=2 noet: */ diff --git a/src/pacman-g2/trans.h b/src/pacman-g2/trans.h index da85293..6227279 100644 --- a/src/pacman-g2/trans.h +++ b/src/pacman-g2/trans.h @@ -33,6 +33,8 @@ void cb_trans_conv(unsigned char event, void *data1, void *data2, void *data3, i void cb_trans_progress(unsigned char event, const char *pkgname, int percent, int howmany, int remain); +int addpkg(list_t *targets); + #endif /* _PM_TRANS_H */ /* vim: set ts=2 sw=2 noet: */ diff --git a/src/pacman-g2/upgrade.c b/src/pacman-g2/upgrade.c index 48a1d05..831742c 100644 --- a/src/pacman-g2/upgrade.c +++ b/src/pacman-g2/upgrade.c @@ -26,7 +26,7 @@ #include <pacman.h> /* pacman-g2 */ #include "list.h" -#include "add.h" +#include "trans.h" #include "upgrade.h" #include "conf.h" _______________________________________________ Frugalware-git mailing list [email protected] http://frugalware.org/mailman/listinfo/frugalware-git
