- the 'package' atom within a patch is not a stand-alone resolvable
authorKlaus Kaempf <kkaempf@suse.de>
Fri, 24 Feb 2006 19:00:16 +0000 (19:00 +0000)
committerKlaus Kaempf <kkaempf@suse.de>
Fri, 24 Feb 2006 19:00:16 +0000 (19:00 +0000)
  but contains only _additional_ information to augment the package
  created by standard repomd data
- add 'augmentPackage()' to inject this additional metadata into
  an already existing package
  (this does not work as expected since the Package is const.
   So we re-create a new Package from the old and add information)
  (incomplete, currently only dependencies are added. Should add
   also patch_rpm and delta_rpm information)
- dont use 'PackageID' but 'NVRA' which is semantically identical

ToDo:
 strip down 'YUMPatchPackage' to the 'augmentable' information.
 The updated package, the patch refers to, should have all
 information, The 'YUMPatchPackage' should only add information
 relevant for the patch-package relationship.

zypp/source/yum/YUMPatchImpl.cc
zypp/source/yum/YUMSourceImpl.cc
zypp/source/yum/YUMSourceImpl.h

index 569b2fc..dd6edd0 100644 (file)
@@ -50,15 +50,15 @@ namespace zypp
       : _source(source_r)
       {
        _patch_id = parsed.patchId;
-        _timestamp = str::strtonum<time_t>(parsed.timestamp);
-        _category = parsed.category;
-        _reboot_needed = parsed.rebootNeeded;
-        _affects_pkg_manager = parsed.packageManager;
-        std::string updateScript;
+       _timestamp = str::strtonum<time_t>(parsed.timestamp);
+       _category = parsed.category;
+       _reboot_needed = parsed.rebootNeeded;
+       _affects_pkg_manager = parsed.packageManager;
+       std::string updateScript;
 /*
-        std::string engine;
-        MultiLang description;
-        _summary = parsed.MultiLang summary;
+       std::string engine;
+       MultiLang description;
+       _summary = parsed.MultiLang summary;
 */
 
 
@@ -84,37 +84,36 @@ namespace zypp
             it != parsed.atoms.end();
             it++)
        {
-          switch ((*it)->atomType())
-          {
-            case YUMPatchAtom::Package: {
-              shared_ptr<YUMPatchPackage> package_data
-                = dynamic_pointer_cast<YUMPatchPackage>(*it);
-              Package::Ptr package = srcimpl_r.createPackage(_source, *package_data);
-              _atoms.push_back(package);
-              break;
-            }
-            case YUMPatchAtom::Message: {
-              shared_ptr<YUMPatchMessage> message_data
-                = dynamic_pointer_cast<YUMPatchMessage>(*it);
-              Message::Ptr message = srcimpl_r.createMessage(_source, *message_data);
-              _atoms.push_back(message);
-              break;
-            }
-            case YUMPatchAtom::Script: {
-              shared_ptr<YUMPatchScript> script_data
-                = dynamic_pointer_cast<YUMPatchScript>(*it);
-              Script::Ptr script = srcimpl_r.createScript(_source, *script_data);
-              _atoms.push_back(script);
-              break;
-            }
-            default:
-              ERR << "Unknown type of atom" << endl;
-          }
+         switch ((*it)->atomType())
+         {
+           case YUMPatchAtom::Package: {
+             shared_ptr<YUMPatchPackage> package_data
+               = dynamic_pointer_cast<YUMPatchPackage>(*it);
+             srcimpl_r.augmentPackage( *package_data );
+             break;
+           }
+           case YUMPatchAtom::Message: {
+             shared_ptr<YUMPatchMessage> message_data
+               = dynamic_pointer_cast<YUMPatchMessage>(*it);
+             Message::Ptr message = srcimpl_r.createMessage(_source, *message_data);
+             _atoms.push_back(message);
+             break;
+           }
+           case YUMPatchAtom::Script: {
+             shared_ptr<YUMPatchScript> script_data
+               = dynamic_pointer_cast<YUMPatchScript>(*it);
+             Script::Ptr script = srcimpl_r.createScript(_source, *script_data);
+             _atoms.push_back(script);
+             break;
+           }
+           default:
+             ERR << "Unknown type of atom" << endl;
+         }
          for (AtomList::iterator it = _atoms.begin();
               it != _atoms.end();
               it++)
          {
-            (*it)->injectRequires(cap);
+           (*it)->injectRequires(cap);
          }
 
        }
