>From f6af53eed61c3088d756cba021b03266a0702ce8 Mon Sep 17 00:00:00 2001
From: Nagy Gabor <[EMAIL PROTECTED]>
Date: Sun, 24 Aug 2008 23:24:53 +0200
Subject: [PATCH] HoldPkg rework

The HoldPkg feature is even more important when the packages to be held are
pulled automatically by pacman, in a -Rc and -Rs operation. Before, it only
applied when the packages were explicitly requested by the user to be
removed. This patch extends holdpkg to -Rc and -Rs by doing the HoldPkg
check just before trans_commit.

Additionally, the whole HoldPkg stuff was moved to the front-end.

I changed the default behavior to "don't remove", so I modified remove030.py
pactest as well.

See also: FS#9173.

Original-work-by: Xavier Chantry <[EMAIL PROTECTED]>
Signed-off-by: Nagy Gabor <[EMAIL PROTECTED]>
---
 lib/libalpm/alpm.h         |   10 +---------
 lib/libalpm/error.c        |    3 ---
 lib/libalpm/handle.c       |   32 --------------------------------
 lib/libalpm/handle.h       |    1 -
 lib/libalpm/remove.c       |   10 ----------
 pactest/tests/remove030.py |    6 ++----
 src/pacman/callback.c      |    4 ----
 src/pacman/conf.c          |    2 ++
 src/pacman/conf.h          |    1 +
 src/pacman/pacman.c        |    7 ++++++-
 src/pacman/remove.c        |   15 +++++++++++++++
 11 files changed, 27 insertions(+), 64 deletions(-)

diff --git a/lib/libalpm/alpm.h b/lib/libalpm/alpm.h
index cdceaf0..7ef6a81 100644
--- a/lib/libalpm/alpm.h
+++ b/lib/libalpm/alpm.h
@@ -132,11 +132,6 @@ void alpm_option_add_ignorepkg(const char *pkg);
 void alpm_option_set_ignorepkgs(alpm_list_t *ignorepkgs);
 int alpm_option_remove_ignorepkg(const char *pkg);
 
-alpm_list_t *alpm_option_get_holdpkgs();
-void alpm_option_add_holdpkg(const char *pkg);
-void alpm_option_set_holdpkgs(alpm_list_t *holdpkgs);
-int alpm_option_remove_holdpkg(const char *pkg);
-
 alpm_list_t *alpm_option_get_ignoregrps();
 void alpm_option_add_ignoregrp(const char *grp);
 void alpm_option_set_ignoregrps(alpm_list_t *ignoregrps);
@@ -378,9 +373,7 @@ typedef enum _pmtransconv_t {
        PM_TRANS_CONV_REPLACE_PKG = 0x02,
        PM_TRANS_CONV_CONFLICT_PKG = 0x04,
        PM_TRANS_CONV_CORRUPTED_PKG = 0x08,
-       PM_TRANS_CONV_LOCAL_NEWER = 0x10,
-       /* 0x20 flag can go here */
-       PM_TRANS_CONV_REMOVE_HOLDPKG = 0x40
+       PM_TRANS_CONV_LOCAL_NEWER = 0x10
 } pmtransconv_t;
 
 /* Transaction Progress */
@@ -524,7 +517,6 @@ enum _pmerrno_t {
        PM_ERR_INTERNAL_ERROR,
        PM_ERR_DB_SYNC,
        PM_ERR_RETRIEVE,
-       PM_ERR_PKG_HOLD,
        PM_ERR_INVALID_REGEX,
        /* External library errors */
        PM_ERR_LIBARCHIVE,
diff --git a/lib/libalpm/error.c b/lib/libalpm/error.c
index 05caf8e..5b87950 100644
--- a/lib/libalpm/error.c
+++ b/lib/libalpm/error.c
@@ -143,9 +143,6 @@ const char SYMEXPORT *alpm_strerror(int err)
                        return _("user aborted the operation");
                case PM_ERR_INTERNAL_ERROR:
                        return _("internal error");
-               case PM_ERR_PKG_HOLD:
-                       /* TODO wow this is not descriptive at all... what does 
this mean? */
-                       return _("not confirmed");
                case PM_ERR_INVALID_REGEX:
                        return _("invalid regular expression");
                /* Errors from external libraries- our own wrapper error */
diff --git a/lib/libalpm/handle.c b/lib/libalpm/handle.c
index af1cc78..fbfe7bf 100644
--- a/lib/libalpm/handle.c
+++ b/lib/libalpm/handle.c
@@ -92,7 +92,6 @@ void _alpm_handle_free(pmhandle_t *handle)
        FREELIST(handle->noupgrade);
        FREELIST(handle->noextract);
        FREELIST(handle->ignorepkg);
-       FREELIST(handle->holdpkg);
        FREELIST(handle->ignoregrp);
        FREE(handle);
 }
