2 * dselect - Debian package maintenance user interface
3 * pkgsublist.cc - status modification and recursive package list handling
5 * Copyright © 1995 Ian Jackson <ijackson@chiark.greenend.org.uk>
6 * Copyright © 2007-2014 Guillem Jover <guillem@debian.org>
8 * This is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * This is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program. If not, see <https://www.gnu.org/licenses/>.
28 #include <dpkg/i18n.h>
29 #include <dpkg/dpkg.h>
30 #include <dpkg/dpkg-db.h>
35 void packagelist::add(pkginfo
*pkg
) {
36 debug(dbg_general
, "packagelist[%p]::add(pkginfo %s)",
37 this, pkg_name(pkg
, pnaw_always
));
38 if (!recursive
|| // never add things to top level
39 !pkg
->clientdata
|| // don't add pure virtual packages
40 pkg
->clientdata
->uprec
) // don't add ones already in the recursive list
42 debug(dbg_general
, "packagelist[%p]::add(pkginfo %s) adding",
43 this, pkg_name(pkg
, pnaw_always
));
44 perpackagestate
*state
= &datatable
[nitems
];
46 state
->direct
= state
->original
= pkg
->clientdata
->selected
;
47 state
->suggested
= state
->selected
= pkg
->clientdata
->selected
;
48 state
->spriority
= sp_inherit
; state
->dpriority
= dp_none
;
49 state
->uprec
= pkg
->clientdata
;
50 state
->relations
.init();
51 pkg
->clientdata
= state
;
57 packagelist::add(pkginfo
*pkg
, pkgwant nw
)
59 debug(dbg_general
, "packagelist[%p]::add(pkginfo %s, %s)",
60 this, pkg_name(pkg
, pnaw_always
), wantstrings
[nw
]);
61 add(pkg
); if (!pkg
->clientdata
) return;
62 pkg
->clientdata
->direct
= nw
;
64 np
= would_like_to_install(nw
,pkg
) ? sp_selecting
: sp_deselecting
;
65 if (pkg
->clientdata
->spriority
> np
) return;
66 debug(dbg_general
, "packagelist[%p]::add(pkginfo %s, %s) setting",
67 this, pkg_name(pkg
, pnaw_always
), wantstrings
[nw
]);
68 pkg
->clientdata
->suggested
= pkg
->clientdata
->selected
= nw
;
69 pkg
->clientdata
->spriority
= np
;
72 void packagelist::add(pkginfo
*pkg
, const char *extrainfo
, showpriority showimp
) {
73 debug(dbg_general
, "packagelist[%p]::add(pkginfo %s, ..., showpriority %d)",
74 this, pkg_name(pkg
, pnaw_always
), showimp
);
75 add(pkg
); if (!pkg
->clientdata
) return;
76 if (pkg
->clientdata
->dpriority
< showimp
) pkg
->clientdata
->dpriority
= showimp
;
77 pkg
->clientdata
->relations(extrainfo
);
81 packagelist::alreadydone(doneent
**done
, void *check
)
83 doneent
*search
= *done
;
85 while (search
&& search
->dep
!= check
)
86 search
= search
->next
;
89 debug(dbg_general
, "packagelist[%p]::alreadydone(%p, %p) new",
98 void packagelist::addunavailable(deppossi
*possi
) {
99 debug(dbg_general
, "packagelist[%p]::addunavail(%p)", this, possi
);
101 if (!recursive
) return;
102 if (alreadydone(&unavdone
,possi
)) return;
104 if (possi
->up
->up
->clientdata
== nullptr)
105 internerr("deppossi from package %s has nullptr clientdata",
106 pkg_name(possi
->up
->up
, pnaw_always
));
107 if (possi
->up
->up
->clientdata
->uprec
== nullptr)
108 internerr("deppossi from package %s has nullptr clientdata's uprec",
109 pkg_name(possi
->up
->up
, pnaw_always
));
111 // cppcheck-suppress[constVariable]: false positive, operator() modifies it.
112 // cppcheck-suppress[constVariableReference]: idem, new name for the same.
113 varbuf
& vb
= possi
->up
->up
->clientdata
->relations
;
115 vb(_(" does not appear to be available\n"));
119 packagelist::add(dependency
*depends
, showpriority displayimportance
)
121 debug(dbg_general
, "packagelist[%p]::add(dependency[%p])", this, depends
);
123 if (alreadydone(&depsdone
, depends
))
126 const char *comma
= "";
128 depinfo(depends
->up
->set
->name
);
130 depinfo(gettext(relatestrings
[depends
->type
]));
133 for (possi
=depends
->list
;
135 possi
=possi
->next
, comma
=(possi
&& possi
->next
? ", " : _(" or "))) {
137 depinfo(possi
->ed
->name
);
138 if (possi
->verrel
!= DPKG_RELATION_NONE
) {
139 switch (possi
->verrel
) {
140 case DPKG_RELATION_LE
:
143 case DPKG_RELATION_GE
:
146 case DPKG_RELATION_LT
:
149 case DPKG_RELATION_GT
:
152 case DPKG_RELATION_EQ
:
156 internerr("unknown dpkg_relation %d", possi
->verrel
);
158 depinfo(versiondescribe(&possi
->version
, vdew_nonambig
));
163 add(depends
->up
, depinfo
.string(), displayimportance
);
164 for (possi
=depends
->list
; possi
; possi
=possi
->next
) {
165 add(&possi
->ed
->pkg
, depinfo
.string(), displayimportance
);
166 if (depends
->type
!= dep_provides
) {
167 /* Providers are not relevant if we are looking at a provider
168 * relationship already. */
170 for (provider
= possi
->ed
->depended
.available
;
172 provider
= provider
->rev_next
) {
173 if (provider
->up
->type
!= dep_provides
) continue;
174 add(provider
->up
->up
, depinfo
.string(), displayimportance
);
175 add(provider
->up
,displayimportance
);
182 void repeatedlydisplay(packagelist
*sub
,
183 showpriority initial
,
184 packagelist
*unredisplay
) {
185 debug(dbg_general
, "repeatedlydisplay(packagelist[%p])", sub
);
186 if (sub
->resolvesuggest() != 0 && sub
->deletelessimp_anyleft(initial
)) {
187 debug(dbg_general
, "repeatedlydisplay(packagelist[%p]) once", sub
);
188 if (unredisplay
) unredisplay
->enddisplay();
193 /* Reset manual_install flag now that resolvesuggest() has seen it. */
194 manual_install
= false;
195 newl
= sub
->display();
197 debug(dbg_general
, "repeatedlydisplay(packagelist[%p]) newl", sub
);
198 kb
= sub
->bindings
; delete sub
;
199 sub
= new packagelist(kb
,newl
);
200 if (sub
->resolvesuggest() <= 1) break;
201 if (!sub
->deletelessimp_anyleft(dp_must
)) break;
202 debug(dbg_general
, "repeatedlydisplay(packagelist[%p]) again", sub
);
204 if (unredisplay
) unredisplay
->startdisplay();
206 debug(dbg_general
, "repeatedlydisplay(packagelist[%p]) done", sub
);
210 int packagelist::deletelessimp_anyleft(showpriority than
) {
211 debug(dbg_general
, "packagelist[%p]::dli_al(%d): nitems=%d",
214 for (runthr
=0, insat
=0;
217 if (table
[runthr
]->dpriority
< than
) {
218 table
[runthr
]->free(recursive
);
220 if (insat
!= runthr
) table
[insat
]= table
[runthr
];
225 debug(dbg_general
, "packagelist[%p]::dli_al(%d) done; nitems=%d",