@@ -122,11 +121,11 @@ namespace zypp
 
       std::string YUMPatchImpl::id() const
       {
-        return _patch_id;
+       return _patch_id;
       }
       Date YUMPatchImpl::timestamp() const
       {
-        return _timestamp;
+       return _timestamp;
       }
 
       TranslatedText YUMPatchImpl::summary() const
@@ -155,102 +154,102 @@ namespace zypp
 
       std::string YUMPatchImpl::category() const
       {
-        return _category;
+       return _category;
       }
 
       bool YUMPatchImpl::reboot_needed() const
       {
-        return _reboot_needed;
+       return _reboot_needed;
       }
 
       bool YUMPatchImpl::affects_pkg_manager() const
       {
-        return _affects_pkg_manager;
+       return _affects_pkg_manager;
       }
 
       bool YUMPatchImpl::interactive() const {
-        if (_reboot_needed)
-        {
-          DBG << "Patch needs reboot" << endl;
-          return true;
-        }
-        AtomList not_installed = not_installed_atoms();
-        for (AtomList::iterator it = not_installed.begin();
-          it != not_installed.end();
-          it++)
-        {
-          if ((*it)->kind() == "Message")
-          {
+       if (_reboot_needed)
+       {
+         DBG << "Patch needs reboot" << endl;
+         return true;
+       }
+       AtomList not_installed = not_installed_atoms();
+       for (AtomList::iterator it = not_installed.begin();
+         it != not_installed.end();
+         it++)
+       {
+         if ((*it)->kind() == "Message")
+         {
   //          DBG << "Patch contains a message" << endl;
-            return true;
-          }
-          if ((*it)->kind() == "Package")
-          {
-                                   // Resolvable*
-                                    // Resolvable
-                                     // ResolvablePtr
+           return true;
+         }
+         if ((*it)->kind() == "Package")
+         {
+                                  // Resolvable*
+                                   // Resolvable
+                                    // ResolvablePtr
 
 
-            // <ma> never do somthing like this!!!
+           // <ma> never do somthing like this!!!
   //          Package* p = (Package*)&**it;
-            //
-            // (*it) is a ResolvablePtr
+           //
+           // (*it) is a ResolvablePtr
 
 
 
 
-            // FIXME use the condition
+           // FIXME use the condition
   //          if (p->licenseToConfirm() != "")
-            if (false)
-            {
+           if (false)
+           {
   //            DBG << "Package has a license to be shown to user" << endl;
-              return true;
-            }
-          }
-        }
-        return false;
+             return true;
+           }
+         }
+       }
+       return false;
       }
 
       YUMPatchImpl::AtomList YUMPatchImpl::all_atoms() const {
-        return _atoms;
+       return _atoms;
       }
 
       YUMPatchImpl::AtomList YUMPatchImpl::not_installed_atoms() const {
-        AtomList ret;
-        for (AtomList::const_iterator it = _atoms.begin();
-          it != _atoms.end();
-          it++)
-        {
-          if (true) // FIXME check if atom/resolvable is not installed
-          {
-            ret.push_back(*it);
-          }
-        }
-        return ret;
+       AtomList ret;
+       for (AtomList::const_iterator it = _atoms.begin();
+         it != _atoms.end();
+         it++)
+       {
+         if (true) // FIXME check if atom/resolvable is not installed
+         {
+           ret.push_back(*it);
+         }
+       }
+       return ret;
       }
 
   // TODO check necessarity of functions below
 
       bool YUMPatchImpl::any_atom_selected() const {
-        for (AtomList::const_iterator it = _atoms.begin();
-          it != _atoms.end();
-          it++)
-        {
-          if (false) // FIXME check if atom/resolvable is selected
-          {
-            return true;
-          }
-        }
-        return false;
+       for (AtomList::const_iterator it = _atoms.begin();
+         it != _atoms.end();
+         it++)
+       {
+         if (false) // FIXME check if atom/resolvable is selected
+         {
+           return true;
+         }
+       }
+       return false;
       }
 
       void YUMPatchImpl::mark_atoms_to_freshen( bool freshen ) {
-        for (AtomList::iterator it = _atoms.begin();
-          it != _atoms.end();
-          it++)
-        {
-          // TODO mark the resolvable to be or not to be freshed
-        }
+       for (AtomList::iterator it = _atoms.begin();
+         it != _atoms.end();
+         it++)
+       {
+         // TODO mark the resolvable to be or not to be freshed
+       }
       }
 
       Source_Ref YUMPatchImpl::source() const