@@ -205,15 +204,6 @@ alpm_list_t SYMEXPORT *alpm_option_get_ignorepkgs()
        return handle->ignorepkg;
 }
 
-alpm_list_t SYMEXPORT *alpm_option_get_holdpkgs()
-{
-       if (handle == NULL) {
-               pm_errno = PM_ERR_HANDLE_NULL;
-               return NULL;
-       }
-       return handle->holdpkg;
-}
-
 alpm_list_t SYMEXPORT *alpm_option_get_ignoregrps()
 {
        if (handle == NULL) {
@@ -516,28 +506,6 @@ int SYMEXPORT alpm_option_remove_ignorepkg(const char *pkg)
        return(0);
 }
 
-void SYMEXPORT alpm_option_add_holdpkg(const char *pkg)
-{
-       handle->holdpkg = alpm_list_add(handle->holdpkg, strdup(pkg));
-}
-
-void SYMEXPORT alpm_option_set_holdpkgs(alpm_list_t *holdpkgs)
-{
-       if(handle->holdpkg) FREELIST(handle->holdpkg);
-       if(holdpkgs) handle->holdpkg = holdpkgs;
-}
-
-int SYMEXPORT alpm_option_remove_holdpkg(const char *pkg)
-{
-       char *vdata = NULL;
-       handle->holdpkg = alpm_list_remove_str(handle->holdpkg, pkg, &vdata);
-       if(vdata != NULL) {
-               FREE(vdata);
-               return(1);
-       }
-       return(0);
-}
-
 void SYMEXPORT alpm_option_add_ignoregrp(const char *grp)
 {
        handle->ignoregrp = alpm_list_add(handle->ignoregrp, strdup(grp));
diff --git a/lib/libalpm/handle.h b/lib/libalpm/handle.h
index bec0a6f..ad7666d 100644
--- a/lib/libalpm/handle.h
+++ b/lib/libalpm/handle.h
@@ -52,7 +52,6 @@ typedef struct _pmhandle_t {
        alpm_list_t *noupgrade;   /* List of packages NOT to be upgraded */
        alpm_list_t *noextract;   /* List of files NOT to extract */
        alpm_list_t *ignorepkg;   /* List of packages to ignore */
-       alpm_list_t *holdpkg;     /* List of packages which 'hold' pacman */
        alpm_list_t *ignoregrp;   /* List of groups to ignore */
 
        /* options */
diff --git a/lib/libalpm/remove.c b/lib/libalpm/remove.c
index 864fafa..b7f04a3 100644
--- a/lib/libalpm/remove.c
+++ b/lib/libalpm/remove.c
@@ -65,16 +65,6 @@ int _alpm_remove_loadtarget(pmtrans_t *trans, pmdb_t *db, 
char *name)
                RET_ERR(PM_ERR_PKG_NOT_FOUND, -1);
        }
 
-       /* ignore holdpkgs on upgrade */
-       if((trans == handle->trans)
-           && alpm_list_find_str(handle->holdpkg, info->name)) {
-               int resp = 0;
-               QUESTION(trans, PM_TRANS_CONV_REMOVE_HOLDPKG, info, NULL, NULL, 
&resp);
-               if(!resp) {
-                       RET_ERR(PM_ERR_PKG_HOLD, -1);
-               }
-       }
-
        _alpm_log(PM_LOG_DEBUG, "adding %s in the targets list\n", info->name);
        trans->packages = alpm_list_add(trans->packages, _alpm_pkg_dup(info));
 
diff --git a/pactest/tests/remove030.py b/pactest/tests/remove030.py
index 9e2b9da..e975a4b 100644
--- a/pactest/tests/remove030.py
+++ b/pactest/tests/remove030.py
@@ -7,7 +7,5 @@ self.option["HoldPkg"] = ["dummy"]
 
 self.args = "-R %s" % p1.name
 
-self.addrule("PACMAN_RETCODE=0")
-self.addrule("!PKG_EXIST=dummy")
-self.addrule("!FILE_EXIST=etc/dummy.conf")
-self.addrule("!FILE_PACSAVE=etc/dummy.conf")
+self.addrule("PACMAN_RETCODE=1")
+self.addrule("PKG_EXIST=dummy")
diff --git a/src/pacman/callback.c b/src/pacman/callback.c
index 3c98d39..e5404d5 100644
--- a/src/pacman/callback.c
+++ b/src/pacman/callback.c
@@ -260,10 +260,6 @@ void cb_trans_conv(pmtransconv_t event, void *data1, void 
*data2,
                                                alpm_pkg_get_name(data1));
                        }
                        break;
-               case PM_TRANS_CONV_REMOVE_HOLDPKG:
-                       *response = yesno(_(":: %s is designated as a HoldPkg. 
Remove anyway?"),
-                                       alpm_pkg_get_name(data1));
-                       break;
                case PM_TRANS_CONV_REPLACE_PKG:
                        *response = yesno(_(":: Replace %s with %s/%s?"),
                                        alpm_pkg_get_name(data1),
diff --git a/src/pacman/conf.c b/src/pacman/conf.c
index 48c927b..40746e5 100644
--- a/src/pacman/conf.c
+++ b/src/pacman/conf.c
@@ -47,6 +47,7 @@ config_t *config_new(void)
        newconfig->rootdir = NULL;
        newconfig->dbpath = NULL;
        newconfig->logfile = NULL;
+       newconfig->holdpkg = NULL;
        newconfig->syncfirst = NULL;
 
        return(newconfig);
@@ -58,6 +59,7 @@ int config_free(config_t *oldconfig)
                return(-1);
        }
 
+       FREELIST(oldconfig->holdpkg);
        FREELIST(oldconfig->syncfirst);
        free(oldconfig->configfile);
        free(oldconfig->rootdir);
diff --git a/src/pacman/conf.h b/src/pacman/conf.h
index 8ea6662..466d983 100644
--- a/src/pacman/conf.h
+++ b/src/pacman/conf.h
@@ -69,6 +69,7 @@ typedef struct __config_t {
         * downloaded of the total download list */
        unsigned short totaldownload;
        unsigned short cleanmethod; /* select -Sc behavior */
+       alpm_list_t *holdpkg;
        alpm_list_t *syncfirst;
 } config_t;
 
diff --git a/src/pacman/pacman.c b/src/pacman/pacman.c
index 83e713a..92feaf7 100644
--- a/src/pacman/pacman.c
+++ b/src/pacman/pacman.c
@@ -524,6 +524,11 @@ static int parseargs(int argc, char *argv[])
 }
 
 /* helper for being used with setrepeatingoption */
+static void option_add_holdpkg(const char *name) {
+       config->holdpkg = alpm_list_add(config->holdpkg, strdup(name));
+}
+
+/* helper for being used with setrepeatingoption */
 static void option_add_syncfirst(const char *name) {
        config->syncfirst = alpm_list_add(config->syncfirst, strdup(name));
 }
@@ -675,7 +680,7 @@ static int _parseconfig(const char *file, const char 
*givensection,
                                        } else if(strcmp(key, "IgnoreGroup") == 
0) {
                                                setrepeatingoption(ptr, 
"IgnoreGroup", alpm_option_add_ignoregrp);
                                        } else if(strcmp(key, "HoldPkg") == 0) {
-                                               setrepeatingoption(ptr, 
"HoldPkg", alpm_option_add_holdpkg);
+                                               setrepeatingoption(ptr, 
"HoldPkg", option_add_holdpkg);
                                        } else if(strcmp(key, "SyncFirst") == 
0) {
                                                setrepeatingoption(ptr, 
"SyncFirst", option_add_syncfirst);
                                        } else if(strcmp(key, "DBPath") == 0) {
diff --git a/src/pacman/remove.c b/src/pacman/remove.c
index b70f703..841a08b 100644
--- a/src/pacman/remove.c
+++ b/src/pacman/remove.c
@@ -121,6 +121,21 @@ int pacman_remove(alpm_list_t *targets)
                goto cleanup;
        }
 
+       /* Search for holdpkg in target list */
+       int holdpkg = 0;
+       for(i = alpm_trans_get_pkgs(); i; i = alpm_list_next(i)) {
+               pmpkg_t *pkg = alpm_list_getdata(i);
+               if(alpm_list_find_str(config->holdpkg, alpm_pkg_get_name(pkg))) 
{
+                       pm_printf(PM_LOG_WARNING, _("%s is designated as a 
HoldPkg.\n"),
+                                                       alpm_pkg_get_name(pkg));
+                       holdpkg = 1;
+               }
+       }
+       if(holdpkg && (noyes(_("HoldPkg was found in target list. Do you want 
to continue?")) == 0)) {
+               retval = 1;
+               goto cleanup;
+       }
+
        /* Warn user in case of dangerous operation */
        if(config->flags & PM_TRANS_FLAG_RECURSE ||
           config->flags & PM_TRANS_FLAG_CASCADE) {
-- 
1.6.0

_______________________________________________
pacman-dev mailing list
[email protected]
http://archlinux.org/mailman/listinfo/pacman-dev

Reply via email to