Mailinglist Archive: zypp-devel (56 mails)

< Previous Next >
Re: [zypp-devel] How to get a packages' depends and requires from libzypp
  • From: Michael Andres <ma@xxxxxxx>
  • Date: Thu, 13 Dec 2007 14:32:15 +0100
  • Message-id: <20071213133215.GA27328@xxxxxxx>
On Tue, Dec 11, Boyd Timothy wrote:

Please take a minute and review the following code:

http://pastebin.ca/812178

In general:

const char *edition_str = installable->edition().asString().c_str();
if (strcmp (edition_str, pi->version) == 0) {

c_str returns a pointer to a std::strings internal data. This pointer is
not valid past the lifetime of the std::string.

Edition::asString returns a temporary, so edition_str is no longer valid
at the time you do the strcmp.

These should be safe:

std::string edition_str( installable->edition().asString() );
if (strcmp (edition_str.c_str(), pi->version) == 0) {
or
std::string edition_str( installable->edition().asString() );
if (edition_str == pi->version) {
or
if (installable->edition().asString() == pi->version) {


std::string uses a shared data representation and performs copy on write,
so creating a local edition_str is cheap. And it supports comparison with
char*.



Is this what you had in mind? Isn't there an easier way to get this
information?

I noticed that this only works for packages that are not installed.
Is there a mechanism that would work for packages that are installed?

Too keep in mind:

Inside the ui::Selectable("name") is a list of all available packages with
that "name". The default/guess returned by ->candidateObj() actually
depends on properties of an installed package if there is one (at least
it's architecture and it's vendor).

As you do not load the Target (installed) packages into the pool, it might
be that the candidate returned is not the best choice for the real system.

And the solver will assume there is no package installed, so he will
always choose the best available version for a package. This is not
necessarily what you'll get, if you actually install the selected package.
It might always be that an already installed version fits as well.


But if you include the target packages, the solver (most probably) no
longer tells you about required but already installed packages...


I'll think about a better solution...

--

cu,
Michael Andres

+------------------------------------------------------------------+
Key fingerprint = 2DFA 5D73 18B1 E7EF A862 27AC 3FB8 9E3A 27C6 B0E4
+------------------------------------------------------------------+
Michael Andres YaST Development ma@xxxxxxxxxx
SUSE LINUX Products GmbH, GF: Markus Rex, HRB 16746 (AG Nuernberg)
Maxfeldstrasse 5, D-90409 Nuernberg, Germany, ++49 (0)911 - 740 53-0
+------------------------------------------------------------------+

--
To unsubscribe, e-mail: zypp-devel+unsubscribe@xxxxxxxxxxxx
For additional commands, e-mail: zypp-devel+help@xxxxxxxxxxxx

< Previous Next >
Follow Ups