index fb151b2..f6a0bfe 100644 (file)
@@ -19,6 +19,7 @@
 #include "zypp/source/yum/YUMGroupImpl.h"
 #include "zypp/source/yum/YUMPatternImpl.h"
 
+#include "zypp/NVRA.h"
 #include "zypp/PathInfo.h"
 #include "zypp/base/Logger.h"
 #include "zypp/base/Exception.h"
@@ -177,8 +178,8 @@ namespace zypp
 
       try {
          // now put other and filelist data to structures for easier find
-         map<PackageID, YUMFileListData_Ptr> files_data;
-         map<PackageID, YUMOtherData_Ptr> other_data;
+         map<NVRA, YUMFileListData_Ptr> files_data;
+         map<NVRA, YUMOtherData_Ptr> other_data;
          for (std::list<YUMRepomdData_Ptr>::const_iterator it
                  = repo_files.begin();
              it != repo_files.end();
@@ -198,11 +199,10 @@ namespace zypp
                  ! filelist.atEnd();
                  ++filelist)
            {
-               PackageID id((*filelist)->name,
-                           (*filelist)->ver,
-                           (*filelist)->rel,
-                           (*filelist)->arch);
-               files_data[id] = *filelist;
+               NVRA nvra( (*filelist)->name,
+                          Edition( (*filelist)->ver, (*filelist)->rel, str::strtonum<int>( (*filelist)->epoch ) ),
+                          Arch ( (*filelist)->arch ) );
+               files_data[nvra] = *filelist;
            }
            if (filelist.errorStatus())
              throw *filelist.errorStatus();
@@ -226,11 +226,10 @@ namespace zypp
                  ! other.atEnd();
                  ++other)
            {
-               PackageID id((*other)->name,
-                           (*other)->ver,
-                           (*other)->rel,
-                           (*other)->arch);
-               other_data[id] = *other;
+               NVRA nvra( (*other)->name,
+                          Edition( (*other)->ver, (*other)->rel, str::strtonum<int>( (*other)->epoch ) ),
+                          Arch( (*other)->arch ) );
+               other_data[nvra] = *other;
            }
            if (other.errorStatus())
              throw *other.errorStatus();
@@ -254,17 +253,17 @@ namespace zypp
                  !prim.atEnd();
                  ++prim)
            {
-               PackageID id((*prim)->name,
-                        (*prim)->ver,
-                        (*prim)->rel,
-                        (*prim)->arch);
-               map<PackageID, YUMOtherData_Ptr>::iterator found_other
-                   = other_data.find(id);
-               map<PackageID, YUMFileListData_Ptr>::iterator found_files
-                   = files_data.find(id);
+               NVRA nvra( (*prim)->name,
+                          Edition( (*prim)->ver, (*prim)->rel, str::strtonum<int>( (*prim)->epoch ) ),
+                          Arch( (*prim)->arch ) );
+               map<NVRA, YUMOtherData_Ptr>::iterator found_other
+                   = other_data.find( nvra );
+               map<NVRA, YUMFileListData_Ptr>::iterator found_files
+                   = files_data.find( nvra );
   
                YUMFileListData filelist_empty;
                YUMOtherData other_empty;
+               ResImplTraits<YUMPackageImpl>::Ptr impl;
                Package::Ptr p = createPackage(
                  source_r,
                  **prim,
@@ -273,8 +272,11 @@ namespace zypp
                    : filelist_empty,
                  found_other != other_data.end()
                    ? *found_other->second
-                    : other_empty
+                    : other_empty,
+                 impl
                );
+               ImplAndPackage iap = { impl, p };
+               _package_impl[nvra] = iap;
                _store.insert (p);
            }
            if (prim.errorStatus())
