From: Michael Andres Date: Thu, 25 Oct 2012 16:08:36 +0000 (+0200) Subject: Fix source-install to accept package names and lookup their source package (bnc#785832) X-Git-Tag: 1.8.5~1 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=b03c2d58669b0d748a9f9d7cce31312d2841d5c3;p=platform%2Fupstream%2Fzypper.git Fix source-install to accept package names and lookup their source package (bnc#785832) --- diff --git a/doc/zypper.8 b/doc/zypper.8 index 8140043..48f3fda 100644 --- a/doc/zypper.8 +++ b/doc/zypper.8 @@ -384,7 +384,9 @@ Install version 2.0.6 of virtualbox-ose package (any of the following): .TP .B source-install (si) ... -Install specified source packages and their build dependencies. +Install specified source packages and their build dependencies. If the name of +a binary package is given, the coresponding source package is looked up and +installed instead. This command will try to find the newest available versions of the source packages and use rpm -i to install them and the packages that are required diff --git a/src/Zypper.h b/src/Zypper.h index d3e70f3..20f6fd7 100644 --- a/src/Zypper.h +++ b/src/Zypper.h @@ -120,7 +120,7 @@ struct RuntimeData */ zypp::RepoInfo current_repo; - std::list srcpkgs_to_install; + std::set srcpkgs_to_install; // hack to enable media progress reporting in the commit phase in normal // output level diff --git a/src/misc.cc b/src/misc.cc index ff1bf54..f61c90d 100644 --- a/src/misc.cc +++ b/src/misc.cc @@ -35,7 +35,6 @@ using namespace std; using namespace zypp; -using namespace zypp::ui; using namespace boost; extern ZYpp::Ptr God; @@ -121,7 +120,7 @@ bool confirm_licenses(Zypper & zypper) for (ResPool::const_iterator it = God->pool().begin(); it != God->pool().end(); ++it) { bool to_accept = true; - + if (it->status().isToBeInstalled() && !it->resolvable()->licenseToConfirm().empty()) { @@ -171,7 +170,7 @@ bool confirm_licenses(Zypper & zypper) if ( !it->resolvable()->needToAcceptLicense() ) to_accept = false; - + if (to_accept) { // introduction @@ -318,50 +317,44 @@ void report_licenses(Zypper & zypper) } // ---------------------------------------------------------------------------- - -static SrcPackage::constPtr source_find( const string & arg ) +namespace { - /* - * Workflow: - * - * 1. interate all SrcPackage resolvables with specified name - * 2. find the latest version or version satisfying specification. - */ - SrcPackage::constPtr srcpkg; - - ResPool pool(God->pool()); - DBG << "looking source for : " << arg << endl; - for_( srcit, pool.byIdentBegin(arg), - pool.byIdentEnd(arg) ) + SrcPackage::constPtr source_find( Zypper & zypper_r, const string & arg_r ) + { + /* + * Workflow: + * + * 1. return srcpackage "arg_r" if available + * 2. else if package "arg_r" is available, return it's srcpackage if available + * 3; else return 0 + */ + DBG << "looking for source package: " << arg_r << endl; + ui::Selectable::Ptr p( ui::Selectable::get( ResKind::srcpackage, arg_r ) ); + if ( p ) + return asKind( p->theObj().resolvable() ); + + // else: try package and packages sourcepackage + p = zypp::ui::Selectable::get( zypp::ResKind::package, arg_r ); + if ( p ) { - DBG << *srcit << endl; - if ( ! srcit->status().isInstalled() ) // this will be true for all of the srcpackages, won't it? - { - SrcPackage::constPtr _srcpkg = asKind(srcit->resolvable()); + std::string name( p->theObj()->asKind()->sourcePkgName() ); + DBG << "looking for source package of package: " << name << endl; + zypper_r.out().info( boost::str( format(_("Package '%s' has source package '%s'.")) % arg_r % name ) ); - DBG << "Considering srcpakcage " << _srcpkg->name() << "-" << _srcpkg->edition() << ": "; - if (srcpkg) - { - if (_srcpkg->edition() > srcpkg->edition()) - { - DBG << "newer edition (" << srcpkg->edition() << " > " << _srcpkg->edition() << ")"; - _srcpkg.swap(srcpkg); - } - else - DBG << "is older than the current candidate"; - } - else - { - DBG << "first candindate"; - _srcpkg.swap(srcpkg); - } - DBG << endl; - } + p = zypp::ui::Selectable::get( ResKind::srcpackage, p->theObj()->asKind()->sourcePkgName() ); + if ( p ) + return asKind( p->theObj().resolvable() ); + else + zypper_r.out().error( boost::str( format(_("Source package '%s' for package '%s' not found.")) % name % arg_r ) ); } + else + zypper_r.out().error( boost::str( format(_("Source package '%s' not found.")) % arg_r ) ); - return srcpkg; -} + DBG << "no source package found for: " << arg_r << endl; + return SrcPackage::constPtr(); + } +} // namespace // ---------------------------------------------------------------------------- void build_deps_install(Zypper & zypper) @@ -376,10 +369,11 @@ void build_deps_install(Zypper & zypper) for (vector::const_iterator it = zypper.arguments().begin(); it != zypper.arguments().end(); ++it) { - SrcPackage::constPtr srcpkg = source_find(*it); + SrcPackage::constPtr srcpkg = source_find(zypper, *it); if (srcpkg) { + zypper.runtimeData().srcpkgs_to_install.insert(srcpkg); DBG << format("Injecting build requieres for source package %s-%s") % srcpkg->name() % srcpkg->edition() << endl; @@ -400,8 +394,6 @@ void build_deps_install(Zypper & zypper) } else { - zypper.out().error(boost::str(format( - _("Source package '%s' not found.")) % (*it))); zypper.setExitCode(ZYPPER_EXIT_INF_CAP_NOT_FOUND); } } @@ -421,13 +413,10 @@ void mark_src_pkgs(Zypper & zypper) for (vector::const_iterator it = zypper.arguments().begin(); it != zypper.arguments().end(); ++it) { - SrcPackage::constPtr srcpkg = source_find(*it); + SrcPackage::constPtr srcpkg = source_find(zypper, *it); - if (srcpkg) - zypper.runtimeData().srcpkgs_to_install.push_back(srcpkg); - else - zypper.out().error(boost::str(format( - _("Source package '%s' not found.")) % (*it))); + if ( srcpkg ) + zypper.runtimeData().srcpkgs_to_install.insert(srcpkg); } }