Added methods to provide package to local filesystem to Package
authorJiri Srain <jsrain@suse.cz>
Fri, 27 Jan 2006 09:24:25 +0000 (09:24 +0000)
committerJiri Srain <jsrain@suse.cz>
Fri, 27 Jan 2006 09:24:25 +0000 (09:24 +0000)
interface

zypp/BaseVersion.h
zypp/DeltaRpm.h
zypp/Package.cc
zypp/Package.h
zypp/PatchRpm.h

index 0adba4f..3c64f45 100644 (file)
@@ -38,6 +38,9 @@ namespace zypp
     Date _buildtime;
   };
 
+  inline bool operator==(const BaseVersion & bv1, const BaseVersion & bv2)
+  { return bv1.edition() == bv2.edition(); }
+
 } // namespace zypp
 ///////////////////////////////////////////////////////////////////
 #endif // ZYPP_BASEVERSION_H
index 4683ef8..8e8e3db 100644 (file)
@@ -37,12 +37,12 @@ namespace zypp
     , _buildtime(buildtime)
     , _base_version(base_version)
     {}
-    Arch arch() { return _arch; }
-    Pathname filename() { return _filename; }
-    ByteCount downloadsize() { return _downloadsize; }
-    CheckSum checksum() { return _checksum; }
-    Date buildtime() { return _buildtime; }
-    BaseVersion baseVersion() { return _base_version; }
+    Arch arch() const { return _arch; }
+    Pathname filename() const { return _filename; }
+    ByteCount downloadsize() const { return _downloadsize; }
+    CheckSum checksum() const { return _checksum; }
+    Date buildtime() const { return _buildtime; }
+    BaseVersion baseVersion() const { return _base_version; }
   private:
     Arch _arch;
     Pathname _filename;
index cf2642d..2243c07 100644 (file)
@@ -10,6 +10,7 @@
  *
 */
 #include "zypp/Package.h"
+#include "zypp/base/Exception.h"
 
 using namespace std;
 
@@ -133,6 +134,44 @@ namespace zypp
   std::list<DeltaRpm> Package::deltaRpms() const
   { return pimpl().deltaRpms(); }
 
+  /** */
+  Pathname Package::getPlainRpm() const
+  { return source().provideFile(plainRpm()); }
+
+  /** */
+  Pathname Package::getDeltaRpm(BaseVersion & base_r) const
+  {
+#warning (2x): TODO: BaseVersion compare checks only Edition
+    std::list<DeltaRpm> deltas = deltaRpms();
+    for (std::list<DeltaRpm>::const_iterator it = deltas.begin();
+         it != deltas.end(); it++)
+    {
+      if (base_r == it->baseVersion())
+       return source().provideFile(it->filename());
+    }
+    ZYPP_THROW(Exception("No matching delta RPM found"));
+    return source().provideFile(plainRpm()); // never reached
+  }
+
+  /** */
+  Pathname Package::getPatchRpm(BaseVersion & base_r) const
+  {
+    std::list<PatchRpm> patches = patchRpms();
+    for (std::list<PatchRpm>::const_iterator it = patches.begin();
+         it != patches.end(); it++)
+    {
+      std::list<BaseVersion> bases = it->baseVersions();
+      for (std::list<BaseVersion>::const_iterator bvit = bases.begin();
+          bvit != bases.end(); bvit++)
+      {
+       if (base_r == *bvit)
+         return source().provideFile(it->filename());
+      }
+    }
+    ZYPP_THROW(Exception("No matching patch RPM found"));
+    return source().provideFile(plainRpm()); // never reached
+  }
+
   /////////////////////////////////////////////////////////////////
 } // namespace zypp
 ///////////////////////////////////////////////////////////////////
index 34eb641..50c01dc 100644 (file)
@@ -82,6 +82,18 @@ namespace zypp
     std::list<PatchRpm> patchRpms() const;
     /** */
     std::list<DeltaRpm> deltaRpms() const;
+    /**
+     * \throws Exception
+     */
+    Pathname getPlainRpm() const;
+    /**
+     * \throws Exception
+     */
+    Pathname getDeltaRpm(BaseVersion & base_r) const;
+    /**
+     * \throws Exception
+     */
+    Pathname getPatchRpm(BaseVersion & base_r) const;
 
     // data here:
  
index f81c5fe..e13d754 100644 (file)
@@ -37,12 +37,12 @@ namespace zypp
     , _buildtime(buildtime)
     , _base_versions(base_versions)
     {}
-    Arch arch() { return _arch; }
-    Pathname filename() { return _filename; }
-    ByteCount downloadsize() { return _downloadsize; }
-    CheckSum checksum() { return _checksum; }
-    Date buildtime() { return _buildtime; }
-    std::list<BaseVersion> baseVersions() { return _base_versions; }
+    Arch arch() const { return _arch; }
+    Pathname filename() const { return _filename; }
+    ByteCount downloadsize() const { return _downloadsize; }
+    CheckSum checksum() const { return _checksum; }
+    Date buildtime() const { return _buildtime; }
+    std::list<BaseVersion> baseVersions() const { return _base_versions; }
   private:
     Arch _arch;
     Pathname _filename;