no feedback, tests passes, go on
authorDuncan Mac-Vicar P <dmacvicar@suse.de>
Tue, 4 Apr 2006 09:33:52 +0000 (09:33 +0000)
committerDuncan Mac-Vicar P <dmacvicar@suse.de>
Tue, 4 Apr 2006 09:33:52 +0000 (09:33 +0000)
13 files changed:
zypp/Package.cc
zypp/Package.h
zypp/Source.cc
zypp/Source.h
zypp/detail/PackageImplIf.cc
zypp/detail/PackageImplIf.h
zypp/source/SourceImpl.cc
zypp/source/SourceImpl.h
zypp/source/susetags/SuseTagsPackageImpl.cc
zypp/source/susetags/SuseTagsPackageImpl.h
zypp/target/TargetImpl.cc
zypp/target/TargetImpl.h
zypp/target/store/XMLFilesBackend.cc

index 0e323f5..671f0c0 100644 (file)
@@ -59,6 +59,9 @@ namespace zypp
   std::string Package::buildhost() const
   { return pimpl().buildhost(); }
 
+  CheckSum Package::checksum() const
+  { return pimpl().checksum(); }
+
   /** */
   std::string Package::distribution() const
   { return pimpl().distribution(); }
@@ -129,8 +132,8 @@ namespace zypp
   { return pimpl().licenseToConfirm(); }
 
   /** */
-  Pathname Package::plainRpm() const
-  { return pimpl().location(); }
+  //Pathname Package::plainRpm() const
+  //{ return pimpl().location(); }
 
   /** */
   std::list<PatchRpm> Package::patchRpms() const
@@ -141,8 +144,8 @@ namespace zypp
   { return pimpl().deltaRpms(); }
 
   /** */
-  Pathname Package::getPlainRpm() const
-  { return source().provideFile(plainRpm(), mediaId()); }
+  //Pathname Package::getPlainRpm() const
+  //{ return source().provideFile(plainRpm(), mediaId()); }
 
   /** */
   Pathname Package::getDeltaRpm(BaseVersion & base_r) const
@@ -156,7 +159,7 @@ namespace zypp
        return source().provideFile(it->filename());
     }
     ZYPP_THROW(Exception("No matching delta RPM found"));
-    return source().provideFile(plainRpm()); // never reached
+    return source().provideFile(location()); // never reached
   }
 
   /** */
@@ -175,7 +178,7 @@ namespace zypp
       }
     }
     ZYPP_THROW(Exception("No matching patch RPM found"));
-    return source().provideFile(plainRpm()); // never reached
+    return source().provideFile(location()); // never reached
   }
 
   bool Package::installOnly() const
index e4623f3..6398f69 100644 (file)
@@ -38,6 +38,10 @@ namespace zypp
     typedef TraitsType::constPtrType constPtr;
 
   public:
+    /**
+     * Checksum the source says this package should have
+     */
+    CheckSum checksum() const;
     /** Time of package installation */
     Date installtime() const;
     /** Get the package change log */
@@ -84,7 +88,7 @@ namespace zypp
     /** */
     License licenseToConfirm() const;
     /** */
-    Pathname plainRpm() const;
+    //Pathname plainRpm() const;
     /** */
     std::list<PatchRpm> patchRpms() const;
     /** */
@@ -92,7 +96,7 @@ namespace zypp
     /**
      * \throws Exception
      */
-    Pathname getPlainRpm() const;
+    //Pathname getPlainRpm() const;
     /**
      * \throws Exception
      */
index f2830a6..51e4329 100644 (file)
@@ -65,10 +65,12 @@ namespace zypp
   { return _pimpl->provideFile(file_r, media_nr); }
 
   const Pathname Source_Ref::provideDirTree(const Pathname & dir_r,
-                                            const unsigned media_nr)
-                                         
+                                            const unsigned media_nr)                                              
   { return _pimpl->provideDirTree(dir_r, media_nr); }
 
+  const Pathname Source_Ref::providePackage( Package::constPtr package )
+  { return _pimpl->providePackage( package ); }
+  
   const void Source_Ref::releaseFile(const Pathname & file_r,
                                     const unsigned media_nr)
   { _pimpl->releaseFile(file_r, media_nr); }
index 671fc2c..0de6b48 100644 (file)
@@ -18,6 +18,7 @@
 #include "zypp/base/PtrTypes.h"
 #include "zypp/base/SafeBool.h"
 
+#include "zypp/Package.h"
 #include "zypp/Pathname.h"
 #include "zypp/Url.h"
 #include "zypp/Resolvable.h"
@@ -83,6 +84,8 @@ namespace zypp
     /** All resolvables of a given kind provided by this source. */
     const ResStore resolvables(zypp::Resolvable::Kind kind) const;
 
+    const Pathname providePackage( Package::constPtr package );
+    
     /** Provide a file to local filesystem */
     const Pathname provideFile(const Pathname & file_r,
                               const unsigned media_nr = 1);
index 34dc0a5..09bbbab 100644 (file)
@@ -29,6 +29,9 @@ namespace zypp
       Date PackageImplIf::buildtime() const
       { return Date(); }
 
+      CheckSum PackageImplIf::checksum() const
+      { return CheckSum(); }
+
       std::string PackageImplIf::buildhost() const
       { return std::string(); }
 
index 9ccaae8..d308778 100644 (file)
@@ -15,6 +15,7 @@
 #include <set>
 
 #include "zypp/detail/ResObjectImplIf.h"
+#include "zypp/CheckSum.h"
 #include "zypp/Edition.h"
 #include "zypp/Arch.h"
 #include "zypp/Changelog.h"
