Git-Url: 
http://git.frugalware.org/gitweb/gitweb.cgi?p=pacman-g2.git;a=commitdiff;h=9e4651faaf136126908dd07720e6fc3a73368e69

commit 9e4651faaf136126908dd07720e6fc3a73368e69
Author: Michel Hermier <herm...@frugalware.org>
Date:   Mon Aug 1 08:18:36 2011 +0200

sync.c: Move sysupgrace code to trans_sysupgrade.c (will be a trans on it's own 
in the future).

diff --git a/lib/libpacman/Makefile.am b/lib/libpacman/Makefile.am
index 60d6948..43deba8 100644
--- a/lib/libpacman/Makefile.am
+++ b/lib/libpacman/Makefile.am
@@ -24,6 +24,7 @@ TARGETS = md5driver.c \
versioncmp.c \
backup.c \
trans.c \
+       trans_sysupgrade.c \
add.c \
remove.c \
sync.c \
diff --git a/lib/libpacman/handle.h b/lib/libpacman/handle.h
index ec94d30..f5d7276 100644
--- a/lib/libpacman/handle.h
+++ b/lib/libpacman/handle.h
@@ -22,6 +22,8 @@
#define _PACMAN_HANDLE_H

#include <stdio.h>
+#include <time.h>
+#include <unistd.h>

#include "pacman.h"

diff --git a/lib/libpacman/sync.c b/lib/libpacman/sync.c
index 0757651..98496ce 100644
--- a/lib/libpacman/sync.c
+++ b/lib/libpacman/sync.c
@@ -89,7 +89,7 @@ void _pacman_sync_free(void *data)
/* Test for existence of a package in a pmlist_t* of pmsyncpkg_t*
* If found, return a pointer to the respective pmsyncpkg_t*
*/
-static pmsyncpkg_t *find_pkginsync(char *needle, pmlist_t *haystack)
+pmsyncpkg_t *find_pkginsync(char *needle, pmlist_t *haystack)
{
pmlist_t *i;
pmsyncpkg_t *ps;
@@ -113,148 +113,6 @@ static int istoonew(pmpkg_t *pkg)
return((pkg->date + handle->upgradedelay) > t);
}

