Author: dmacvicar
Date: Tue May 10 20:10:47 2011
New Revision: 63940
URL: http://svn.opensuse.org/viewcvs/yast?rev=63940&view=rev
Log:
More porting
Added:
branches/tmp/dmacvicar/zc10/pkg-bindings/src/PkgProgress.cc
branches/tmp/dmacvicar/zc10/pkg-bindings/src/PkgProgress.h
branches/tmp/dmacvicar/zc10/pkg-bindings/src/PkgService.cc
branches/tmp/dmacvicar/zc10/pkg-bindings/src/PkgService.h
branches/tmp/dmacvicar/zc10/pkg-bindings/src/ServiceManager.cc
branches/tmp/dmacvicar/zc10/pkg-bindings/src/ServiceManager.h
branches/tmp/dmacvicar/zc10/pkg-bindings/src/Source.loT
branches/tmp/dmacvicar/zc10/pkg-bindings/src/Utils.cc
branches/tmp/dmacvicar/zc10/pkg-bindings/src/Utils.h
branches/tmp/dmacvicar/zc10/pkg-bindings/src/YRepo.cc
branches/tmp/dmacvicar/zc10/pkg-bindings/src/YRepo.h
branches/tmp/dmacvicar/zc10/pkg-bindings/src/log.h
Modified:
branches/tmp/dmacvicar/zc10/pkg-bindings/src/Makefile.am
branches/tmp/dmacvicar/zc10/pkg-bindings/src/Package.cc
branches/tmp/dmacvicar/zc10/pkg-bindings/src/PkgModuleFunctions.cc
branches/tmp/dmacvicar/zc10/pkg-bindings/src/PkgModuleFunctions.h
branches/tmp/dmacvicar/zc10/pkg-bindings/src/Resolvable.cc
branches/tmp/dmacvicar/zc10/pkg-bindings/src/Selection.cc
branches/tmp/dmacvicar/zc10/pkg-bindings/src/Source.cc
branches/tmp/dmacvicar/zc10/pkg-bindings/src/Target.cc
branches/tmp/dmacvicar/zc10/pkg-bindings/src/ycpTools.h
Modified: branches/tmp/dmacvicar/zc10/pkg-bindings/src/Makefile.am
URL: http://svn.opensuse.org/viewcvs/yast/branches/tmp/dmacvicar/zc10/pkg-bindings/src/Makefile.am?rev=63940&r1=63939&r2=63940&view=diff
==============================================================================
--- branches/tmp/dmacvicar/zc10/pkg-bindings/src/Makefile.am (original)
+++ branches/tmp/dmacvicar/zc10/pkg-bindings/src/Makefile.am Tue May 10 20:10:47 2011
@@ -22,7 +22,11 @@
Y2CCPkg.cc Y2CCPkg.h \
ycpTools.cc ycpTools.h \
PkgModule.cc PkgModule.h \
- YRepo.h YRepo.cc
+ YRepo.h YRepo.cc \
+ PkgProgress.cc PkgProgress.h \
+ Utils.h Utils.cc \
+ ServiceManager.cc ServiceManager.h \
+ PkgService.cc PkgService.h \
PkgModuleFunctions.h \
PkgModuleFunctions.cc \
Package.cc \
Modified: branches/tmp/dmacvicar/zc10/pkg-bindings/src/Package.cc
URL: http://svn.opensuse.org/viewcvs/yast/branches/tmp/dmacvicar/zc10/pkg-bindings/src/Package.cc?rev=63940&r1=63939&r2=63940&view=diff
==============================================================================
--- branches/tmp/dmacvicar/zc10/pkg-bindings/src/Package.cc (original)
+++ branches/tmp/dmacvicar/zc10/pkg-bindings/src/Package.cc Tue May 10 20:10:47 2011
@@ -32,9 +32,9 @@
#include
#include
+#include
#include
#include
-#include
#include
#include
@@ -43,12 +43,9 @@
#include
#include
#include
-#include
-#include
#include
#include
#include
-#include
#include <fstream>
#include <sstream>
@@ -59,6 +56,118 @@
typedef std::list<PoolItem> PoolItemList;
}
+// helper function - create a symbolic link to the created base product (by SourceCreateBase() function)
+// returns 'true' on success
+// see http://en.opensuse.org/Product_Management/Code11/installed
+bool PkgModuleFunctions::CreateBaseProductSymlink()
+{
+ if (base_product)
+ {
+ y2milestone("Creating symlink for the base product...");
+
+ // get the package
+ zypp::sat::Solvable refsolvable = base_product->referencePackage();
+
+ if (refsolvable != zypp::sat::Solvable::noSolvable)
+ {
+ // create a package pointer from the SAT solvable
+ zypp::Package::Ptr refpkg(zypp::makezypp::Package(refsolvable));
+
+ if (refpkg)
+ {
+ y2milestone("Found reference package for the base product: %s-%s",
+ refpkg->name().c_str(), refpkg->edition().asString().c_str());
+
+ // get the package files
+ zypp::Package::FileList files( refpkg->filelist() );
+ y2milestone("The reference package has %d files", files.size());
+
+ std::string product_file;
+ zypp::str::smatch what;
+ const zypp::str::regex product_file_regex("^/etc/products\\.d/(.*\\.prod)$");
+
+ // find the product file
+ for_(iter, files.begin(), files.end())
+ {
+ if (zypp::str::regex_match(*iter, what, product_file_regex))
+ {
+ product_file = what[1];
+ break;
+ }
+ }
+
+ if (product_file.empty())
+ {
+ y2error("The product file has not been found");
+ return false;
+ }
+ else
+ {
+ y2milestone("Found product file %s", product_file.c_str());
+
+ // check and remove the existing link (refresh the link after upgrade)
+ const zypp::Pathname base_link(_target_root / "/etc/products.d/baseproduct");
+
+ struct stat stat_buf;
+ if (::stat(base_link.asString().c_str(), &stat_buf) == 0)
+ {
+ // the file exists, remove it
+ if (::unlink(base_link.asString().c_str()) != 0)
+ {
+ y2error("Cannot remove base link file %s: %s",
+ base_link.asString().c_str(),
+ ::strerror(errno)
+ );
+
+ return false;
+ }
+ }
+ // ENOENT == "No such file or directory", see 'man errno'
+ else if (errno != ENOENT)
+ {
+ y2error("Cannot stat %s file: %s", base_link.asString().c_str(), ::strerror(errno));
+ return false;
+ }
+ else
+ {
+ y2debug("Link %s does not exist", base_link.asString().c_str());
+ }
+
+ if (::symlink(product_file.c_str(), base_link.asString().c_str()) != 0)
+ {
+ y2error("Cannot create symlink %s -> %s: %s",
+ base_link.asString().c_str(),
+ product_file.c_str(),
+ ::strerror(errno)
+ );
+
+ return false;
+ }
+ else
+ {
+ y2milestone("Symlink %s -> %s has been created", base_link.asString().c_str(), product_file.c_str());
+ }
+ }
+ }
+ else
+ {
+ y2error("The reference solvable is not a package");
+ return false;
+ }
+ }
+ else
+ {
+ y2milestone("The base product doesn't have any reference package");
+ }
+ }
+ else
+ {
+ y2debug("A base product has not been added");
+ }
+
+ return true;
+}
+
// ------------------------
/**
* @builtin PkgQueryProvides
@@ -252,8 +361,8 @@
return res;
}
-static YCPValue
-PkgMediaSizesOrCount (bool sizes, bool download_size)
+YCPValue
+PkgModuleFunctions::PkgMediaSizesOrCount (bool sizes, bool download_size)
{
// all enabled sources
std::list<RepoId> source_ids;
@@ -513,310 +622,21 @@
return YCPBoolean(false);
}
-
-struct ProvideProcess
-{
- zypp::PoolItem_Ref item;
- zypp::Arch _architecture;
- zypp::ResStatus::TransactByValue whoWantsIt;
- std::string version;
- bool onlyNeeded;
-
- ProvideProcess( zypp::Arch arch, const std::string &vers, const bool oNeeded)
- : _architecture( arch ), whoWantsIt(zypp::ResStatus::APPL_HIGH), version(vers), onlyNeeded(oNeeded)
- { }
-
- bool operator()( zypp::PoolItem provider )
- {
- // 1. compatible arch
- // 2. best arch
- // 3. best edition
- // see QueueItemRequire in zypp/solver/detail, RequireProcess
-
- // check the version if it's specified
- if (!version.empty() && version != provider->edition().asString())
- {
- y2milestone("Skipping version %s (requested: %s)", provider->edition().asString().c_str(), version.c_str());
- return true;
- }
-
- if (!provider.status().isInstalled()
- && (!onlyNeeded || provider.status().isNeeded()) ) // take only needed items (e.G. needed patches)
- {
- // deselect the item if it's already selected,
- // only one item should be selected
- if (provider.status().isToBeInstalled())
- {
- provider.status().resetTransact(whoWantsIt);
- }
-
- // regarding items which are installable only
- if (!provider->arch().compatibleWith( _architecture )) {
- y2milestone ("provider %s has incompatible arch '%s'", provider->name().c_str(), provider->arch().asString().c_str());
- }
- else if (!item) { // no provider yet
- item = provider;
- }
- else if (item->arch().compare( provider->arch() ) < 0) { // provider has better arch
- item = provider;
- }
- else if (item->edition().compare( provider->edition() ) < 0) {
- item = provider; // provider has better edition
- }
- }
-
- return true;
- }
-
-};
-
-
-/**
- * helper function, install a resolvable with a specific name and kind
-*/
-
-bool
-PkgModuleFunctions::DoProvideNameKind( const std::string & name, zypp::Resolvable::Kind kind, zypp::Arch architecture,
- const std::string & version ,const bool onlyNeeded)
-{
- try
- {
- ProvideProcess info( architecture, version, onlyNeeded);
- info.whoWantsIt = whoWantsIt;
-
- invokeOnEach( zypp_ptr()->pool().byNameBegin( name ),
- zypp_ptr()->pool().byNameEnd( name ),
- zypp::resfilter::ByKind( kind ),
- zypp::functor::functorRef (info)
- );
-
- if (!info.item)
- return false;
-
- bool result = info.item.status().setToBeInstalled( whoWantsIt );
- if (!result) {
- std::ostringstream os;
- os << info.item;
- y2milestone( "DoProvideNameKind failed for %s\n", os.str().c_str() );
- }
- return true;
- }
- catch (...)
- {
- }
-
- return false;
-}
-
-/*
- * Helper function
- */
-bool
-PkgModuleFunctions::DoAllKind(zypp::Resolvable::Kind kind, bool provide)
-{
- bool ret = true;
-
- try
- {
- for (zypp::ResPool::byKind_iterator it = zypp_ptr()->pool().byKindBegin(kind);
- it != zypp_ptr()->pool().byKindEnd(kind); ++it)
- {
- bool res = provide ? it->status().setToBeInstalled( whoWantsIt )
- : (it->status().isInstalled() && it->status().setToBeUninstalled( whoWantsIt ));
-
- y2milestone ("%s %s -> %s\n", (provide ? "Install" : "Remove"), (*it)->name().c_str(), (res ? "Ok" : "Failed"));
- ret = ret && res;
- }
- }
- catch (...)
- {
- ret = false;
- }
-
- return ret;
-}
-
-bool
-PkgModuleFunctions::DoProvideAllKind(zypp::Resolvable::Kind kind)
-{
- return DoAllKind(kind, true);
-}
-
-bool
-PkgModuleFunctions::DoRemoveAllKind(zypp::Resolvable::Kind kind)
-{
- return DoAllKind(kind, false);
-}
-
-
-
-/**
- * helper function, deinstall a kind which provides tag (as a
- * kind name, a provided tag, or a provided file
- *
- * !!!!**** WARNING: This is different from DoProvideNameKind ****!!!!
-*/
-
-bool
-PkgModuleFunctions::DoRemoveNameKind( const std::string & name, zypp::Resolvable::Kind kind)
-{
- zypp::Dep dep( zypp::Dep::PROVIDES );
- CaIMatch match;
-
- try
- {
- // look for installed packages
- invokeOnEach( zypp_ptr()->pool().byCapabilityIndexBegin( name, dep ),
- zypp_ptr()->pool().byCapabilityIndexEnd( name, dep ),
- zypp::functor::chain( zypp::resfilter::ByCaIInstalled(),
- zypp::resfilter::ByCaIKind( kind ) ),
- zypp::functor::functorRef( match ) );
- }
- catch (...)
- {
- return false;
- }
-
- if (!match.item)
- return false;
-
- bool result = match.item.status().setToBeUninstalled( whoWantsIt );
- y2milestone ("DoRemoveNameKind %s -> %s\n", name.c_str(), (result ? "Ok" : "Bad"));
-
- return true;
-}
-
-// ------------------------
-/**
- @builtin DoProvide
- @short Install a list of packages to the system
- @description
- Provides (read: installs) a list of tags to the system
-
- tag is a package name
-
- returns a map of tag,reason pairs if tags could not be provided.
- Usually this map should be empty (all required packages are
- installed)
-
- If tags could not be provided (due to package install failures or
- conflicts), the tag is listed as a key and the value describes
- the reason for the failure (as an already translated string).
- @param list tags
- @return map
-*/
-YCPValue
-PkgModuleFunctions::DoProvide (const YCPList& tags)
-{
- YCPMap ret;
- if (tags->size() > 0)
- {
- for (int i = 0; i < tags->size(); ++i)
- {
- if (tags->value(i)->isString())
- {
- DoProvideNameKind (tags->value(i)->asString()->value(), zypp::ResTraitszypp::Package::kind, zypp_ptr()->architecture(), "");
- }
- else
- {
- y2error ("Pkg::DoProvide not string '%s'", tags->value(i)->toString().c_str());
- }
- }
- }
-# warning error handling - return value
- return ret;
-}
-
-
-// ------------------------
-/**
- @builtin DoRemove
-
- @short Removes a list of packges from the system
- @description
- tag is a package name
-
- returns a map of tag,reason pairs if tags could not be removed.
- Usually this map should be empty (all required packages are
- removed)
-
- If a tag could not be removed (because other packages still
- require it), the tag is listed as a key and the value describes
- the reason for the failure (as an already translated string).
- @param list tags
- @return list Result
-*/
-YCPValue
-PkgModuleFunctions::DoRemove (const YCPList& tags)
-{
- YCPMap ret;
- if (tags->size() > 0)
- {
- for (int i = 0; i < tags->size(); ++i)
- {
- if (tags->value(i)->isString())
- {
- DoRemoveNameKind( tags->value(i)->asString()->value(), zypp::ResTraitszypp::Package::kind);
- }
- else
- {
- y2error ("Pkg::DoRemove not string '%s'", tags->value(i)->toString().c_str());
- }
- }
- }
- return ret;
-}
-
-// ------------------------
-
-struct ItemMatch
-{
- zypp::PoolItem_Ref item;
-
- bool operator() (const zypp::PoolItem_Ref i )
- {
- item = i;
- return false;
- }
-};
-
-static zypp::Package::constPtr
-find_package( const string & name, zypp::PoolItem_Ref & item, zypp::ResPool pool )
+static zypp::Package::constPtr find_package(const string &name)
{
if (name.empty())
return NULL;
- ItemMatch match;
-
- // look for uninstalled packages first, because they probably have
- // translated summary
-
- invokeOnEach( pool.byNameBegin( name ),
- pool.byNameEnd( name ),
- zypp::functor::chain( zypp::resfilter::ByUninstalled(),
- zypp::resfilter::ByKind( zypp::ResTraitszypp::Package::kind ) ),
- zypp::functor::functorRef( match ) );
+ zypp::ui::Selectable::Ptr s = zypp::ui::Selectable::get(name);
- // if no match yet, try again with installed package
- // (but those only provide an english summary)
-
- if (!match.item) {
- invokeOnEach( pool.byNameBegin( name ),
- pool.byNameEnd( name ),
- zypp::functor::chain( zypp::resfilter::ByInstalled(),
- zypp::resfilter::ByKind( zypp::ResTraitszypp::Package::kind ) ),
- zypp::functor::functorRef( match ) );
+ if (s)
+ {
+ return zypp::dynamic_pointer_cast<const zypp::Package>(s->theObj().resolvable());
}
- if (!match.item)
- return NULL;
-
- item = match.item;
-
- return zypp::asKindzypp::Package( match.item.resolvable() );
+ return NULL;
}
-
/**
@builtin PkgSummary
@@ -826,22 +646,19 @@
@usage Pkg::PkgSummary (string package) -> "This is a nice package"
*/
-#warning This is bogus, as we have multiple matching packages
-
YCPValue
PkgModuleFunctions::PkgSummary (const YCPString& p)
{
try
{
- zypp::PoolItem_Ref item;
- zypp::Package::constPtr pkg = find_package( p->value(), item, zypp_ptr()->pool() );
+ zypp::Package::constPtr pkg = find_package(p->value());
if (pkg == NULL)
{
return YCPVoid();
}
- return YCPString( pkg->summary() );
+ return YCPString(pkg->summary());
}
catch (...)
{
@@ -861,15 +678,12 @@
*/
-#warning This is bogus, as we have multiple matching packages
-
YCPValue
PkgModuleFunctions::PkgVersion (const YCPString& p)
{
try
{
- zypp::PoolItem_Ref item;
- zypp::Package::constPtr pkg = find_package( p->value(), item, zypp_ptr()->pool() );
+ zypp::Package::constPtr pkg = find_package(p->value());
if (pkg == NULL)
{
@@ -895,22 +709,20 @@
@usage Pkg::PkgSize (string package) -> 12345678
*/
-#warning This is bogus, as we have multiple matching packages
YCPValue
PkgModuleFunctions::PkgSize (const YCPString& p)
{
try
{
- zypp::PoolItem_Ref item;
- zypp::Package::constPtr pkg = find_package( p->value(), item, zypp_ptr()->pool() );
+ zypp::Package::constPtr pkg = find_package(p->value());
if (pkg == NULL)
{
return YCPVoid();
}
- return YCPInteger( pkg->size() );
+ return YCPInteger( pkg->installSize() );
}
catch (...)
{
@@ -929,15 +741,13 @@
@usage Pkg::PkgGroup (string package) -> string
*/
-#warning This is bogus, as we have multiple matching packages
YCPValue
PkgModuleFunctions::PkgGroup (const YCPString& p)
{
try
{
- zypp::PoolItem_Ref item;
- zypp::Package::constPtr pkg = find_package( p->value(), item, zypp_ptr()->pool() );
+ zypp::Package::constPtr pkg = find_package(p->value());
if (pkg == NULL)
{
@@ -953,24 +763,40 @@
return YCPVoid();
}
+PkgModuleFunctions::RepoId PkgModuleFunctions::logFindAlias(const std::string &alias) const
+{
+ RepoId index = 0LL;
+
+ for(RepoCont::const_iterator it = repos.begin(); it != repos.end() ; ++it, ++index)
+ {
+ if (!(*it)->isDeleted() && (*it)->repoInfo().alias() == alias)
+ return index;
+ }
+
+ return -1LL;
+}
YCPValue
-PkgModuleFunctions::PkgProp( zypp::PoolItem_Ref item )
+PkgModuleFunctions::PkgProp(const zypp::PoolItem &item)
{
YCPMap data;
- zypp::Package::constPtr pkg = zypp::asKindzypp::Package( item.resolvable() );
+
+ zypp::Package::constPtr pkg = zypp::dynamic_pointer_cast<const zypp::Package>(item.resolvable());
+
if (pkg == NULL) {
- y2error( "Not a package: %s", item->name().c_str() );
- return data;
+ y2error("NULL pkg");
+ return YCPVoid();
}
data->add( YCPString("arch"), YCPString( pkg->arch().asString() ) );
- data->add( YCPString("medianr"), YCPInteger( pkg->sourceMediaNr() ) );
+ data->add( YCPString("medianr"), YCPInteger( pkg->mediaNr() ) );
- y2debug("srcId: %ld", pkg->source().numericId() );
- data->add( YCPString("srcid"), YCPInteger( pkg->source().numericId() ) );
+ long long sid = logFindAlias(pkg->repoInfo().alias());
+ y2debug("srcId: %lld", sid );
+ data->add( YCPString("srcid"), YCPInteger( sid ) );
std::string status("available");
+
if (item.status().isInstalled())
{
status = "installed";
@@ -983,10 +809,11 @@
{
status = "removed";
}
+
data->add( YCPString("status"), YCPSymbol(status));
- data->add( YCPString("location"), YCPString( pkg->location().basename() ) );
- data->add( YCPString("path"), YCPString( pkg->location().asString() ) );
+ data->add( YCPString("location"), YCPString( pkg->location().filename().basename() ) );
+ data->add( YCPString("path"), YCPString( pkg->location().filename().asString() ) );
return data;
}
@@ -1011,19 +838,22 @@
* @usage Pkg::PkgProperties (string package) -> map
*/
-#warning This is bogus, as we have multiple matching packages
-
YCPValue
PkgModuleFunctions::PkgProperties (const YCPString& p)
{
+ if (p.isNull())
+ {
+ return YCPVoid();
+ }
+
try
{
- YCPMap data;
- zypp::PoolItem_Ref item;
- zypp::Package::constPtr pkg = find_package( p->value(), item, zypp_ptr()->pool() );
+ zypp::ui::Selectable::Ptr s = zypp::ui::Selectable::get(p->value());
- if (item)
- return PkgProp( item );
+ if (s)
+ {
+ return PkgProp(s->theObj());
+ }
}
catch (...)
{
@@ -1042,13 +872,27 @@
{
try
{
- for (zypp::ResPool::byName_iterator it = zypp_ptr()->pool().byNameBegin(pkgname);
- it != zypp_ptr()->pool().byNameEnd(pkgname); ++it)
+ // access to the Pool of Selectables
+ zypp::ResPoolProxy selectablePool(zypp::ResPool::instance().proxy());
+
+ for_(it, selectablePool.byKindBeginzypp::Package(),
+ selectablePool.byKindEndzypp::Package())
{
- // is it a package?
- if (zypp::isKindzypp::Package(it->resolvable()))
+ zypp::ui::Selectable::Ptr s = (*it);
+
+ if (s)
{
- data->add( PkgProp( *it ) );
+ // iterate over installed packages
+ for_(inst_it, s->installedBegin(), s->installedEnd())
+ {
+ data->add(PkgProp(*inst_it));
+ }
+
+ // iterate over available packages
+ for_(avail_it, s->availableBegin(), s->availableEnd())
+ {
+ data->add(PkgProp(*avail_it));
+ }
}
}
}
@@ -1064,17 +908,13 @@
YCPValue
PkgModuleFunctions::GetPkgLocation (const YCPString& p, bool full_path)
{
- zypp::PoolItem_Ref item;
-
try
{
- zypp::Package::constPtr pkg = find_package( p->value(), item, zypp_ptr()->pool() );
-
- YCPMap data;
+ zypp::Package::constPtr pkg = find_package(p->value());
- if (item) {
- return (full_path) ? YCPString( pkg->location().asString() )
- : YCPString( pkg->location().basename() );
+ if (pkg) {
+ return (full_path) ? YCPString( pkg->location().filename().asString() )
+ : YCPString( pkg->location().filename().basename() );
}
}
catch (...)
@@ -1117,7 +957,29 @@
return GetPkgLocation(p, true);
}
+// a helper function
+YCPList _create_filelist(const zypp::PoolItem &pi)
+{
+ zypp::Package::constPtr package = zypp::dynamic_pointer_cast<const zypp::Package>(pi.resolvable());
+
+ YCPList ret;
+
+ if (!package)
+ {
+ y2error("Not a package");
+ return ret;
+ }
+
+ zypp::Package::FileList files( package->filelist() );
+ // insert the file names
+ for_( it, files.begin(), files.end() )
+ {
+ ret->add(YCPString(*it));
+ }
+
+ return ret;
+}
/**
* @builtin PkgGetFilelist
@@ -1141,61 +1003,84 @@
{
std::string pkgname = package->value();
std::string type = which->symbol();
- YCPList ret;
if (type != "any" && type != "installed" && type != "candidate")
{
y2error("PkgGetFilelist: Unknown parameter, use `any, `installed or `candidate");
- return ret;
+ return YCPList();
}
if (!pkgname.empty())
{
try
{
- for (zypp::ResPool::byName_iterator it = zypp_ptr()->pool().byNameBegin(pkgname);
- it != zypp_ptr()->pool().byNameEnd(pkgname); ++it)
+ zypp::ui::Selectable::Ptr s = zypp::ui::Selectable::get(pkgname);
+
+ if (s)
{
- // is it a package?
- if (zypp::isKindzypp::Package(it->resolvable()))
+ if (type == "any")
{
- if (type == "any" ||
- (type == "installed" && it->status().isInstalled()) ||
- (type == "candidate" && it->status().isToBeInstalled())
- )
+ if (s->hasInstalledObj())
{
- // cast to Package object
- zypp::Package::constPtr package = zypp::dynamic_pointer_cast<const zypp::Package>(it->resolvable());
- std::liststd::string files = package->filenames();
-
- // insert the file names
- for (std::list<string>::iterator it = files.begin(); it != files.end(); ++it)
- {
- ret->add(YCPString(*it));
- }
-
-#warning PkgGetFilelist has different semantics for `any optinon - the result depends on item order in the pool, first found is returned
- // finish the loop, we have found required package
- break;
+ return _create_filelist(s->installedObj());
+ }
+ else if (s->hasCandidateObj())
+ {
+ return _create_filelist(s->candidateObj());
+ }
+ else
+ {
+ y2milestone("Package %s is not installed and is not available", pkgname.c_str());
}
}
- }
- }
- catch (...)
- {
- }
- }
-
- return ret;
-}
-
-// ------------------------
+ else if (type == "installed")
+ {
+ if (s->hasInstalledObj())
+ {
+ return _create_filelist(s->installedObj());
+ }
+ else
+ {
+ y2milestone("Package %s is not installed", pkgname.c_str());
+ }
+ }
+ else if (type == "candidate")
+ {
+ if (s->hasCandidateObj())
+ {
+ return _create_filelist(s->candidateObj());
+ }
+ else
+ {
+ y2milestone("Package %s is not available", pkgname.c_str());
+ }
+ }
+ else
+ {
+ y2internal("Unhandled package type %s", type.c_str());
+ }
+ }
+ else
+ {
+ y2warning("Package %s was not found", pkgname.c_str());
+ }
+ }
+ catch (...)
+ {
+ }
+ }
+
+ return YCPList();
+}
+
+bool state_saved = false;
+
+// ------------------------
/**
@builtin SaveState
- @short Save the current selection state - do not use, not implemented
+ @short Save the current selection state, can be restored later using Pkg::RestoreState()
@description
- save the current package selection status for later
- retrieval via Pkg::RestoreState()
+ Save the current status of all resolvables for later restoration via Pkg::RestoreState() function. Only one state is stored, the following call will rewrite the saved status.
@return boolean
@see Pkg::RestoreState
@@ -1204,15 +1089,24 @@
YCPValue
PkgModuleFunctions::SaveState ()
{
-# warning SaveState is not implemented
- return YCPBoolean (true);
+ // a state has been already saved, it will be lost...
+ if (state_saved)
+ {
+ y2warning("Pkg::SaveState() has been already called, rewriting the saved state...");
+ }
+
+ y2milestone("Saving status...");
+ zypp_ptr()->poolProxy().saveState();
+ state_saved = true;
+
+ return YCPBoolean(true);
}
// ------------------------
/**
@builtin RestoreState
- @short Restore Saved state - do not use, not implemented
+ @short Restore Saved state - restore the state saved by Pkg::SaveState()
@description
restore the package selection status from a former
call to Pkg::SaveState()
@@ -1228,26 +1122,41 @@
YCPValue
PkgModuleFunctions::RestoreState (const YCPBoolean& ch)
{
-# warning RestoreState is not implemented
+ bool ret = false;
+
if (!ch.isNull () && ch->value () == true)
{
- // return YCPBoolean (_y2pm.packageSelectionDiffState());
+ // check only
+ ret = zypp_ptr()->poolProxy().diffState();
}
- return YCPBoolean(false /*_y2pm.packageSelectionRestoreState()*/);
+ else
+ {
+ if (!state_saved)
+ {
+ y2error("No previous state saved, state cannot be restored");
+ }
+ else
+ {
+ y2milestone("Restoring the saved status...");
+ zypp_ptr()->poolProxy().restoreState();
+ ret = true;
+ }
+ }
+
+ return YCPBoolean(ret);
}
// ------------------------
/**
@builtin ClearSaveState
- @short clear a saved state (to reduce memory consumption) - do not use, not implemented
+ @short Clear the saved state - do not use, does nothing (the saved state cannot be removed, it is part of each resolvable object)
@return boolean
*/
YCPValue
PkgModuleFunctions::ClearSaveState ()
{
-# warning ClearSaveState is not implemented
return YCPBoolean (true);
}
@@ -1267,12 +1176,15 @@
{
try
{
- for (zypp::ResPool::byKind_iterator it = zypp_ptr()->pool().byKindBegin(zypp::ResTraitszypp::Package::kind);
- it != zypp_ptr()->pool().byKindEnd(zypp::ResTraitszypp::Package::kind);
- ++it)
+ // access to the Pool of Selectables
+ zypp::ResPoolProxy selectablePool(zypp::ResPool::instance().proxy());
+
+ for_(it, selectablePool.byKindBeginzypp::Package(),
+ selectablePool.byKindEndzypp::Package())
{
- // return true if there is a package installed/removed by user
- if ((it->status().isToBeInstalled() || it->status().isToBeUninstalled()) && it->status().isByUser())
+ zypp::ui::Selectable::Ptr s = (*it);
+
+ if (s && s->fate() != zypp::ui::Selectable::UNMODIFIED && s->modifiedBy() == zypp::ResStatus::USER)
{
return YCPBoolean(true);
}
@@ -1289,7 +1201,7 @@
/**
@builtin PkgAnyToDelete
- @short Check if there are any package to be deleted
+ @short Check if there are any package to be deleted - obsoleted
@description
return true if any packages are to be deleted
@return boolean
@@ -1298,35 +1210,15 @@
YCPValue
PkgModuleFunctions::PkgAnyToDelete ()
{
- bool ret = false;
-
y2warning("Pkg::PkgAnyToDelete() is obsoleted, use Pkg::IsAnyResolvable(`package, `to_remove) instead");
-
- try
- {
- for (zypp::ResPool::byKind_iterator it = zypp_ptr()->pool().byKindBegin(zypp::ResTraitszypp::Package::kind);
- it != zypp_ptr()->pool().byKindEnd(zypp::ResTraitszypp::Package::kind);
- ++it)
- {
- if (it->status().isToBeUninstalled())
- {
- ret = true;
- break;
- }
- }
- }
- catch (...)
- {
- }
-
- return YCPBoolean(ret);
+ return IsAnyResolvable(YCPSymbol("package"), YCPSymbol("to_remove"));
}
// ------------------------
/**
@builtin AnyToInstall
- @short Check if there are any package to be installed
+ @short Check if there are any package to be installed - obsoleted
@description
return true if any packages are to be installed
@return boolean
@@ -1335,33 +1227,12 @@
YCPValue
PkgModuleFunctions::PkgAnyToInstall ()
{
- bool ret = false;
-
y2warning("Pkg::PkgAnyToInstall() is obsoleted, use Pkg::IsAnyResolvable(`package, `to_install) instead");
-
- try
- {
- for (zypp::ResPool::byKind_iterator it = zypp_ptr()->pool().byKindBegin(zypp::ResTraitszypp::Package::kind);
- it != zypp_ptr()->pool().byKindEnd(zypp::ResTraitszypp::Package::kind);
- ++it)
- {
- if (it->status().isToBeInstalled())
- {
- ret = true;
- break;
- }
- }
- }
- catch (...)
- {
- }
-
- return YCPBoolean(ret);
+ return IsAnyResolvable(YCPSymbol("package"), YCPSymbol("to_install"));
}
// ------------------------
-
/* helper function */
static void
pkg2list (YCPList &list, const zypp::ResPool::byKind_iterator& it, bool names_only)
@@ -1381,7 +1252,6 @@
return;
}
-
/**
@builtin FilterPackages
@@ -1517,60 +1387,18 @@
return packages;
}
-
/**
* @builtin PkgUpdateAll
- * @param map update_options Options for the solver. All parameters are optional, if a parameter is missing the default value from the package manager (libzypp) is used. Currently supported options: <tt>$["delete_unmaintained":boolean, "silent_downgrades":boolean, "keep_installed_patches":boolean]</tt>
+ * @param map update_options Options for the solver. All parameters are optional,
+ * if a parameter is missing the default value from the package manager (libzypp) is used.
+ * Currently supported options: <tt>NONE</tt>
+ *
* @short Update installed packages
* @description
- * Mark all packages for installation which are installed and have
- * an available candidate for update.
- *
- * This will mark packages for installation *and* for deletion (if a
- * package provides/obsoletes another package)
- *
- * This function does not solve dependencies.
- *
- * Symbols and integer values returned:
- *
- * <b>ProblemListSze</b>: Number of taboo and dropped packages found.
- *
- * <b>DeleteUnmaintained</b>: Whether delete_unmaintained arg was true or false.
- * Dependent on this, <b>SumDropped</b> below either denotes packages to delete
- * (if true) or packages to keep (if false).
- *
- * <b>SumProcessed</b>: TOTAL number of installed packages we processed.
- *
- * <b>SumToInstall</b>: TOTAL number of packages now tagged as to install.
- * Summs <b>Ipreselected</b>, <b>Iupdate</b>, <b>Idowngrade</b>, <b>Ireplaced</b>.
- *
- * <b>Ipreselected</b>: Packages which were already taged to install.
- *
- * <b>Iupdate</b>: Packages set to install as update to a newer version.
- *
- * <b>Idowngrade</b>: Packages set to install performing a version downgrade.
- *
- * <b>Ireplaced</b>: Packages set to install as they replace an installed package.
+ * Perform a distribution upgrade. This function solves
+ * dependencies.
*
- * <b>SumToDelete</b>: TOTAL number of packages now tagged as to delete.
- * Summs <b>Dpreselected</b>, <b>SumDropped</b> if <b>DeleteUnmaintained</b>
- * was set.
- *
- * <b>Dpreselected</b>: Packages which were already taged to delete.
- *
- * <b>SumToKeep</b>: TOTAL number of packages which remain unchanged.
- * Summs <b>Ktaboo</b>, <b>Knewer</b>, <b>Ksame</b>, <b>SumDropped</b>
- * if <b>DeleteUnmaintained</b> was not set.
- *
- * <b>Ktaboo</b>: Packages which are set taboo.
- *
- * <b>Knewer</b>: Packages kept because only older versions are available.
- *
- * <b>Ksame</b>: Packages kept because they are up to date.
- *
- * <b>SumDropped</b>: TOTAL number of dropped packages found. Dependent
- * on the delete_unmaintained arg, they are either tagged as to delete or
- * remain unchanged.
+ * Symbols and integer values returned: <tt>NONE</tt>
*
* @return map summary of the update
*/
@@ -1578,48 +1406,30 @@
YCPValue
PkgModuleFunctions::PkgUpdateAll (const YCPMap& options)
{
- zypp::UpgradeStatistics stats;
+ // NOTE(ma): Since libzypp switched to use libsatsolver for distribution upgrade,
+ // there are no more in-/output arguments to doUpgrade. The statistics previously
+ // returned from resolver()->doUpgrade(stats) via the UpgradeStatistics argument
+ // no longer exist. If some feedback is required here, libzypp could offer sort of
+ // transaction summary. Such a summary woulfd not be tied to the distribution upgrade,
+ // but would be available all the time and reflect the status of the zypp pool.
+
YCPValue delete_unmaintained = options->value(YCPString("delete_unmaintained"));
if(!delete_unmaintained.isNull())
{
- if (delete_unmaintained->isBoolean())
- {
- stats.delete_unmaintained = delete_unmaintained->asBoolean()->value();
- }
- else
- {
- y2error("unexpected type of 'delete_unmaintained' key: %s, must be a boolean!",
- Type::vt2type(delete_unmaintained->valuetype())->toString().c_str());
- }
+ y2error("'delete_unmaintained' flag is obsoleted and should not be used, check the code!");
}
YCPValue silent_downgrades = options->value(YCPString("silent_downgrades"));
if(!silent_downgrades.isNull())
{
- if (silent_downgrades->isBoolean())
- {
- stats.silent_downgrades = silent_downgrades->asBoolean()->value();
- }
- else
- {
- y2error("unexpected type of 'silent_downgrades' key: %s, must be a boolean!",
- Type::vt2type(silent_downgrades->valuetype())->toString().c_str());
- }
+ y2error("'silent_downgrades' flag is obsoleted and should not be used, check the code!");
}
YCPValue keep_installed_patches = options->value(YCPString("keep_installed_patches"));
if(!keep_installed_patches.isNull())
{
- if (keep_installed_patches->isBoolean())
- {
- stats.keep_installed_patches = keep_installed_patches->asBoolean()->value();
- }
- else
- {
- y2error("unexpected type of 'keep_installed_patches' key: %s, must be a boolean!",
- Type::vt2type(keep_installed_patches->valuetype())->toString().c_str());
- }
+ y2error("'keep_installed_patches' flag is obsoleted and should not be used, check the code!");
}
@@ -1628,46 +1438,14 @@
try
{
// solve upgrade, get statistics
- zypp_ptr()->resolver()->doUpgrade(stats);
+ zypp_ptr()->resolver()->doUpgrade();
}
catch (...)
- {
- return data;
- }
-
- data->add( YCPSymbol("ProblemListSze"), YCPInteger(stats.chk_is_taboo + stats.chk_dropped));
-
- // packages to install; sum and details
- data->add( YCPSymbol("SumToInstall"), YCPInteger( stats.totalToInstall() ) );
- data->add( YCPSymbol("Ipreselected"), YCPInteger( stats.chk_already_toins ) );
- data->add( YCPSymbol("Iupdate"), YCPInteger( stats.chk_to_update ) );
- data->add( YCPSymbol("Idowngrade"), YCPInteger( stats.chk_to_downgrade ) );
- data->add( YCPSymbol("Ireplaced"), YCPInteger( stats.chk_replaced
- + stats.chk_replaced_guessed
- + stats.chk_add_split ) );
- // packages to delete; sum and details (! see dropped packages)
- data->add( YCPSymbol("SumToDelete"), YCPInteger( stats.totalToDelete() ) );
- data->add( YCPSymbol("Dpreselected"), YCPInteger( stats.chk_already_todel ) );
-
- // packages to delete; sum and details (! see dropped packages)
- data->add( YCPSymbol("SumToKeep"), YCPInteger( stats.totalToKeep() ) );
- data->add( YCPSymbol("Ktaboo"), YCPInteger( stats.chk_is_taboo ) );
- data->add( YCPSymbol("Knewer"), YCPInteger( stats.chk_to_keep_downgrade ) );
- data->add( YCPSymbol("Ksame"), YCPInteger( stats.chk_to_keep_installed ) );
-
- // dropped packages; dependent on the delete_unmaintained
- // option set for doUpdate, dropped packages count as ToDelete
- // or ToKeep.
- data->add( YCPSymbol("SumDropped"), YCPInteger( stats.chk_dropped ) );
- data->add( YCPSymbol("DeleteUnmaintained"),YCPInteger( stats.delete_unmaintained ) );
-
- // Total mumber of installed packages processed
- data->add( YCPSymbol("SumProcessed"), YCPInteger( stats.chk_installed_total ) );
+ {}
return data;
}
-
/**
@builtin PkgInstall
@short Select package for installation
@@ -1712,21 +1490,29 @@
if (name.empty())
return YCPBoolean (false);
- // ensure installation of the 'best' architecture
+ bool ret = false;
+ zypp::ui::Selectable::Ptr selectable = zypp::ui::Selectable::get(zypp::ResKind::srcpackage, name);
- return YCPBoolean( DoProvideNameKind( name, zypp::ResTraitszypp::SrcPackage::kind, zypp_ptr()->architecture(), "" ) );
-}
+ if (selectable)
+ {
+ ret = selectable->setToInstall(whoWantsIt);
+ }
+ else
+ {
+ y2error("Source package %s is not available", name.c_str());
+ }
+ return YCPBoolean(ret);
+}
/**
@builtin PkgDelete
- @short Select package for deletion
+ @short Select package for deletion (deletes all installed instances of the package)
@param string package
@return boolean
*/
-#warning This is bogus, as we have multiple matching (kernel) packages
YCPValue
PkgModuleFunctions::PkgDelete (const YCPString& p)
@@ -1735,31 +1521,24 @@
if (name.empty())
return YCPBoolean (false);
+ bool ret = false;
+
try
{
- // find the package
- zypp::ResPool::byName_iterator it = std::find_if (
- zypp_ptr()->pool().byNameBegin(name)
- , zypp_ptr()->pool().byNameEnd(name)
- , zypp::functor::chain (
- zypp::resfilter::ByInstalled (),
- zypp::resfilter::ByKind( zypp::ResTraitszypp::Package::kind )
- )
- );
-
+ zypp::ui::Selectable::Ptr selectable = zypp::ui::Selectable::get(name);
- // set the status to uninstalled
- return YCPBoolean( (it != zypp_ptr()->pool().byNameEnd(name))
- && it->status().setToBeUninstalled(whoWantsIt) );
+ if (selectable)
+ {
+ ret = selectable->setToDelete(whoWantsIt);
+ }
}
catch (...)
{
}
- return YCPBoolean (false);
+ return YCPBoolean(ret);
}
-
/**
@builtin PkgTaboo
@@ -1776,38 +1555,20 @@
if (name.empty())
return YCPBoolean (false);
- bool ret = true;
+ bool ret = false;
try
{
- bool found = false;
-
- for (zypp::ResPool::byName_iterator it = zypp_ptr()->pool().byNameBegin(name);
- it != zypp_ptr()->pool().byNameEnd(name); ++it)
- {
- // is it a package?
- // installed package cannot be set to taboo
- if (zypp::isKindzypp::Package(it->resolvable()) && !it->status().isInstalled())
- {
- found = true;
-
- bool res = it->status().resetTransact(whoWantsIt)
- // lock the package at the USER level (bug #186205)
- && it->status().resetTransact(zypp::ResStatus::USER)
- && it->status().setLock(true, zypp::ResStatus::USER);
-
- ret = ret && res;
- }
- }
+ zypp::ui::Selectable::Ptr selectable = zypp::ui::Selectable::get(name);
- if (!found)
+ if (selectable)
{
- ret = false;
+ // lock the package at the USER level (bug #186205)
+ ret = selectable->setStatus(zypp::ui::S_Taboo, zypp::ResStatus::USER);
}
}
catch (...)
{
- ret = false;
}
return YCPBoolean(ret);
@@ -1829,39 +1590,53 @@
if (name.empty())
return YCPBoolean (false);
- bool ret = true;
+ bool ret = false;
try
{
- bool found = false;
+ zypp::ui::Selectable::Ptr selectable = zypp::ui::Selectable::get(name);
- for (zypp::ResPool::byName_iterator it = zypp_ptr()->pool().byNameBegin(name);
- it != zypp_ptr()->pool().byNameEnd(name); ++it)
+ if (selectable)
{
- // is it a package?
- if (zypp::isKindzypp::Package(it->resolvable()))
- {
- found = true;
- ret = it->status().resetTransact(whoWantsIt) && ret;
- }
- }
-
- if (!found)
- {
- ret = false;
+ ret = selectable->unset(whoWantsIt);
}
}
catch (...)
{
- ret = false;
}
return YCPBoolean(ret);
}
+template <class T>
+inline void ResetAllKind(zypp::ResPoolProxy &proxy, const zypp::ResStatus::TransactByValue &level)
+{
+ for_(it, proxy.byKindBegin<T>(), proxy.byKindEnd<T>())
+ {
+ zypp::ui::Selectable::Ptr s = (*it);
+ if (s && (level == zypp::ResStatus::USER || s->theObj().status().transacts()))
+ {
+ s->theObj().status().resetTransact(level);
+ }
+ }
+}
+
+
+void ResetAll(const zypp::ResStatus::TransactByValue &level)
+{
+ // access to the Pool of Selectables
+ zypp::ResPoolProxy selectablePool(zypp::ResPool::instance().proxy());
+
+ // unset all packages, patterns...
+ ResetAllKindzypp::Package(selectablePool, level);
+ ResetAllKindzypp::Pattern(selectablePool, level);
+ ResetAllKindzypp::Patch(selectablePool, level);
+ ResetAllKindzypp::Product(selectablePool, level);
+ ResetAllKindzypp::SrcPackage(selectablePool, level);
+}
/**
- * @builtin Reset
+ * @builtin PkgReset
*
* @short Reset most internal stuff on the package manager.
@return boolean
@@ -1872,14 +1647,7 @@
{
try
{
- for (zypp::ResPool::const_iterator it = zypp_ptr()->pool().begin()
- ; it != zypp_ptr()->pool().end()
- ; ++it)
- {
- // reset all transaction flags
- it->statusReset();
- }
-
+ ResetAll(zypp::ResStatus::USER);
return YCPBoolean (true);
}
catch (...)
@@ -1889,9 +1657,8 @@
return YCPBoolean (false);
}
-
/**
- * @builtin Reset
+ * @builtin PkgApplReset
*
* @short Reset most internal stuff on the package manager.
Reset only packages set by the application, not by the user
@@ -1903,14 +1670,7 @@
{
try
{
- for (zypp::ResPool::const_iterator it = zypp_ptr()->pool().begin()
- ; it != zypp_ptr()->pool().end()
- ; ++it)
- {
- // reset all transaction flags
- it->status().resetTransact(zypp::ResStatus::APPL_HIGH);
- }
-
+ ResetAll(whoWantsIt);
return YCPBoolean (true);
}
catch (...)
@@ -1920,11 +1680,35 @@
return YCPBoolean (false);
}
+void SaveProblemList(const zypp::ResolverProblemList &problems, const std::string &filename)
+{
+ try
+ {
+ int problem_size = problems.size();
+
+ if (problem_size > 0)
+ {
+ y2error ("PkgSolve: %d packages failed (see %s)", problem_size, filename.c_str());
+
+ std::ofstream out (filename.c_str());
+
+ out << problem_size << " packages failed" << std::endl;
+ for(zypp::ResolverProblemList::const_iterator p = problems.begin();
+ p != problems.end(); ++p )
+ {
+ out << (*p)->description() << std::endl;
+ }
+ }
+ }
+ catch (...)
+ {
+ }
+}
/**
@builtin PkgSolve
@short Solve current package dependencies
- @optarg booean filter filter all conflicts with installed packages
+ @optarg boolean filter unused, only for backward compatibility
(installed packages will be preferred)
@return boolean
@@ -1940,54 +1724,24 @@
}
catch (const zypp::Exception& excpt)
{
- y2error("An error occurred during Pkg::PkgSolve.");
+ y2error("An error occurred during Pkg::Solve.");
_last_error.setLastError(excpt.asUserString(), "See /var/log/YaST2/badlist for more information.");
+ result = false;
}
// save information about failed dependencies to file
if (!result)
{
-# warning PkgSolve: filter option is not used
-/* bool filter_conflicts_with_installed = false;
-
- if (! filter.isNull())
- {
- filter_conflicts_with_installed = filter->value();
- }
-*/
-
- try
- {
- zypp::ResolverProblemList problems = zypp_ptr()->resolver()->problems();
- int problem_size = problems.size();
-
- if (problem_size > 0)
- {
- y2error ("PkgSolve: %d packages failed (see /var/log/YaST2/badlist)", problem_size);
-
- std::ofstream out ("/var/log/YaST2/badlist");
-
- out << problem_size << " packages failed" << std::endl;
- for(zypp::ResolverProblemList::const_iterator p = problems.begin();
- p != problems.end(); ++p )
- {
- out << (*p)->description() << std::endl;
- }
- }
- }
- catch (...)
- {
- return YCPBoolean(false);
- }
+ zypp::ResolverProblemList problems = zypp_ptr()->resolver()->problems();
+ SaveProblemList(problems, "/var/log/YaST2/badlist");
}
return YCPBoolean(result);
}
-
/**
@builtin PkgEstablish
- @short establish the pool state
+ @short establish the pool state - obsoleted, not needed
@return boolean
Returns true. (If no pool item 'transacts')
@@ -2000,53 +1754,12 @@
YCPBoolean
PkgModuleFunctions::PkgEstablish ()
{
- bool result = false;
-
- try
- {
- result = zypp_ptr()->resolver()->establishPool();
- }
- catch (const zypp::Exception& excpt)
- {
- y2error("An error occurred during Pkg::PkgEstablish.");
- _last_error.setLastError(excpt.asUserString(), "See /var/log/YaST2/badlist for more information.");
- }
-
- // save information about failed dependencies to file
- if (!result)
- {
- try
- {
- zypp::ResolverProblemList problems = zypp_ptr()->resolver()->problems();
- int problem_size = problems.size();
-
- if (problem_size > 0)
- {
- y2error ("PkgSolve: %d packages failed (see /var/log/YaST2/badlist)", problem_size);
-
- std::ofstream out ("/var/log/YaST2/badlist");
-
- out << problem_size << " packages failed" << std::endl;
- for(zypp::ResolverProblemList::const_iterator p = problems.begin();
- p != problems.end(); ++p )
- {
- out << (*p)->description() << std::endl;
- }
- }
- }
- catch (...)
- {
- return YCPBoolean(false);
- }
- }
-
- return YCPBoolean(result);
+ return YCPBoolean(false);
}
-
/**
@builtin PkgFreshen
- @short check all package freshens and schedule matching ones for installation
+ @short check all package freshens and schedule matching ones for installation - obsoleted, not needed
@return boolean
Returns true. (If no pool item 'transacts')
@@ -2056,103 +1769,51 @@
If it has, dependencies will be solved and the returned result might be false.
*/
-
+#warning Freshens is obsolete
YCPBoolean
PkgModuleFunctions::PkgFreshen()
{
- bool result = false;
-
- try
- {
- result = zypp_ptr()->resolver()->freshenPool();
- }
- catch (const zypp::Exception& excpt)
- {
- y2error("An error occurred during Pkg::PkgFreshen.");
- _last_error.setLastError(excpt.asUserString(), "See /var/log/YaST2/badlist for more information.");
- }
-
- // save information about failed dependencies to file
- if (!result)
- {
- try
- {
- zypp::ResolverProblemList problems = zypp_ptr()->resolver()->problems();
- int problem_size = problems.size();
-
- if (problem_size > 0)
- {
- y2error ("PkgSolve: %d packages failed (see /var/log/YaST2/badlist)", problem_size);
-
- std::ofstream out ("/var/log/YaST2/badlist");
-
- out << problem_size << " packages failed" << std::endl;
- for(zypp::ResolverProblemList::const_iterator p = problems.begin();
- p != problems.end(); ++p )
- {
- out << (*p)->description() << std::endl;
- }
- }
- }
- catch (...)
- {
- return YCPBoolean(false);
- }
- }
-
- return YCPBoolean(result);
+ return YCPBoolean(true);
}
-
/**
@builtin PkgSolveCheckTargetOnly
@short Solve packages currently installed on target system.
@description
- Solve packages currently installed on target system. Packages status
- remains unchanged, i.e. does not select/deselect any packages to
- resolve failed dependencies.
+ Solve packages currently installed on target system.
+ All transactions are reset after the call!
@return boolean
*/
YCPBoolean
PkgModuleFunctions::PkgSolveCheckTargetOnly()
{
- // create pool just with objects from target
- zypp::ResStore store;
-
try
{
- store = zypp_ptr()->target()->resolvables();
+ zypp_ptr()->target()->load();
}
catch (...)
{
return YCPBoolean(false);
}
- zypp::ResPoolManager pool;
- pool.insert(store.begin(), store.end(), true);
-
- // create resolver
- zypp::Resolver solver(pool.accessor());
-
bool result = false;
try
{
// verify consistency of system
- result = solver.verifySystem();
+ result = zypp_ptr()->resolver()->verifySystem();
}
catch (const zypp::Exception& excpt)
{
y2error("An error occurred during Pkg::PkgSolveCheckTargetOnly");
- _last_error.setLastError(excpt.asUserString());
+ _last_error.setLastError(ExceptionAsString(excpt));
}
return YCPBoolean(result);
}
-
/**
@builtin PkgSolveErrors
@short Returns number of fails
@@ -2176,31 +1837,8 @@
return YCPVoid();
}
-/**
- @builtin PkgCommit
-
- @short Commit package changes (actually install/delete packages)
- @description
-
- if medianr == 0, all packages regardless of media are installed
-
- if medianr > 0, only packages from this media are installed
-
- @param integer medianr Media Number
- @return list [ int successful, list failed, list remaining, list srcremaining ]
- The 'successful' value will be negative, if installation was aborted !
-
-*/
-YCPValue
-PkgModuleFunctions::PkgCommit (const YCPInteger& media)
+YCPValue PkgModuleFunctions::CommitHelper(const zypp::ZYppCommitPolicy &policy)
{
- int medianr = media->value ();
-
- if (medianr < 0)
- {
- return YCPError ("Bad args to Pkg::PkgCommit");
- }
-
zypp::ZYpp::CommitResult result;
// clean the last reported source
@@ -2209,32 +1847,30 @@
try
{
- zypp::ZYppCommitPolicy policy;
- policy.restrictToMedia( medianr );
+ // reset the values for SourceChanged callback
+ last_reported_repo = -1;
+ last_reported_mediumnr = 1;
+
result = zypp_ptr()->commit(policy);
}
catch (const zypp::target::TargetAbortedException & excpt)
{
y2milestone ("Installation aborted by user");
YCPList ret;
- ret->add(YCPInteger(-1LL));
+ ret->add(YCPInteger(-1));
return ret;
}
catch (const zypp::Exception& excpt)
{
y2error("Pkg::Commit has failed: ZYpp::commit has failed");
- _last_error.setLastError(excpt.asUserString());
+ _last_error.setLastError(ExceptionAsString(excpt));
return YCPVoid();
}
- try {
- zypp::SourceManager::sourceManager()->releaseAllSources();
- }
- catch (const zypp::Exception& excpt)
- {
- y2error("Pkg::Commit has failed: cannot release all sources");
- _last_error.setLastError(excpt.asUserString());
- }
+ SourceReleaseAll();
+
+ // create the base product link (bnc#413444)
+ CreateBaseProductSymlink();
YCPList ret;
@@ -2257,12 +1893,6 @@
resolvable->add (YCPString ("kind"), YCPSymbol ("product"));
else if (zypp::isKindzypp::Pattern(it->resolvable()))
resolvable->add (YCPString ("kind"), YCPSymbol ("pattern"));
- else if (zypp::isKindzypp::Selection(it->resolvable()))
- resolvable->add (YCPString ("kind"), YCPSymbol ("selection"));
- else if (zypp::isKindzypp::Script(it->resolvable()))
- resolvable->add (YCPString ("kind"), YCPSymbol ("script"));
- else if (zypp::isKindzypp::Message(it->resolvable()))
- resolvable->add (YCPString ("kind"), YCPSymbol ("message"));
else if (zypp::isKindzypp::Patch(it->resolvable()))
resolvable->add (YCPString ("kind"), YCPSymbol ("patch"));
else
@@ -2286,6 +1916,37 @@
}
/**
+ @builtin PkgCommit
+
+ @short Commit package changes (actually install/delete packages), see also Pkg::Commit()
+ @description
+
+ if medianr == 0, all packages regardless of media are installed
+
+ if medianr > 0, only packages from this media are installed
+
+ @param integer medianr Media Number
+ @return list [ int successful, list failed, list remaining, list srcremaining ]
+ The 'successful' value will be negative, if installation was aborted !
+
+*/
+YCPValue
+PkgModuleFunctions::PkgCommit (const YCPInteger& media)
+{
+ int medianr = media->value ();
+
+ if (medianr < 0)
+ {
+ return YCPError ("Bad args to Pkg::PkgCommit");
+ }
+
+ zypp::ZYppCommitPolicy policy;
+ policy.restrictToMedia( medianr );
+
+ return CommitHelper(policy);
+}
+
+/**
@builtin GetBackupPath
@short get current path for update backup of rpm config files
@@ -2327,7 +1988,6 @@
return YCPVoid();
}
-
/**
@builtin CreateBackups
@short whether to create package backups during install or removal
@@ -2348,7 +2008,6 @@
return YCPVoid ();
}
-
/**
@builtin PkgGetLicenseToConfirm
@@ -2367,23 +2026,15 @@
{
try
{
- // find the uninstalled (!) package
- zypp::ResPool::byName_iterator it = std::find_if (
- zypp_ptr()->pool().byNameBegin(pkgname)
- , zypp_ptr()->pool().byNameEnd(pkgname)
- , zypp::functor::chain(
- zypp::resfilter::ByUninstalled (),
- zypp::resfilter::ByKind( zypp::ResTraitszypp::Package::kind ) )
- );
+ zypp::ui::Selectable::Ptr s = zypp::ui::Selectable::get(pkgname);
- if (it != zypp_ptr()->pool().byNameEnd(pkgname) && !it->status().isLicenceConfirmed())
+ if (s && s->toInstall() && !s->hasLicenceConfirmed())
{
- // cast to Package object
- zypp::Package::constPtr package = zypp::dynamic_pointer_cast<const zypp::Package>(it->resolvable());
-
- // get the license
- zypp::License license = package->licenseToConfirm();
- return YCPString(license);
+ zypp::Package::constPtr package = zypp::dynamic_pointer_cast<const zypp::Package>(s->candidateObj().resolvable());
+ if (package)
+ {
+ return YCPString(package->licenseToConfirm());
+ }
}
}
catch (...)
@@ -2410,38 +2061,12 @@
YCPMap ret;
for ( int i = 0; i < packages->size(); ++i ) {
- std::string pkgname = packages->value(i)->asString()->value();
+ YCPString license = PkgGetLicenseToConfirm(packages->value(i)->asString());
- if (!pkgname.empty())
+ // found a license to confirm?
+ if (!license->value().empty())
{
- try
- {
- // find the uninstalled (!) package
- zypp::ResPool::byName_iterator it = std::find_if(
- zypp_ptr()->pool().byNameBegin(pkgname)
- , zypp_ptr()->pool().byNameEnd(pkgname)
- , zypp::functor::chain(
- zypp::resfilter::ByUninstalled (),
- zypp::resfilter::ByKind( zypp::ResTraitszypp::Package::kind ) )
- );
-
- // found a package?
- if (it != zypp_ptr()->pool().byNameEnd(pkgname))
- {
- // cast to Package object
- zypp::Package::constPtr package = zypp::dynamic_pointer_cast<const zypp::Package>(it->resolvable());
- zypp::License license = package->licenseToConfirm();
-
- // has the license already been confirmed?
- if (!license.empty() && !it->status().isLicenceConfirmed())
- {
- ret->add(packages->value(i), YCPString(license));
- }
- }
- }
- catch (...)
- {
- }
+ ret->add(packages->value(i), license);
}
}
@@ -2455,7 +2080,6 @@
@param string name of a package
@return boolean true if the license has been successfuly confirmed
*/
-#warning This is bogus, as we have multiple matching packages
YCPBoolean PkgModuleFunctions::PkgMarkLicenseConfirmed (const YCPString & package)
{
std::string pkgname = package->value();
@@ -2464,20 +2088,12 @@
{
try
{
- // find the package
- zypp::ResPool::byName_iterator it = std::find_if(
- zypp_ptr()->pool().byNameBegin(pkgname)
- , zypp_ptr()->pool().byNameEnd(pkgname)
- , zypp::functor::chain(
- zypp::resfilter::ByUninstalled (),
- zypp::resfilter::ByKind( zypp::ResTraitszypp::Package::kind ) )
- );
+ zypp::ui::Selectable::Ptr s = zypp::ui::Selectable::get(pkgname);
- if (it != zypp_ptr()->pool().byNameEnd(pkgname))
+ if (s && s->toInstall() && !s->hasLicenceConfirmed())
{
- // confirm the license
- it->status().setLicenceConfirmed(true);
- return YCPBoolean( true );
+ s->setLicenceConfirmed();
+ return YCPBoolean(true);
}
}
catch (...)
@@ -2506,3 +2122,4 @@
return YCPBoolean(false);
}
+
Modified: branches/tmp/dmacvicar/zc10/pkg-bindings/src/PkgModuleFunctions.cc
URL: http://svn.opensuse.org/viewcvs/yast/branches/tmp/dmacvicar/zc10/pkg-bindings/src/PkgModuleFunctions.cc?rev=63940&r1=63939&r2=63940&view=diff
==============================================================================
--- branches/tmp/dmacvicar/zc10/pkg-bindings/src/PkgModuleFunctions.cc (original)
+++ branches/tmp/dmacvicar/zc10/pkg-bindings/src/PkgModuleFunctions.cc Tue May 10 20:10:47 2011
@@ -175,7 +175,10 @@
: Y2Namespace()
, _target_root( "/" )
, zypp_pointer(NULL)
+ , last_reported_repo(-1)
+ , last_reported_mediumnr(-1)
,_callbackHandler( *new CallbackHandler( ) )
+ , _target_loaded(false)
{
registerFunctions ();
@@ -230,6 +233,15 @@
return zypp_pointer;
}
+zypp::RepoManager PkgModuleFunctions::CreateRepoManager()
+{
+ // set path option, use root dir as a prefix for the default directory
+ zypp::RepoManagerOptions repo_options(_target_root);
+
+ y2milestone("Path to repository files: %s", repo_options.knownReposPath.asString().c_str());
+
+ return zypp::RepoManager(repo_options);
+}
/**
* Destructor.
Modified: branches/tmp/dmacvicar/zc10/pkg-bindings/src/PkgModuleFunctions.h
URL: http://svn.opensuse.org/viewcvs/yast/branches/tmp/dmacvicar/zc10/pkg-bindings/src/PkgModuleFunctions.h?rev=63940&r1=63939&r2=63940&view=diff
==============================================================================
--- branches/tmp/dmacvicar/zc10/pkg-bindings/src/PkgModuleFunctions.h (original)
+++ branches/tmp/dmacvicar/zc10/pkg-bindings/src/PkgModuleFunctions.h Tue May 10 20:10:47 2011
@@ -42,9 +42,12 @@
#include
#include
#include
+#include
#include
#include "PkgError.h"
-
+#include "YRepo.h"
+#include "Utils.h"
+#include "ServiceManager.h"
// textdomain
extern "C" {
@@ -59,7 +62,6 @@
// define new _ macro
#define _(MSG) ::dgettext("pkg-bindings", MSG)
-
/**
* A simple class for package management access
*/
@@ -75,6 +77,16 @@
protected:
+ // container for the internal structure
+ typedef std::vector RepoCont;
+
+ zypp::RepoManager CreateRepoManager();
+ ServiceManager service_manager;
+
+ public:
+ typedef RepoCont::size_type RepoId;
+ protected:
+
zypp::Pathname _target_root;
std::setstd::string _broken_sources;
@@ -94,6 +106,20 @@
private: // source related
+ YCPValue CommitHelper(const zypp::ZYppCommitPolicy &policy);
+
+ zypp::Product::constPtr base_product;
+ RepoId last_reported_repo;
+ int last_reported_mediumnr;
+
+ bool CreateBaseProductSymlink();
+
+ // all known installation sources
+ RepoCont repos;
+
+ // helper
+ YCPValue PkgMediaSizesOrCount (bool sizes, bool download_size=false);
+
bool DoProvideNameKind( const std::string & name, zypp::Resolvable::Kind kind, zypp::Arch architecture,
const std::string& version, const bool onlyNeeded = false);
bool DoRemoveNameKind( const std::string & name, zypp::Resolvable::Kind kind);
@@ -101,7 +127,7 @@
bool DoRemoveAllKind(zypp::Resolvable::Kind kind);
bool DoAllKind(zypp::Resolvable::Kind kind, bool provide);
YCPValue GetPkgLocation(const YCPString& p, bool full_path);
- YCPValue PkgProp( zypp::PoolItem item );
+ YCPValue PkgProp( const zypp::PoolItem &item );
void SetCurrentDU();
@@ -128,16 +154,30 @@
**/
CallbackHandler & _callbackHandler;
+ bool _target_loaded;
+
PkgError _last_error;
/**
* Logging helper:
- * call zypp::SourceManager::sourceManager()->findSource
- * and in case of exception, log error and setLastError AND RETHROW
+ * search for a repository and in case of exception, log error
+ * and setLastError AND RETHROW
*/
- //zypp::Source_Ref logFindSource (zypp::SourceManager::SourceId id);
+ YRepo_Ptr logFindRepository(RepoId id);
+
+ RepoId logFindAlias(const std::string &alias) const;
+
+ YCPMap Resolvable2YCPMap(const zypp::PoolItem &item, const std::string &req_kind, bool dependencies);
+
+ YCPValue SourceProvideDirectoryInternal(const YCPInteger& id, const YCPInteger& mid, const YCPString& d, const YCPBoolean &optional, const YCPBoolean &recursive, bool check_signatures);
+ YCPValue SourceProvideFileCommon(const YCPInteger &id,
+ const YCPInteger &mid,
+ const YCPString& f,
+ const bool optional,
+ const bool check_signatures,
+ const bool digested);
+public:
- public:
// general
/* TYPEINFO: void() */
YCPValue InstSysMode ();
Added: branches/tmp/dmacvicar/zc10/pkg-bindings/src/PkgProgress.cc
URL: http://svn.opensuse.org/viewcvs/yast/branches/tmp/dmacvicar/zc10/pkg-bindings/src/PkgProgress.cc?rev=63940&view=auto
==============================================================================
--- branches/tmp/dmacvicar/zc10/pkg-bindings/src/PkgProgress.cc (added)
+++ branches/tmp/dmacvicar/zc10/pkg-bindings/src/PkgProgress.cc Tue May 10 20:10:47 2011
@@ -0,0 +1,25 @@
+
+
+#include "PkgProgress.h"
+#include "log.h"
+
+#include
+
+void PkgProgress::Start( const std::string &process, const std::liststd::string &stages,
+ const std::string &help)
+{
+}
+
+
+void PkgProgress::NextStage()
+{
+}
+
+void PkgProgress::Done()
+{
+}
+
+PkgProgress::~PkgProgress()
+{
+}
+
Added: branches/tmp/dmacvicar/zc10/pkg-bindings/src/PkgProgress.h
URL: http://svn.opensuse.org/viewcvs/yast/branches/tmp/dmacvicar/zc10/pkg-bindings/src/PkgProgress.h?rev=63940&view=auto
==============================================================================
--- branches/tmp/dmacvicar/zc10/pkg-bindings/src/PkgProgress.h (added)
+++ branches/tmp/dmacvicar/zc10/pkg-bindings/src/PkgProgress.h Tue May 10 20:10:47 2011
@@ -0,0 +1,38 @@
+/*
+ File: PkgProgress.h
+
+ Author: Ladislav Slezák
+/-*/
+
+#ifndef PkgProgress_h
+#define PkgProgress_h
+
+#include <string>
+#include <list>
+
+//class PkgFunctions::CallbackHandler;
+#include
+#include
+
+
+#include
+#include
+
+class PkgProgress
+{
+ public:
+
+ PkgProgress(PkgModuleFunctions::CallbackHandler &handler_ref)
+ {}
+
+ void Start( const std::string &process, const std::liststd::string &stages, const std::string &help);
+
+ void NextStage();
+
+ void Done();
+
+ ~PkgProgress();
+};
+
+#endif
+
Added: branches/tmp/dmacvicar/zc10/pkg-bindings/src/PkgService.cc
URL: http://svn.opensuse.org/viewcvs/yast/branches/tmp/dmacvicar/zc10/pkg-bindings/src/PkgService.cc?rev=63940&view=auto
==============================================================================
--- branches/tmp/dmacvicar/zc10/pkg-bindings/src/PkgService.cc (added)
+++ branches/tmp/dmacvicar/zc10/pkg-bindings/src/PkgService.cc Tue May 10 20:10:47 2011
@@ -0,0 +1,56 @@
+/* ------------------------------------------------------------------------------
+ * Copyright (c) 2008 Novell, Inc. All Rights Reserved.
+ *
+ *
+ * This program is free software; you can redistribute it and/or modify it under
+ * the terms of version 2 of the GNU General Public License as published by the
+ * Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+ * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along with
+ * this program; if not, contact Novell, Inc.
+ *
+ * To contact Novell about this file by physical or electronic mail, you may find
+ * current contact information at www.novell.com.
+ * ------------------------------------------------------------------------------
+ */
+
+
+#include "PkgService.h"
+
+PkgService::PkgService() : _deleted(false), _old_alias()
+{
+}
+
+PkgService::PkgService(const zypp::ServiceInfo &s, const std::string &old_alias) :
+ zypp::ServiceInfo(s), _deleted(false), _old_alias(old_alias)
+{
+}
+
+PkgService::PkgService(const PkgService &s) :
+ zypp::ServiceInfo(s), _deleted(s._deleted), _old_alias(s._old_alias)
+{
+}
+
+PkgService::~PkgService()
+{
+}
+
+bool PkgService::isDeleted() const
+{
+ return _deleted;
+}
+
+void PkgService::setDeleted()
+{
+ _deleted = true;
+}
+
+std::string PkgService::origAlias() const
+{
+ return _old_alias;
+}
+
Added: branches/tmp/dmacvicar/zc10/pkg-bindings/src/PkgService.h
URL: http://svn.opensuse.org/viewcvs/yast/branches/tmp/dmacvicar/zc10/pkg-bindings/src/PkgService.h?rev=63940&view=auto
==============================================================================
--- branches/tmp/dmacvicar/zc10/pkg-bindings/src/PkgService.h (added)
+++ branches/tmp/dmacvicar/zc10/pkg-bindings/src/PkgService.h Tue May 10 20:10:47 2011
@@ -0,0 +1,50 @@
+/* ------------------------------------------------------------------------------
+ * Copyright (c) 2008 Novell, Inc. All Rights Reserved.
+ *
+ *
+ * This program is free software; you can redistribute it and/or modify it under
+ * the terms of version 2 of the GNU General Public License as published by the
+ * Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+ * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along with
+ * this program; if not, contact Novell, Inc.
+ *
+ * To contact Novell about this file by physical or electronic mail, you may find
+ * current contact information at www.novell.com.
+ * ------------------------------------------------------------------------------
+ */
+
+#include <string>
+#include
+
+// Extend zypp::ServiceInfo class to contain "deleted" flag and original service alias
+class PkgService : public zypp::ServiceInfo
+{
+ public:
+
+ PkgService();
+
+ PkgService(const zypp::ServiceInfo &s, const std::string &old_alias = "");
+
+ PkgService(const PkgService &s);
+
+ ~PkgService();
+
+ bool isDeleted() const;
+
+ void setDeleted();
+
+ std::string origAlias() const;
+
+
+ private:
+
+ bool _deleted;
+ std::string _old_alias;
+};
+
+
Modified: branches/tmp/dmacvicar/zc10/pkg-bindings/src/Resolvable.cc
URL: http://svn.opensuse.org/viewcvs/yast/branches/tmp/dmacvicar/zc10/pkg-bindings/src/Resolvable.cc?rev=63940&r1=63939&r2=63940&view=diff
==============================================================================
--- branches/tmp/dmacvicar/zc10/pkg-bindings/src/Resolvable.cc (original)
+++ branches/tmp/dmacvicar/zc10/pkg-bindings/src/Resolvable.cc Tue May 10 20:10:47 2011
@@ -33,36 +33,45 @@
#include
#include
-#include
+#include
+#include
#include
#include
#include
-#include
#include
#include
-#include
#include
#include
+#include
+#include
+#include
#include <set>
///////////////////////////////////////////////////////////////////
-// ------------------------
/**
@builtin ResolvableInstallArchVersion
@short Install all resolvables with selected name, architecture and kind. Use it only in a special case, ResolvableInstall() should be prefrerred.
- @param name_r name of the resolvable, if empty ("") install all resolvables of the kind
- @param kind_r kind of resolvable, can be `product, `patch, `package, `selection or `pattern
- @param arch architecture of the resolvable
- @param vers Required version of the resolvable, empty string means any version
+ @param name_r name of the resolvable
+ @param kind_r kind of resolvable, can be `product, `patch, `package, `srcpackage or `pattern
+ @param arch architecture of the resolvable, empty means the best architecture
+ @param vers Required version of the resolvable, empty string means the best version
@return boolean false if failed
*/
YCPValue
PkgModuleFunctions::ResolvableInstallArchVersion( const YCPString& name_r, const YCPSymbol& kind_r, const YCPString& arch, const YCPString& vers )
{
+ std::string name(name_r.isNull() ? "" : name_r->value());
+
+ if (name.empty())
+ {
+ y2error("Empty name");
+ return YCPBoolean(false);
+ }
+
zypp::Resolvable::Kind kind;
-
+
std::string req_kind = kind_r->symbol ();
std::string arch_str = arch->value();
@@ -73,19 +82,19 @@
zypp::Arch architecture(arch_str);
if( req_kind == "product" ) {
- kind = zypp::ResTraitszypp::Product::kind;
+ kind = zypp::ResKind::product;
}
else if ( req_kind == "patch" ) {
- kind = zypp::ResTraitszypp::Patch::kind;
+ kind = zypp::ResKind::patch;
}
else if ( req_kind == "package" ) {
- kind = zypp::ResTraitszypp::Package::kind;
+ kind = zypp::ResKind::package;
}
- else if ( req_kind == "selection" ) {
- kind = zypp::ResTraitszypp::Selection::kind;
+ else if ( req_kind == "srcpackage" ) {
+ kind = zypp::ResKind::srcpackage;
}
else if ( req_kind == "pattern" ) {
- kind = zypp::ResTraitszypp::Pattern::kind;
+ kind = zypp::ResKind::pattern;
}
else
{
@@ -93,78 +102,130 @@
return YCPBoolean(false);
}
- std::string version_str = vers->value();
+ std::string version_str = vers->value();
+ bool ret = false;
+
+ zypp::ResPoolProxy selectablePool(zypp::ResPool::instance().proxy());
+ zypp::ui::Selectable::Ptr s = zypp::ui::Selectable::get(kind, name);
+
+ if (s)
+ {
+ // install the required version and arch
+ for_(avail_it, s->availableBegin(), s->availableEnd())
+ {
+ // get the resolvable
+ zypp::Resolvable::constPtr res = avail_it->resolvable();
- return YCPBoolean(
- (name_r->value().empty())
- ? DoProvideAllKind(kind)
- : DoProvideNameKind (name_r->value(), kind, architecture, version_str)
- );
+ // check version and arch
+ if (res->arch() == architecture && res->edition() == version_str)
+ {
+ // install the preselected candidate
+ s->setCandidate(*avail_it);
+ ret = s->setToInstall(whoWantsIt);
+ break;
+ }
+ }
+
+ if (!ret)
+ {
+ y2error("Required version and arch of %s:%s was not found", req_kind.c_str(), name.c_str());
+ }
+ }
+ else
+ {
+ y2error("Required selectable %s:%s was not found", req_kind.c_str(), name.c_str());
+ }
+
+ return YCPBoolean(ret);
+}
+
+bool ResolvableInstallOrDelete(const YCPString& name_r, const YCPSymbol& kind_r, bool install)
+{
+ zypp::Resolvable::Kind kind;
+
+ std::string req_kind = kind_r->symbol ();
+
+ if( req_kind == "product" ) {
+ kind = zypp::ResKind::product;
+ }
+ else if ( req_kind == "patch" ) {
+ kind = zypp::ResKind::patch;
+ }
+ else if ( req_kind == "package" ) {
+ kind = zypp::ResKind::package;
+ }
+ else if ( req_kind == "srcpackage" ) {
+ kind = zypp::ResKind::srcpackage;
+ }
+ else if ( req_kind == "pattern" ) {
+ kind = zypp::ResKind::pattern;
+ }
+ else
+ {
+ y2error("Unknown symbol: %s", req_kind.c_str());
+ return false;
+ }
+
+ std::string name(name_r.isNull() ? "" : name_r->value());
+
+ if (name.empty())
+ {
+ y2error("Empty resolvable name");
+ return false;
+ }
+
+ zypp::ui::Selectable::Ptr s = zypp::ui::Selectable::get(kind, name);
+
+ if (s)
+ {
+ y2milestone("%s: %s:%s ", install ? "Installing" : "Removing", req_kind.c_str(), name.c_str());
+ return install ? s->setToInstall(zypp::ResStatus::APPL_HIGH):
+ s->setToDelete(zypp::ResStatus::APPL_HIGH);
+ }
+ else
+ {
+ y2error("Resolvable %s:%s was not found", req_kind.c_str(), name.c_str());
+ }
+
+ return false;
}
// ------------------------
/**
@builtin ResolvableInstall
@short Install all resolvables with selected name and kind
- @param name_r name of the resolvable, if empty ("") install all resolvables of the kind
- @param kind_r kind of resolvable, can be `product, `patch, `package, `selection or `pattern
+ @param name_r name of the resolvable
+ @param kind_r kind of resolvable, can be `product, `patch, `package, `srcpackage or `pattern
@return boolean false if failed
*/
YCPValue
PkgModuleFunctions::ResolvableInstall( const YCPString& name_r, const YCPSymbol& kind_r )
{
- return ResolvableInstallArchVersion(name_r, kind_r, YCPString(zypp_ptr()->architecture().asString()), YCPString(""));
+ // true = install
+ return YCPBoolean(ResolvableInstallOrDelete(name_r, kind_r, true));
}
// ------------------------
/**
@builtin ResolvableRemove
@short Removes all resolvables with selected name and kind
- @param name_r name of the resolvable, if empty ("") remove all resolvables of the kind
- @param kind_r kind of resolvable, can be `product, `patch, `package, `selection or `pattern
+ @param name_r name of the resolvable
+ @param kind_r kind of resolvable, can be `product, `patch, `package, `srcpackage or `pattern
@return boolean false if failed
*/
YCPValue
PkgModuleFunctions::ResolvableRemove ( const YCPString& name_r, const YCPSymbol& kind_r )
{
- zypp::Resolvable::Kind kind;
-
- std::string req_kind = kind_r->symbol ();
-
- if( req_kind == "product" ) {
- kind = zypp::ResTraitszypp::Product::kind;
- }
- else if ( req_kind == "patch" ) {
- kind = zypp::ResTraitszypp::Patch::kind;
- }
- else if ( req_kind == "package" ) {
- kind = zypp::ResTraitszypp::Package::kind;
- }
- else if ( req_kind == "selection" ) {
- kind = zypp::ResTraitszypp::Selection::kind;
- }
- else if ( req_kind == "pattern" ) {
- kind = zypp::ResTraitszypp::Pattern::kind;
- }
- else
- {
- y2error("Pkg::ResolvableRemove: unknown symbol: %s", req_kind.c_str());
- return YCPBoolean(false);
- }
-
- return YCPBoolean(
- (name_r->value().empty())
- ? DoRemoveAllKind(kind)
- : DoRemoveNameKind (name_r->value(), kind)
- );
+ // false = remove
+ return YCPBoolean(ResolvableInstallOrDelete(name_r, kind_r, false));
}
// ------------------------
/**
@builtin ResolvableNeutral
@short Remove all transactions from all resolvables with selected name and kind
- @param name_r name of the resolvable, if empty ("") use all resolvables of the kind
- @param kind_r kind of resolvable, can be `product, `patch, `package, `selection or `pattern
+ @param name_r name of the resolvable, if empty ("") use all resolvables of the kind
+ @param kind_r kind of resolvable, can be `product, `patch, `package, `srcpackage or `pattern
@param force_r remove the transactions even on USER level - default is APPL_HIGH (use true value only if really needed!)
@return boolean false if failed
*/
@@ -172,25 +233,25 @@
PkgModuleFunctions::ResolvableNeutral ( const YCPString& name_r, const YCPSymbol& kind_r, const YCPBoolean& force_r )
{
zypp::Resolvable::Kind kind;
-
+
std::string req_kind = kind_r->symbol();
std::string name = name_r->value();
bool force = force_r->value();
if( req_kind == "product" ) {
- kind = zypp::ResTraitszypp::Product::kind;
+ kind = zypp::ResKind::product;
}
else if ( req_kind == "patch" ) {
- kind = zypp::ResTraitszypp::Patch::kind;
+ kind = zypp::ResKind::patch;
}
else if ( req_kind == "package" ) {
- kind = zypp::ResTraitszypp::Package::kind;
+ kind = zypp::ResKind::package;
}
- else if ( req_kind == "selection" ) {
- kind = zypp::ResTraitszypp::Selection::kind;
+ else if ( req_kind == "srcpackage" ) {
+ kind = zypp::ResKind::srcpackage;
}
else if ( req_kind == "pattern" ) {
- kind = zypp::ResTraitszypp::Pattern::kind;
+ kind = zypp::ResKind::pattern;
}
else
{
@@ -202,24 +263,20 @@
try
{
- for (zypp::ResPool::byKind_iterator it = zypp_ptr()->pool().byKindBegin(kind);
- it != zypp_ptr()->pool().byKindEnd(kind);
- ++it)
+ if (name.empty())
{
- if (name.empty() || (*it)->name() == name)
+ for (zypp::ResPoolProxy::const_iterator it = zypp_ptr()->poolProxy().byKindBegin(kind);
+ it != zypp_ptr()->poolProxy().byKindEnd(kind);
+ ++it)
{
- if (!it->status().resetTransact(whoWantsIt))
- {
- ret = false;
- }
-
- // force neutralization on the user level
- if (force && !it->status().resetTransact(zypp::ResStatus::USER))
- {
- ret = false;
- }
+ ret = (*it)->unset(force ? zypp::ResStatus::USER : whoWantsIt) && ret;
}
}
+ else
+ {
+ zypp::ui::Selectable::Ptr s = zypp::ui::Selectable::get(kind, name);
+ ret = s ? s->unset(force ? zypp::ResStatus::USER : whoWantsIt) : false;
+ }
}
catch (...)
{
@@ -234,32 +291,32 @@
@builtin ResolvableSetSoftLock
@short Soft lock - it prevents the solver from re-selecting item
if it's recommended (if it's required it will be selected).
- @param name_r name of the resolvable, if empty ("") use all resolvables of the kind
- @param kind_r kind of resolvable, can be `product, `patch, `package, `selection or `pattern
+ @param name_r name of the resolvable, if empty ("") use all resolvables of the kind
+ @param kind_r kind of resolvable, can be `product, `patch, `package, `srcpackage or `pattern
@return boolean false if failed
*/
YCPValue
PkgModuleFunctions::ResolvableSetSoftLock ( const YCPString& name_r, const YCPSymbol& kind_r )
{
zypp::Resolvable::Kind kind;
-
+
std::string req_kind = kind_r->symbol();
std::string name = name_r->value();
if( req_kind == "product" ) {
- kind = zypp::ResTraitszypp::Product::kind;
+ kind = zypp::ResKind::product;
}
else if ( req_kind == "patch" ) {
- kind = zypp::ResTraitszypp::Patch::kind;
+ kind = zypp::ResKind::patch;
}
else if ( req_kind == "package" ) {
- kind = zypp::ResTraitszypp::Package::kind;
+ kind = zypp::ResKind::package;
}
- else if ( req_kind == "selection" ) {
- kind = zypp::ResTraitszypp::Selection::kind;
+ else if ( req_kind == "srcpackage" ) {
+ kind = zypp::ResKind::package;
}
else if ( req_kind == "pattern" ) {
- kind = zypp::ResTraitszypp::Pattern::kind;
+ kind = zypp::ResKind::pattern;
}
else
{
@@ -271,18 +328,20 @@
try
{
- for (zypp::ResPool::byKind_iterator it = zypp_ptr()->pool().byKindBegin(kind);
- it != zypp_ptr()->pool().byKindEnd(kind);
- ++it)
+ if (name.empty())
{
- if (name.empty() || (*it)->name() == name)
+ for (zypp::ResPoolProxy::const_iterator it = zypp_ptr()->poolProxy().byKindBegin(kind);
+ it != zypp_ptr()->poolProxy().byKindEnd(kind);
+ ++it)
{
- if (!it->status().setSoftLock(whoWantsIt))
- {
- ret = false;
- }
+ ret = (*it)->theObj().status().setSoftLock(whoWantsIt) && ret;
}
}
+ else
+ {
+ zypp::ui::Selectable::Ptr s = zypp::ui::Selectable::get(kind, name);
+ ret = s ? s->theObj().status().setSoftLock(whoWantsIt) : false;
+ }
}
catch (...)
{
@@ -292,22 +351,92 @@
return YCPBoolean(ret);
}
-
/**
@builtin ResolvableProperties
@short Return properties of resolvable
@description
return list of resolvables of selected kind with required name
-
+
@param name name of the resolvable, if empty returns all resolvables of the kind
- @param kind_r kind of resolvable, can be `product, `patch, `package, `selection, `pattern or `language
+ @param kind_r kind of resolvable, can be `product, `patch, `package, `pattern or `language
@param version version of the resolvable, if empty all versions are returned
@return list