@@ -64,6 +65,8 @@ namespace zypp
     public:
       /** \name Rpm Package Attributes. */
       //@{
+      
+      virtual CheckSum checksum() const PURE_VIRTUAL;
       /** */
       virtual Date buildtime() const PURE_VIRTUAL;
       /** */
index e5f506e..5491a61 100644 (file)
@@ -10,8 +10,9 @@
  *
 */
 #include <iostream>
+#include <fstream>
 #include "zypp/base/Logger.h"
-
+#include "zypp/Digest.h"
 #include "zypp/SourceFactory.h"
 #include "zypp/source/SourceImpl.h"
 #include "zypp/ZYppCallbacks.h"
@@ -122,6 +123,41 @@ namespace zypp
       media_mgr.dirInfo( _media, retlist, path_r, dots );
     }
 
+    const Pathname SourceImpl::providePackage( Package::constPtr package )
+    {
+#warning FIXME: error handling
+#warning FIXME: Url
+        callback::SendReport<source::DownloadResolvableReport> report;
+        report->start( package, package->source().url() );
+        Pathname file = package->source().provideFile( package->location(), package->mediaId());
+        CheckSum checksum = package->checksum();
+        std::string calculated_digest;
+        // check digest
+        try
+        { 
+          std::ifstream is(file.asString().c_str(), std::ifstream::binary);
+          calculated_digest = Digest::digest(checksum.type(), is);
+          is.close();
+        }
+        catch (std::exception &e)
+        {
+          ERR << "Can't open " << file << " for integrity check." << std::endl;
+        }
+        
+        if ( checksum.checksum() != calculated_digest )
+        {
+          ZYPP_THROW(Exception("Package " + package->location().asString() + " fails integrity check. Expected: [" + checksum.checksum() + "] Read: [" + calculated_digest + "]"));
+        }
+        else
+        {
+          MIL << package->location() << " ok. [" << calculated_digest << "]" << std::endl;
+        }
+        
+        
+        report->finish( package, source::DownloadResolvableReport::NO_ERROR, "" );
+        return file;
+    }
+    
     const Pathname SourceImpl::provideFile(const Pathname & file_r,
                                           const unsigned media_nr,
                                           bool cached,
index 7aedc51..b7870a0 100644 (file)
@@ -115,6 +115,9 @@ namespace zypp
                            const unsigned media_nr = 1,
                            const bool recursive = false);
 
+      const Pathname providePackage( Package::constPtr package );
+      const Pathname providePackageInteractive( Package::constPtr package );
+      
       /**
        * Provide info about a directory
        *
index 8f9b2d6..54cabc9 100644 (file)
@@ -39,7 +39,9 @@ namespace zypp
       SuseTagsPackageImpl::~SuseTagsPackageImpl()
       {}
 
-
+      CheckSum SuseTagsPackageImpl::checksum() const
+      { return _checksum; }
+          
       TranslatedText SuseTagsPackageImpl::summary() const
       { return _summary; }
 
index 57a57ec..9710af0 100644 (file)
@@ -41,7 +41,7 @@ namespace zypp
         //@{
        virtual TranslatedText summary() const;
        virtual TranslatedText description() const;
-
+        virtual CheckSum checksum() const;
         /** */
         virtual Date buildtime() const;
         /** */
index 1c3c7fc..cdc333d 100644 (file)
@@ -138,22 +138,6 @@ namespace zypp
       return _store;
     }
 
-    
-    Pathname TargetImpl::getRpmFile(Package::constPtr package)
-    {
-       callback::SendReport<source::DownloadResolvableReport> report;
-
-#warning FIXME: error handling
-#warning FIXME: Url
-       report->start( package, package->source().url() );
-
-       Pathname file = package->getPlainRpm();
-
-       report->finish( package, source::DownloadResolvableReport::NO_ERROR, "" );
-       
-       return file;
-    }
-
 
     int TargetImpl::commit( ResPool pool_r, unsigned int medianr,
                            TargetImpl::PoolItemList & errors_r, TargetImpl::PoolItemList & remaining_r,
@@ -241,7 +225,7 @@ namespace zypp
           Package::constPtr p = dynamic_pointer_cast<const Package>(it->resolvable());
           if (it->status().isToBeInstalled())
           {
-            Pathname localfile = getRpmFile( p );
+            Pathname localfile = p->source().providePackage(p);
            lastUsedSource = p->source();                       // remember the package source
 
 #warning Exception handling
@@ -320,7 +304,7 @@ namespace zypp
              it->status().setTransact( false, ResStatus::USER );
             }
             progress.disconnect();
-           p->source().releaseFile( p->plainRpm(), p->mediaId() );
+           p->source().releaseFile( p->location(), p->mediaId() );
           }
           else
           {
index 0fa8748..2b1a24b 100644 (file)
@@ -129,9 +129,6 @@ namespace zypp
     private:
       /** Null implementation */
       static TargetImpl_Ptr _nullimpl;
-      
-      /** wrapper with callback around getPlainRpm */
-      Pathname getRpmFile(Package::constPtr package);
     };
     ///////////////////////////////////////////////////////////////////
 
index 1782c7f..70ed554 100644 (file)
@@ -515,7 +515,12 @@ XMLFilesBackend::deleteObject( ResObject::constPtr resolvable )
   std::string filename = fullPathForResolvable(resolvable);
   try
   {
-    remove(path(filename));
+    int ret = filesystem::unlink(Pathname(filename));
+    if ( ret != 0 )
+    {
+      ERR << "Error removing resolvable " << resolvable << std::endl;
+      ZYPP_THROW(Exception("Error deleting " + filename));
+    }
   }
   catch(std::exception &e)
   {