Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame] | 1 | From 64aa98646a17c299bf37af2975b98daf5d7d30b4 Mon Sep 17 00:00:00 2001 |
| 2 | From: Alejandro del Castillo <alejandro.delcastillo@ni.com> |
| 3 | Date: Thu, 31 Jan 2019 18:16:08 -0600 |
| 4 | Subject: [PATCH] libopkg: add --add-ignore-recommends option |
| 5 | |
| 6 | Add option to ignore specific recommended packages. On the libsolv |
| 7 | backed, this feature will only work on libsolv version > 0.7.2 [1]. |
| 8 | |
| 9 | [1] https://urldefense.proofpoint.com/v2/url?u=https-3A__github.com_openSUSE_libsolv_issues_254&d=DwIBaQ&c=I_0YwoKy7z5LMTVdyO6YCiE2uzI1jjZZuIPelcSjixA&r=wNcrL2akRn6jfxhHaKavUrJB_C9JAMXtynjLd8ZzgXQ&m=GObNHzFJpWpf_PripIrf-K2RhsktYdAUEieAJexXOKw&s=3G-meChUqClFggFPqsrAxIZBfLnRKIHm62Uuy1X6nQQ&e= |
| 10 | |
| 11 | Signed-off-by: Alejandro del Castillo <alejandro.delcastillo@ni.com> |
| 12 | |
| 13 | Upstream-Status: Accepted |
| 14 | --- |
| 15 | libopkg/opkg_conf.c | 2 + |
| 16 | libopkg/opkg_conf.h | 1 + |
| 17 | .../solvers/internal/pkg_depends_internal.c | 3 +- |
| 18 | libopkg/solvers/libsolv/opkg_solver_libsolv.c | 21 ++++++- |
| 19 | man/opkg.1.in | 3 + |
| 20 | src/opkg.c | 6 ++ |
| 21 | tests/Makefile | 1 + |
| 22 | tests/core/43_add_ignore_recommends.py | 62 +++++++++++++++++++ |
| 23 | 8 files changed, 97 insertions(+), 2 deletions(-) |
| 24 | create mode 100755 tests/core/43_add_ignore_recommends.py |
| 25 | |
| 26 | diff --git a/libopkg/opkg_conf.c b/libopkg/opkg_conf.c |
| 27 | index 06880a1..f2330cd 100644 |
| 28 | --- a/libopkg/opkg_conf.c |
| 29 | +++ b/libopkg/opkg_conf.c |
| 30 | @@ -597,6 +597,7 @@ int opkg_conf_init(void) |
| 31 | pkg_dest_list_init(&opkg_config->tmp_dest_list); |
| 32 | nv_pair_list_init(&opkg_config->arch_list); |
| 33 | str_list_init(&opkg_config->exclude_list); |
| 34 | + str_list_init(&opkg_config->ignore_recommends_list); |
| 35 | |
| 36 | return 0; |
| 37 | } |
| 38 | @@ -938,6 +939,7 @@ void opkg_conf_deinit(void) |
| 39 | pkg_dest_list_deinit(&opkg_config->pkg_dest_list); |
| 40 | nv_pair_list_deinit(&opkg_config->arch_list); |
| 41 | str_list_deinit(&opkg_config->exclude_list); |
| 42 | + str_list_deinit(&opkg_config->ignore_recommends_list); |
| 43 | |
| 44 | if (opkg_config->verbosity >= DEBUG) { |
| 45 | hash_print_stats(&opkg_config->pkg_hash); |
| 46 | diff --git a/libopkg/opkg_conf.h b/libopkg/opkg_conf.h |
| 47 | index eb56a29..316c500 100644 |
| 48 | --- a/libopkg/opkg_conf.h |
| 49 | +++ b/libopkg/opkg_conf.h |
| 50 | @@ -61,6 +61,7 @@ typedef struct opkg_conf { |
| 51 | pkg_dest_list_t tmp_dest_list; |
| 52 | nv_pair_list_t arch_list; |
| 53 | str_list_t exclude_list; |
| 54 | + str_list_t ignore_recommends_list; |
| 55 | |
| 56 | int restrict_to_default_dest; |
| 57 | pkg_dest_t *default_dest; |
| 58 | diff --git a/libopkg/solvers/internal/pkg_depends_internal.c b/libopkg/solvers/internal/pkg_depends_internal.c |
| 59 | index cd56d84..5deee70 100644 |
| 60 | --- a/libopkg/solvers/internal/pkg_depends_internal.c |
| 61 | +++ b/libopkg/solvers/internal/pkg_depends_internal.c |
| 62 | @@ -228,7 +228,8 @@ int pkg_hash_fetch_unsatisfied_dependencies(pkg_t *pkg, |
| 63 | || compound_depend->type == SUGGEST) |
| 64 | && (satisfying_pkg->state_want == SW_DEINSTALL |
| 65 | || satisfying_pkg->state_want == SW_PURGE |
| 66 | - || opkg_config->no_install_recommends); |
| 67 | + || opkg_config->no_install_recommends |
| 68 | + || str_list_contains(&opkg_config->ignore_recommends_list, satisfying_pkg->name)); |
| 69 | if (ignore) { |
| 70 | opkg_msg(NOTICE, |
| 71 | "%s: ignoring recommendation for " |
| 72 | diff --git a/libopkg/solvers/libsolv/opkg_solver_libsolv.c b/libopkg/solvers/libsolv/opkg_solver_libsolv.c |
| 73 | index 2b27e3a..403e07b 100644 |
| 74 | --- a/libopkg/solvers/libsolv/opkg_solver_libsolv.c |
| 75 | +++ b/libopkg/solvers/libsolv/opkg_solver_libsolv.c |
| 76 | @@ -484,6 +484,7 @@ static void pkg2solvable(pkg_t *pkg, Solvable *solvable_out) |
| 77 | static void populate_installed_repo(libsolv_solver_t *libsolv_solver) |
| 78 | { |
| 79 | int i; |
| 80 | + Id what; |
| 81 | |
| 82 | pkg_vec_t *installed_pkgs = pkg_vec_alloc(); |
| 83 | |
| 84 | @@ -507,6 +508,15 @@ static void populate_installed_repo(libsolv_solver_t *libsolv_solver) |
| 85 | /* set solvable attributes */ |
| 86 | pkg2solvable(pkg, solvable); |
| 87 | |
| 88 | + /* if the package is in ignore-recommends-list, disfavor installation */ |
| 89 | + if (str_list_contains(&opkg_config->ignore_recommends_list, pkg->name)) { |
| 90 | + opkg_message(NOTICE, "Disfavor package: %s\n", |
| 91 | + pkg->name); |
| 92 | + what = pool_str2id(libsolv_solver->pool, pkg->name, 1); |
| 93 | + queue_push2(&libsolv_solver->solver_jobs, SOLVER_SOLVABLE_NAME |
| 94 | + | SOLVER_DISFAVOR, what); |
| 95 | + } |
| 96 | + |
| 97 | /* if the package is not autoinstalled, mark it as user installed */ |
| 98 | if (!pkg->auto_installed) |
| 99 | queue_push2(&libsolv_solver->solver_jobs, SOLVER_SOLVABLE |
| 100 | @@ -539,7 +549,7 @@ static void populate_available_repos(libsolv_solver_t *libsolv_solver) |
| 101 | { |
| 102 | int i; |
| 103 | Solvable *solvable; |
| 104 | - Id solvable_id; |
| 105 | + Id solvable_id, what; |
| 106 | |
| 107 | pkg_vec_t *available_pkgs = pkg_vec_alloc(); |
| 108 | |
| 109 | @@ -608,6 +618,15 @@ static void populate_available_repos(libsolv_solver_t *libsolv_solver) |
| 110 | solvable = pool_id2solvable(libsolv_solver->pool, solvable_id); |
| 111 | pkg2solvable(pkg, solvable); |
| 112 | |
| 113 | + /* if the package is in ignore-recommends-list, disfavor installation */ |
| 114 | + if (str_list_contains(&opkg_config->ignore_recommends_list, pkg->name)) { |
| 115 | + opkg_message(NOTICE, "Disfavor package: %s\n", |
| 116 | + pkg->name); |
| 117 | + what = pool_str2id(libsolv_solver->pool, pkg->name, 1); |
| 118 | + queue_push2(&libsolv_solver->solver_jobs, SOLVER_SOLVABLE_NAME |
| 119 | + | SOLVER_DISFAVOR, what); |
| 120 | + } |
| 121 | + |
| 122 | /* if the --force-depends option is specified make dependencies weak */ |
| 123 | if (opkg_config->force_depends) |
| 124 | queue_push2(&libsolv_solver->solver_jobs, SOLVER_SOLVABLE |
| 125 | diff --git a/man/opkg.1.in b/man/opkg.1.in |
| 126 | index 27fa9c1..f192c3b 100644 |
| 127 | --- a/man/opkg.1.in |
| 128 | +++ b/man/opkg.1.in |
| 129 | @@ -162,6 +162,9 @@ priority \fIprio\fP. Lower priorities take precedence. |
| 130 | \fB\--add-exclude <\fIname\fP>\fR |
| 131 | Register package to be excluded from install |
| 132 | .TP |
| 133 | +\fB\--add-ignore-recommends <\fIname\fP>\fR |
| 134 | +Register package to be ignored as a recomendee |
| 135 | +.TP |
| 136 | \fB\--prefer-arch-to-version\fR |
| 137 | Use the architecture priority package rather than the higher version |
| 138 | one if more than one candidate is found. |
| 139 | diff --git a/src/opkg.c b/src/opkg.c |
| 140 | index 650e278..3c93a3b 100644 |
| 141 | --- a/src/opkg.c |
| 142 | +++ b/src/opkg.c |
| 143 | @@ -51,6 +51,7 @@ enum { |
| 144 | ARGS_OPT_ADD_DEST, |
| 145 | ARGS_OPT_SIZE, |
| 146 | ARGS_OPT_ADD_EXCLUDE, |
| 147 | + ARGS_OPT_ADD_IGNORE_RECOMMENDS, |
| 148 | ARGS_OPT_NOACTION, |
| 149 | ARGS_OPT_DOWNLOAD_ONLY, |
| 150 | ARGS_OPT_NODEPS, |
| 151 | @@ -112,6 +113,7 @@ static struct option long_options[] = { |
| 152 | {"add-dest", 1, 0, ARGS_OPT_ADD_DEST}, |
| 153 | {"size", 0, 0, ARGS_OPT_SIZE}, |
| 154 | {"add-exclude", 1, 0, ARGS_OPT_ADD_EXCLUDE}, |
| 155 | + {"add-ignore-recommends", 1, 0, ARGS_OPT_ADD_IGNORE_RECOMMENDS}, |
| 156 | {"test", 0, 0, ARGS_OPT_NOACTION}, |
| 157 | {"tmp-dir", 1, 0, 't'}, |
| 158 | {"tmp_dir", 1, 0, 't'}, |
| 159 | @@ -234,6 +236,9 @@ static int args_parse(int argc, char *argv[]) |
| 160 | case ARGS_OPT_ADD_EXCLUDE: |
| 161 | str_list_append(&opkg_config->exclude_list, optarg); |
| 162 | break; |
| 163 | + case ARGS_OPT_ADD_IGNORE_RECOMMENDS: |
| 164 | + str_list_append(&opkg_config->ignore_recommends_list, optarg); |
| 165 | + break; |
| 166 | case ARGS_OPT_SIZE: |
| 167 | opkg_config->size = 1; |
| 168 | break; |
| 169 | @@ -343,6 +348,7 @@ static void usage() |
| 170 | printf("\t--add-dest <name>:<path> Register destination with given path\n"); |
| 171 | printf("\t--add-arch <arch>:<prio> Register architecture with given priority\n"); |
| 172 | printf("\t--add-exclude <name> Register package to be excluded from install\n"); |
| 173 | + printf("\t--add-ignore-recommends <name> Register package to be ignored as a recomendee\n"); |
| 174 | printf("\t--prefer-arch-to-version Use the architecture priority package rather\n"); |
| 175 | printf("\t than the higher version one if more\n"); |
| 176 | printf("\t than one candidate is found.\n"); |
| 177 | diff --git a/tests/Makefile b/tests/Makefile |
| 178 | index 8e5be08..799816d 100644 |
| 179 | --- a/tests/Makefile |
| 180 | +++ b/tests/Makefile |
| 181 | @@ -42,6 +42,7 @@ REGRESSION_TESTS := core/01_install.py \ |
| 182 | core/40_arch.py \ |
| 183 | core/41_info_fields.py \ |
| 184 | core/42_info_description.py \ |
| 185 | + core/43_add_ignore_recommends.py \ |
| 186 | regress/issue26.py \ |
| 187 | regress/issue31.py \ |
| 188 | regress/issue32.py \ |
| 189 | diff --git a/tests/core/43_add_ignore_recommends.py b/tests/core/43_add_ignore_recommends.py |
| 190 | new file mode 100755 |
| 191 | index 0000000..7da0096 |
| 192 | --- /dev/null |
| 193 | +++ b/tests/core/43_add_ignore_recommends.py |
| 194 | @@ -0,0 +1,62 @@ |
| 195 | +#! /usr/bin/env python3 |
| 196 | +# |
| 197 | +# Create package 'a' (1.0) which Recommends 'c'. |
| 198 | +# Install 'a' with --add-ignore-recommends 'c'. |
| 199 | +# Check that only 'a' (1.0) is installed. |
| 200 | +# Create package 'b' which Depends on 'c'. |
| 201 | +# Install 'a' & 'b', with --add-ignore-recommends 'c'. |
| 202 | +# Verify that 'a','b' & 'c' are installed. |
| 203 | +# Uninstall 'b' & 'c'. |
| 204 | +# Create package 'a' (2.0), which Recommends 'c'. |
| 205 | +# Upgrade 'a' with --add-ignore-recommends 'c' |
| 206 | +# Verify that only 'a' (2.0) is installed |
| 207 | +# |
| 208 | + |
| 209 | +import os |
| 210 | +import opk, cfg, opkgcl |
| 211 | + |
| 212 | +opk.regress_init() |
| 213 | +o = opk.OpkGroup() |
| 214 | + |
| 215 | +o.add(Package='a', Recommends='c', Version='1.0') |
| 216 | +o.add(Package='b', Depends='c') |
| 217 | +o.add(Package='c') |
| 218 | +o.write_opk() |
| 219 | +o.write_list() |
| 220 | + |
| 221 | +opkgcl.update() |
| 222 | + |
| 223 | +opkgcl.install('a', '--add-ignore-recommends c') |
| 224 | + |
| 225 | +if not opkgcl.is_installed('a'): |
| 226 | + opk.fail("Package 'a' installed but reports as not installed.") |
| 227 | + |
| 228 | +if opkgcl.is_installed('c'): |
| 229 | + opk.xfail("[libsolv<0.7.3] Package 'c' should not have been installed since it was in --add-ignore-recommends.") |
| 230 | + |
| 231 | +opkgcl.remove('a') |
| 232 | +opkgcl.install('a b', '--add-ignore-recommends c') |
| 233 | + |
| 234 | +if not opkgcl.is_installed('a'): |
| 235 | + opk.fail("Package 'a' installed but reports as not installed.") |
| 236 | + |
| 237 | +if not opkgcl.is_installed('b'): |
| 238 | + opk.fail("Package 'b' installed but reports as not installed.") |
| 239 | + |
| 240 | +if not opkgcl.is_installed('c'): |
| 241 | + opk.fail("Package 'c' should have been installed since 'b' depends on it.") |
| 242 | + |
| 243 | +opkgcl.remove('b c', '--force-depends') |
| 244 | +o.add(Package='a', Recommends='c', Version='2.0') |
| 245 | +o.write_opk() |
| 246 | +o.write_list() |
| 247 | + |
| 248 | +opkgcl.update() |
| 249 | + |
| 250 | +opkgcl.upgrade('a', '--add-ignore-recommends c') |
| 251 | + |
| 252 | +if not opkgcl.is_installed('a', '2.0'): |
| 253 | + opk.fail("Package 'a (2.0)' installed but reports as not installed.") |
| 254 | + |
| 255 | +if opkgcl.is_installed('c'): |
| 256 | + opk.fail("Package 'c' should not have been installed since it was in --add-ignore-recommends.") |
| 257 | -- |
| 258 | 2.20.1 |
| 259 | |