@@ -461,21 +463,21 @@ namespace zypp
     Source_Ref source_r,
     const zypp::parser::yum::YUMPrimaryData & parsed,
     const zypp::parser::yum::YUMFileListData & filelist,
-    const zypp::parser::yum::YUMOtherData & other
+    const zypp::parser::yum::YUMOtherData & other,
+    ResImplTraits<YUMPackageImpl>::Ptr & impl
   )
   {
     try
     {
-      ResImplTraits<YUMPackageImpl>::Ptr impl(
-       new YUMPackageImpl(source_r, parsed, filelist, other));
-
-           // Collect basic Resolvable data
-           NVRAD dataCollect( parsed.name,
-                             Edition( parsed.ver, parsed.rel, parsed.epoch ),
-                             Arch( parsed.arch ),
-                             createDependencies(parsed,
-                                                 ResTraits<Package>::kind)
-                           );
+      impl = new YUMPackageImpl( source_r, parsed, filelist, other );
+
+      // Collect basic Resolvable data
+      NVRAD dataCollect( parsed.name,
+                        Edition( parsed.ver, parsed.rel, parsed.epoch ),
+                        Arch( parsed.arch ),
+                        createDependencies( parsed,
+                                          ResTraits<Package>::kind )
+                      );
       Package::Ptr package = detail::makeResolvableFromImpl(
        dataCollect, impl
       );
@@ -488,31 +490,86 @@ namespace zypp
     }
   }
 
