On Tue, Dec 11, Boyd Timothy wrote:
Please take a minute and review the following code:
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@novell.com 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@opensuse.org For additional commands, e-mail: zypp-devel+help@opensuse.org