-int _pacman_sync_sysupgrade(pmtrans_t *trans, pmdb_t *db_local, pmlist_t 
*dbs_sync)
-{
-       pmlist_t *i, *j, *k;
-
-       /* this is a sysupgrade, so that install reasons are not touched */
-       handle->sysupgrade = 1;
-
-       /* check for "recommended" package replacements */
-       _pacman_log(PM_LOG_FLOW1, _("checking for package replacements"));
-       for(i = dbs_sync; i; i = i->next) {
-               for(j = _pacman_db_get_pkgcache(i->data); j; j = j->next) {
-                       pmpkg_t *spkg = j->data;
-                       for(k = _pacman_pkg_getinfo(spkg, PM_PKG_REPLACES); k; 
k = k->next) {
-                               pmlist_t *m;
-                               for(m = _pacman_db_get_pkgcache(db_local); m; m 
= m->next) {
-                                       pmpkg_t *lpkg = m->data;
-                                       if(!strcmp(k->data, lpkg->name)) {
-                                               _pacman_log(PM_LOG_DEBUG, 
_("checking replacement '%s' for package '%s'"), k->data, spkg->name);
-                                               
if(_pacman_list_is_strin(lpkg->name, handle->ignorepkg)) {
-                                                       
_pacman_log(PM_LOG_WARNING, _("%s-%s: ignoring package upgrade (to be replaced 
by %s-%s)"),
-                                                               lpkg->name, 
lpkg->version, spkg->name, spkg->version);
-                                               } else {
-                                                       /* get confirmation for 
the replacement */
-                                                       int doreplace = 0;
-                                                       QUESTION(trans, 
PM_TRANS_CONV_REPLACE_PKG, lpkg, spkg, ((pmdb_t *)i->data)->treename, 
&doreplace);
-
-                                                       if(doreplace) {
-                                                               /* if 
confirmed, add this to the 'final' list, designating 'lpkg' as
-                                                                * the package 
to replace.
-                                                                */
-                                                               pmsyncpkg_t *ps;
-                                                               pmpkg_t *dummy 
= _pacman_pkg_new(lpkg->name, NULL);
-                                                               if(dummy == 
NULL) {
-                                                                       
pm_errno = PM_ERR_MEMORY;
-                                                                       goto 
error;
-                                                               }
-                                                               
dummy->requiredby = _pacman_list_strdup(lpkg->requiredby);
-                                                               /* check if 
spkg->name is already in the packages list. */
-                                                               ps = 
find_pkginsync(spkg->name, trans->packages);
-                                                               if(ps) {
-                                                                       /* 
found it -- just append to the replaces list */
-                                                                       
ps->data = _pacman_list_add(ps->data, dummy);
-                                                               } else {
-                                                                       /* none 
found -- enter pkg into the final sync list */
-                                                                       ps = 
_pacman_sync_new(PM_SYNC_TYPE_REPLACE, spkg, NULL);
-                                                                       if(ps 
== NULL) {
-                                                                               
FREEPKG(dummy);
-                                                                               
pm_errno = PM_ERR_MEMORY;
-                                                                               
goto error;
-                                                                       }
-                                                                       
ps->data = _pacman_list_add(NULL, dummy);
-                                                                       
trans->packages = _pacman_list_add(trans->packages, ps);
-                                                               }
-                                                               
_pacman_log(PM_LOG_FLOW2, _("%s-%s elected for upgrade (to be replaced by 
%s-%s)"),
-                                                                         
lpkg->name, lpkg->version, spkg->name, spkg->version);
-                                                       }
-                                               }
-                                               break;
-                                       }
-                               }
-                       }
-               }
-       }
-
-       /* match installed packages with the sync dbs and compare versions */
-       _pacman_log(PM_LOG_FLOW1, _("checking for package upgrades"));
-       for(i = _pacman_db_get_pkgcache(db_local); i; i = i->next) {
-               int cmp;
-               int replace=0;
-               pmpkg_t *local = i->data;
-               pmpkg_t *spkg = NULL;
-               pmsyncpkg_t *ps;
-
-               for(j = dbs_sync; !spkg && j; j = j->next) {
-                       spkg = _pacman_db_get_pkgfromcache(j->data, 
local->name);
-               }
-               if(spkg == NULL) {
-                       _pacman_log(PM_LOG_DEBUG, _("'%s' not found in sync db 
-- skipping"), local->name);
-                       continue;
-               }
-
-               /* we don't care about a to-be-replaced package's newer version 
*/
-               for(j = trans->packages; j && !replace; j=j->next) {
-                       ps = j->data;
-                       if(ps->type == PM_SYNC_TYPE_REPLACE) {
-                               if(_pacman_pkg_isin(spkg->name, ps->data)) {
-                                       replace=1;
-                               }
-                       }
-               }
-               if(replace) {
-                       _pacman_log(PM_LOG_DEBUG, _("'%s' is already elected 
for removal -- skipping"),
-                                                               local->name);
-                       continue;
-               }
-
-               /* compare versions and see if we need to upgrade */
-               cmp = _pacman_versioncmp(local->version, spkg->version);
-               if(cmp > 0 && !_pacman_pkg_getinfo(spkg, PM_PKG_FORCE)) {
-                       /* local version is newer */
-                       _pacman_log(PM_LOG_WARNING, _("%s-%s: local version is 
newer"),
-                               local->name, local->version);
-               } else if(cmp == 0) {
-                       /* versions are identical */
-               } else if(_pacman_list_is_strin(i->data, handle->ignorepkg)) {
-                       /* package should be ignored (IgnorePkg) */
-                       _pacman_log(PM_LOG_WARNING, _("%s-%s: ignoring package 
upgrade (%s)"),
-                               local->name, local->version, spkg->version);
-               } else if(istoonew(spkg)) {
-                       /* package too new (UpgradeDelay) */
-                       _pacman_log(PM_LOG_FLOW1, _("%s-%s: delaying upgrade of 
package (%s)\n"),
-                                       local->name, local->version, 
spkg->version);
-               } else if(_pacman_pkg_getinfo(spkg, PM_PKG_STICK)) {
-                       _pacman_log(PM_LOG_WARNING, _("%s-%s: please upgrade 
manually (%s => %s)"),
-                               local->name, local->version, local->version, 
spkg->version);
-               } else {
-                       _pacman_log(PM_LOG_FLOW2, _("%s-%s elected for upgrade 
(%s => %s)"),
-                               local->name, local->version, local->version, 
spkg->version);
-                       /* check if spkg->name is already in the packages list. 
*/
-                       if(!find_pkginsync(spkg->name, trans->packages)) {
-                               pmpkg_t *dummy = _pacman_pkg_new(local->name, 
local->version);
-                               if(dummy == NULL) {
-                                       goto error;
-                               }
-                               ps = _pacman_sync_new(PM_SYNC_TYPE_UPGRADE, 
spkg, dummy);
-                               if(ps == NULL) {
-                                       FREEPKG(dummy);
-                                       goto error;
-                               }
-                               trans->packages = 
_pacman_list_add(trans->packages, ps);
-                       } else {
-                               /* spkg->name is already in the packages list 
-- just ignore it */
-                       }
-               }
-       }
-
-       return(0);
-
-error:
-       return(-1);
-}
-
int _pacman_sync_addtarget(pmtrans_t *trans, const char *name)
{
char targline[PKG_FULLNAME_LEN];
diff --git a/lib/libpacman/sync.h b/lib/libpacman/sync.h
index cd28992..55c6ae0 100644
--- a/lib/libpacman/sync.h
+++ b/lib/libpacman/sync.h
@@ -37,8 +37,7 @@ typedef struct __pmsyncpkg_t {

pmsyncpkg_t *_pacman_sync_new(int type, pmpkg_t *spkg, void *data);
void _pacman_sync_free(void *data);
-
-int _pacman_sync_sysupgrade(pmtrans_t *trans, pmdb_t *db_local, pmlist_t 
*dbs_sync);
+pmsyncpkg_t *find_pkginsync(char *needle, pmlist_t *haystack);

const pmtrans_ops_t _pacman_sync_pmtrans_opts;

diff --git a/lib/libpacman/trans.c b/lib/libpacman/trans.c
index 357444e..6d43a80 100644
--- a/lib/libpacman/trans.c
+++ b/lib/libpacman/trans.c
@@ -40,6 +40,8 @@
#include "cache.h"
#include "pacman.h"

+#include "trans_sysupgrade.h"
+
static int check_oldcache(void)
{
pmdb_t *db = handle->db_local;
diff --git a/lib/libpacman/trans_sysupgrade.c b/lib/libpacman/trans_sysupgrade.c
new file mode 100644
index 0000000..1cc7e2f
--- /dev/null
+++ b/lib/libpacman/trans_sysupgrade.c
@@ -0,0 +1,214 @@
+/*
+ *  trans_sysupgrade.c
+ *
+ *  Copyright (c) 2002-2006 by Judd Vinet <jvi...@zeroflux.org>
+ *  Copyright (c) 2005 by Aurelien Foret <orel...@chez.com>
+ *  Copyright (c) 2005 by Christian Hamar <kr...@linuxforum.hu>
+ *  Copyright (c) 2005-2008 by Miklos Vajna <vmik...@frugalware.org>
+ *
+ *  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 <fcntl.h>
+#include <string.h>
+#include <time.h>
+#ifdef CYGWIN
+#include <limits.h> /* PATH_MAX */
+#endif
+#include <dirent.h>
+#include <libintl.h>
+/* pacman-g2 */
+#include "log.h"
+#include "error.h"
+#include "list.h"
+#include "package.h"
+#include "db.h"
+#include "cache.h"
+#include "deps.h"
+#include "conflict.h"
+#include "provide.h"
+#include "trans.h"
+#include "util.h"
+#include "sync.h"
+#include "versioncmp.h"
+#include "handle.h"
+#include "util.h"
+#include "pacman.h"
+#include "md5.h"
+#include "sha1.h"
+#include "handle.h"
+#include "server.h"
+
+#include "trans_sysupgrade.h"
+
+#include "sync.h"
+
+static int istoonew(pmpkg_t *pkg)
+{
+       time_t t;
+       if (!handle->upgradedelay)
+               return 0;
+       time(&t);
+       return((pkg->date + handle->upgradedelay) > t);
+}
+
+int _pacman_sync_sysupgrade(pmtrans_t *trans, pmdb_t *db_local, pmlist_t 
*dbs_sync)
+{
+       pmlist_t *i, *j, *k;
+
+       /* this is a sysupgrade, so that install reasons are not touched */
+       handle->sysupgrade = 1;
+
+       /* check for "recommended" package replacements */
+       _pacman_log(PM_LOG_FLOW1, _("checking for package replacements"));
+       for(i = dbs_sync; i; i = i->next) {
+               for(j = _pacman_db_get_pkgcache(i->data); j; j = j->next) {
+                       pmpkg_t *spkg = j->data;
+                       for(k = _pacman_pkg_getinfo(spkg, PM_PKG_REPLACES); k; 
k = k->next) {
+                               pmlist_t *m;
+                               for(m = _pacman_db_get_pkgcache(db_local); m; m 
= m->next) {
+                                       pmpkg_t *lpkg = m->data;
+                                       if(!strcmp(k->data, lpkg->name)) {
+                                               _pacman_log(PM_LOG_DEBUG, 
_("checking replacement '%s' for package '%s'"), k->data, spkg->name);
+                                               
if(_pacman_list_is_strin(lpkg->name, handle->ignorepkg)) {
+                                                       
_pacman_log(PM_LOG_WARNING, _("%s-%s: ignoring package upgrade (to be replaced 
by %s-%s)"),
+                                                               lpkg->name, 
lpkg->version, spkg->name, spkg->version);
+                                               } else {
+                                                       /* get confirmation for 
the replacement */
+                                                       int doreplace = 0;
+                                                       QUESTION(trans, 
PM_TRANS_CONV_REPLACE_PKG, lpkg, spkg, ((pmdb_t *)i->data)->treename, 
&doreplace);
+
+                                                       if(doreplace) {
+                                                               /* if 
confirmed, add this to the 'final' list, designating 'lpkg' as
+                                                                * the package 
to replace.
+                                                                */
+                                                               pmsyncpkg_t *ps;
+                                                               pmpkg_t *dummy 
= _pacman_pkg_new(lpkg->name, NULL);
+                                                               if(dummy == 
NULL) {
+                                                                       
pm_errno = PM_ERR_MEMORY;
+                                                                       goto 
error;
+                                                               }
+                                                               
dummy->requiredby = _pacman_list_strdup(lpkg->requiredby);
+                                                               /* check if 
spkg->name is already in the packages list. */
+                                                               ps = 
find_pkginsync(spkg->name, trans->packages);
+                                                               if(ps) {
+                                                                       /* 
found it -- just append to the replaces list */
+                                                                       
ps->data = _pacman_list_add(ps->data, dummy);
+                                                               } else {
+                                                                       /* none 
found -- enter pkg into the final sync list */
+                                                                       ps = 
_pacman_sync_new(PM_SYNC_TYPE_REPLACE, spkg, NULL);
+                                                                       if(ps 
== NULL) {
+                                                                               
FREEPKG(dummy);
+                                                                               
pm_errno = PM_ERR_MEMORY;
+                                                                               
goto error;
+                                                                       }
+                                                                       
ps->data = _pacman_list_add(NULL, dummy);
+                                                                       
trans->packages = _pacman_list_add(trans->packages, ps);
+                                                               }
+                                                               
_pacman_log(PM_LOG_FLOW2, _("%s-%s elected for upgrade (to be replaced by 
%s-%s)"),
+                                                                         
lpkg->name, lpkg->version, spkg->name, spkg->version);
+                                                       }
+                                               }
+                                               break;
+                                       }
+                               }
+                       }
+               }
+       }
+
+       /* match installed packages with the sync dbs and compare versions */
+       _pacman_log(PM_LOG_FLOW1, _("checking for package upgrades"));
+       for(i = _pacman_db_get_pkgcache(db_local); i; i = i->next) {
+               int cmp;
+               int replace=0;
+               pmpkg_t *local = i->data;
+               pmpkg_t *spkg = NULL;
+               pmsyncpkg_t *ps;
+
+               for(j = dbs_sync; !spkg && j; j = j->next) {
+                       spkg = _pacman_db_get_pkgfromcache(j->data, 
local->name);
+               }
+               if(spkg == NULL) {
+                       _pacman_log(PM_LOG_DEBUG, _("'%s' not found in sync db 
-- skipping"), local->name);
+                       continue;
+               }
+
+               /* we don't care about a to-be-replaced package's newer version 
*/
+               for(j = trans->packages; j && !replace; j=j->next) {
+                       ps = j->data;
+                       if(ps->type == PM_SYNC_TYPE_REPLACE) {
+                               if(_pacman_pkg_isin(spkg->name, ps->data)) {
+                                       replace=1;
+                               }
+                       }
+               }
+               if(replace) {
+                       _pacman_log(PM_LOG_DEBUG, _("'%s' is already elected 
for removal -- skipping"),
+                                                               local->name);
+                       continue;
+               }
+
+               /* compare versions and see if we need to upgrade */
+               cmp = _pacman_versioncmp(local->version, spkg->version);
+               if(cmp > 0 && !_pacman_pkg_getinfo(spkg, PM_PKG_FORCE)) {
+                       /* local version is newer */
+                       _pacman_log(PM_LOG_WARNING, _("%s-%s: local version is 
newer"),
+                               local->name, local->version);
+               } else if(cmp == 0) {
+                       /* versions are identical */
+               } else if(_pacman_list_is_strin(i->data, handle->ignorepkg)) {
+                       /* package should be ignored (IgnorePkg) */
+                       _pacman_log(PM_LOG_WARNING, _("%s-%s: ignoring package 
upgrade (%s)"),
+                               local->name, local->version, spkg->version);
+               } else if(istoonew(spkg)) {
+                       /* package too new (UpgradeDelay) */
+                       _pacman_log(PM_LOG_FLOW1, _("%s-%s: delaying upgrade of 
package (%s)\n"),
+                                       local->name, local->version, 
spkg->version);
+               } else if(_pacman_pkg_getinfo(spkg, PM_PKG_STICK)) {
+                       _pacman_log(PM_LOG_WARNING, _("%s-%s: please upgrade 
manually (%s => %s)"),
+                               local->name, local->version, local->version, 
spkg->version);
+               } else {
+                       _pacman_log(PM_LOG_FLOW2, _("%s-%s elected for upgrade 
(%s => %s)"),
+                               local->name, local->version, local->version, 
spkg->version);
+                       /* check if spkg->name is already in the packages list. 
*/
+                       if(!find_pkginsync(spkg->name, trans->packages)) {
+                               pmpkg_t *dummy = _pacman_pkg_new(local->name, 
local->version);
+                               if(dummy == NULL) {
+                                       goto error;
+                               }
+                               ps = _pacman_sync_new(PM_SYNC_TYPE_UPGRADE, 
spkg, dummy);
+                               if(ps == NULL) {
+                                       FREEPKG(dummy);
+                                       goto error;
+                               }
+                               trans->packages = 
_pacman_list_add(trans->packages, ps);
+                       } else {
+                               /* spkg->name is already in the packages list 
-- just ignore it */
+                       }
+               }
+       }
+
+       return(0);
+
+error:
+       return(-1);
+}
+
+/* vim: set ts=2 sw=2 noet: */
_______________________________________________
Frugalware-git mailing list
Frugalware-git@frugalware.org
http://frugalware.org/mailman/listinfo/frugalware-git

Reply via email to