-  Package::Ptr YUMSourceImpl::createPackage(
-    Source_Ref source_r,
+  static void augmentCapSet( const CapSet & from, CapSet & to )
+  {
+    for (CapSet::const_iterator it = from.begin(); it != from.end(); ++it) {
+       to.insert( *it );
+    }
+    return;
+  }
+
+  static void augmentDependencies( const Dependencies & from, Dependencies & to )
+  {
+MIL << "augmentDependencies(" << from << ")" << endl;
+#define AUG_CAP_SET(tag) augmentCapSet( from[Dep::tag], to[Dep::tag] )
+      AUG_CAP_SET(PROVIDES);
+      AUG_CAP_SET(REQUIRES);
+      AUG_CAP_SET(PREREQUIRES);
+      AUG_CAP_SET(OBSOLETES);
+      AUG_CAP_SET(CONFLICTS);
+      AUG_CAP_SET(FRESHENS);
+      AUG_CAP_SET(RECOMMENDS);
+      AUG_CAP_SET(SUGGESTS);
+      AUG_CAP_SET(SUPPLEMENTS);
+      AUG_CAP_SET(ENHANCES);
+#undef AUG_CAP_SET
+MIL << "=> (" << to << ")" << endl;
+  }
+
+  void YUMSourceImpl::augmentPackage(
     const zypp::parser::yum::YUMPatchPackage & parsed
   )
   {
     try
     {
-      ResImplTraits<YUMPackageImpl>::Ptr impl(new YUMPackageImpl(source_r, parsed));
+       NVRA nvra( parsed.name,
+                  Edition( parsed.ver, parsed.rel, parsed.epoch ),
+                  Arch( parsed.arch ) );
 
-           // Collect basic Resolvable data
-           NVRAD dataCollect( parsed.name,
-                             Edition( parsed.ver, parsed.rel, parsed.epoch ),
-                             Arch( parsed.arch ),
-                             createDependencies(parsed,
-                                                 ResTraits<Package>::kind)
-                           );
-      Package::Ptr package = detail::makeResolvableFromImpl(
-       dataCollect, impl
-      );
-      return package;
+DBG << "augmentPackage(" << nvra << ")" << endl;
+
+       PackageImplMapT::const_iterator it = _package_impl.find( nvra );
+       if (it == _package_impl.end()) {
+           ERR << "Patch augments non-existant package " << nvra << endl;
+           return;
+       }
+       ResImplTraits<YUMPackageImpl>::Ptr impl = it->second.impl;
+       Package::Ptr package = it->second.package;
+DBG << "found " << *package << ", impl " << impl << endl;
+
+       _store.erase( package );
+       impl->unmanage();
+DBG << "Erased old package " << endl;
+
+       Dependencies deps = createDependencies( parsed, ResTraits<Package>::kind );
+
+DBG << "augmenting " << deps << endl;
+
+       augmentDependencies( package->deps(), deps );
+
+DBG << "augmenting done " << endl;
+
+       // Collect augmented package data
+       NVRAD dataCollect( nvra, deps );
+
+DBG << "NVRAD " << (NVRA)dataCollect << endl;
+
+       Package::Ptr augmented_package = detail::makeResolvableFromImpl(
+           dataCollect, impl
+       );
+
+DBG << "augmented_package " << *augmented_package << endl;
+
+DBG << "Inserting augmented package " << endl;
+       _store.insert( augmented_package );
+DBG << "Done" << endl;
+       return;
     }
     catch (const Exception & excpt_r)
     {
       ERR << excpt_r << endl;
-      throw "Cannot create package object";
+      ZYPP_CAUGHT( excpt_r );
+      throw "Cannot create augmented package object";
     }
   }
 
@@ -524,11 +581,11 @@ namespace zypp
     try
     {
       ResImplTraits<YUMGroupImpl>::Ptr impl(new YUMGroupImpl(source_r, parsed));
-           // Collect basic Resolvable data
-           NVRAD dataCollect( parsed.groupId,
-                             Edition::noedition,
-                             Arch_noarch,
-                             createGroupDependencies(parsed));
+      // Collect basic Resolvable data
+      NVRAD dataCollect( parsed.groupId,
+                     Edition::noedition,
+                     Arch_noarch,
+                     createGroupDependencies(parsed));
       Selection::Ptr group = detail::makeResolvableFromImpl(
        dataCollect, impl
       );
@@ -549,11 +606,11 @@ namespace zypp
     try
     {
       ResImplTraits<YUMPatternImpl>::Ptr impl(new YUMPatternImpl(source_r, parsed));
-           // Collect basic Resolvable data
-           NVRAD dataCollect( parsed.name,
-                             Edition::noedition,
-                             Arch_noarch,
-                             createDependencies(parsed, ResTraits<Pattern>::kind));
+      // Collect basic Resolvable data
+      NVRAD dataCollect( parsed.name,
+                     Edition::noedition,
+                     Arch_noarch,
+                     createDependencies(parsed, ResTraits<Pattern>::kind));
       Pattern::Ptr pattern = detail::makeResolvableFromImpl(
        dataCollect, impl
       );
@@ -577,11 +634,11 @@ namespace zypp
 
            // Collect basic Resolvable data
            NVRAD dataCollect( parsed.name,
-                             Edition( parsed.ver, parsed.rel, parsed.epoch ),
-                             Arch_noarch,
-                             createDependencies(parsed,
-                                                 ResTraits<Message>::kind)
-                           );
+                             Edition( parsed.ver, parsed.rel, parsed.epoch ),
+                             Arch_noarch,
+                             createDependencies(parsed,
+                                                 ResTraits<Message>::kind)
+                           );
       Message::Ptr message = detail::makeResolvableFromImpl(
        dataCollect, impl
       );
@@ -603,13 +660,13 @@ namespace zypp
     {
       ResImplTraits<YUMScriptImpl>::Ptr impl(new YUMScriptImpl(source_r, parsed));
 
-           // Collect basic Resolvable data
-           NVRAD dataCollect( parsed.name,
-                             Edition( parsed.ver, parsed.rel, parsed.epoch ),
-                             Arch_noarch,
-                             createDependencies(parsed,
-                                                 ResTraits<Script>::kind)
-                           );
+      // Collect basic Resolvable data
+      NVRAD dataCollect( parsed.name,
+                     Edition( parsed.ver, parsed.rel, parsed.epoch ),
+                     Arch_noarch,
+                     createDependencies(parsed,
+                                         ResTraits<Script>::kind)
+                   );
       Script::Ptr script = detail::makeResolvableFromImpl(
        dataCollect, impl
       );
@@ -633,11 +690,11 @@ namespace zypp
 
            // Collect basic Resolvable data
            NVRAD dataCollect( parsed.name,
-                             Edition( parsed.ver, parsed.rel, parsed.epoch ),
-                             Arch_noarch,
-                             createDependencies(parsed,
-                                                 ResTraits<Product>::kind)
-                           );
+                             Edition( parsed.ver, parsed.rel, parsed.epoch ),
+                             Arch_noarch,
+                             createDependencies(parsed,
+                                                 ResTraits<Product>::kind)
+                           );
       Product::Ptr product = detail::makeResolvableFromImpl(
        dataCollect, impl
       );
@@ -659,13 +716,13 @@ namespace zypp
     {
       ResImplTraits<YUMPatchImpl>::Ptr impl(new YUMPatchImpl(source_r, parsed, *this));
 
-           // Collect basic Resolvable data
-           NVRAD dataCollect( parsed.name,
-                             Edition( parsed.ver, parsed.rel, parsed.epoch ),
-                             Arch_noarch,
-                             createDependencies(parsed,
-                                                 ResTraits<Patch>::kind)
-                           );
+      // Collect basic Resolvable data
+      NVRAD dataCollect( parsed.name,
+                     Edition( parsed.ver, parsed.rel, parsed.epoch ),
+                     Arch_noarch,
+                     createDependencies( parsed,
+                                         ResTraits<Patch>::kind)
+                   );
       Patch::Ptr patch = detail::makeResolvableFromImpl(
        dataCollect, impl
       );
index 145a5e1..6a33d49 100644 (file)
@@ -13,6 +13,8 @@
 #define ZYPP_SOURCE_YUM_YUMSOURCEIMPL_H
 
 #include "zypp/source/SourceImpl.h"
+#include "zypp/detail/ResImplTraits.h"
+#include "zypp/source/yum/YUMPackageImpl.h"
 #include "zypp/parser/yum/YUMParserData.h"
 #include "zypp/Package.h"
 #include "zypp/Message.h"
@@ -61,10 +63,10 @@ namespace zypp
          Source_Ref source_r,
          const zypp::parser::yum::YUMPrimaryData & parsed,
          const zypp::parser::yum::YUMFileListData & filelist,
-         const zypp::parser::yum::YUMOtherData & other
+         const zypp::parser::yum::YUMOtherData & other,
+         zypp::detail::ResImplTraits<zypp::source::yum::YUMPackageImpl>::Ptr & impl
        );
-       Package::Ptr createPackage(
-         Source_Ref source_r,
+       void augmentPackage(
          const zypp::parser::yum::YUMPatchPackage & parsed
        );
        Selection::Ptr createGroup(
@@ -115,52 +117,15 @@ namespace zypp
 
        std::list<Pathname> _metadata_files;
 
-       class PackageID {
-       public:
-         PackageID(std::string name,
-                   std::string ver,
-                   std::string rel,
-                   std::string arch)
-         : _name(name)
-         , _ver(ver)
-         , _rel(rel)
-         , _arch(arch)
-         {};
-         static int compare( const PackageID & lhs, const PackageID & rhs )
-         {
-           if (lhs._name < rhs._name)
-             return 1;
-           if (lhs._name > rhs._name)
-             return -1;
-           if (lhs._ver < rhs._ver)
-             return 1;
-           if (lhs._ver > rhs._ver)
-             return -1;
-           if (lhs._rel < rhs._rel)
-             return 1;
-           if (lhs._rel > rhs._rel)
-             return -1;
-           if (lhs._arch < rhs._arch)
-             return 1;
-           if (lhs._arch > rhs._arch)
-             return -1;
-           return 0;
-         }
-         std::string name() { return _name; }
-         std::string ver() { return _ver; }
-         std::string rel() { return _rel; }
-         std::string arch() { return _arch; }
-       private:
-         std::string _name;
-         std::string _ver;
-         std::string _rel;
-         std::string _arch;
-       };
-       friend inline bool operator<( const YUMSourceImpl::PackageID & lhs, const YUMSourceImpl::PackageID & rhs );
-      };
+       typedef struct {
+           zypp::detail::ResImplTraits<zypp::source::yum::YUMPackageImpl>::Ptr impl;
+           zypp::Package::Ptr package;
+       } ImplAndPackage;
 
-      inline bool operator<( const YUMSourceImpl::PackageID & lhs, const YUMSourceImpl::PackageID & rhs )
-      { return YUMSourceImpl::PackageID::compare( lhs, rhs ) == -1; }
+       typedef std::map<zypp::NVRA, ImplAndPackage> PackageImplMapT;
+       PackageImplMapT _package_impl;
+
+      };
 
       ///////////////////////////////////////////////////////////////////
     } // namespace yum