- first working checksum checker
authorDuncan Mac-Vicar P <dmacvicar@suse.de>
Fri, 7 Jul 2006 14:37:22 +0000 (14:37 +0000)
committerDuncan Mac-Vicar P <dmacvicar@suse.de>
Fri, 7 Jul 2006 14:37:22 +0000 (14:37 +0000)
- removeunused istream constructor

zypp/CheckSum.cc
zypp/MediaSetAccess.cc
zypp/MediaSetAccess.h
zypp/PublicKey.cc
zypp/PublicKey.h

index 172d5cd..a11df9e 100644 (file)
@@ -63,8 +63,8 @@ namespace zypp
   
   /** \relates CheckSum Stream output. */
   std::ostream & operator<<( std::ostream & str, const CheckSum & obj )
-  { return str << (obj.empty() ? std::string("NoCheckSum")
-                               : obj.type()+"-"+obj.checksum()  ); }
+  { return str << (obj.empty() ? std::string("(no checksum)")
+                               : obj.type()+":"+obj.checksum()  ); }
 
   /** \relates CheckSum */
   bool operator==( const CheckSum & lhs, const CheckSum & rhs )
index f735e6a..811c6e0 100644 (file)
@@ -24,13 +24,23 @@ namespace zypp
 ///////////////////////////////////////////////////////////////////
 
   ChecksumFileChecker::ChecksumFileChecker( const CheckSum &checksum )
+    : _checksum(checksum)
   {
-  
   }
 
   bool ChecksumFileChecker::operator()( const Pathname &file )
   {
-
+    // FIXME probably this funcionality should be in CheckSum itself
+    CheckSum real_checksum( _checksum.type(), filesystem::checksum( file, _checksum.type() ));
+    if ( real_checksum == _checksum )
+    {
+      return true;
+    }
+    else
+    {
+      ERR << "Got " << real_checksum << ", expected " << _checksum << std::endl;
+      return false;
+    }
   }
 
   MediaSetAccess::MediaSetAccess(  const Url &url, const Pathname &path )
@@ -67,9 +77,15 @@ namespace zypp
     return provideFileInternal( file, media_nr, false, false);
   }
 
-  const Pathname MediaSetAccess::tryToProvideFile(const Pathname & file, const unsigned media_nr )
+  const Pathname  MediaSetAccess::provideFile(const Pathname & file, const unsigned media_nr, FileChecker checker )
   {
-    return provideFileInternal( file, media_nr, false, false);
+    Pathname p = provideFileInternal( file, media_nr, false, false);
+    
+    if ( ! checker(p) )
+    {
+      ZYPP_THROW(Exception("Error checker"));
+    }
+    return p;
   }
 
   const Pathname MediaSetAccess::provideFileInternal(const Pathname & file, const unsigned media_nr, bool cached, bool checkonly )
index 5be6b92..21e2198 100644 (file)
@@ -91,7 +91,7 @@ namespace zypp
        */
       void setVerifiers( const std::vector<media::MediaVerifierRef> &verifiers );
       const Pathname provideFile(const Pathname & file, const unsigned media_nr = 1 );
-      const Pathname tryToProvideFile(const Pathname & file, const unsigned media_nr = 1 );
+      const Pathname provideFile(const Pathname & file, const unsigned media_nr, const FileChecker checker );
     protected:
       const Pathname provideFileInternal(const Pathname & file, const unsigned media_nr, bool checkonly, bool cached);
       Url rewriteUrl (const Url & url_r, const media::MediaNr medianr);
index 9e53f18..069d1f2 100644 (file)
@@ -43,9 +43,6 @@ namespace devel
       MIL << "Done reading key" << std::endl;
     }
     
-    Impl(const std::istream &data)
-    {}
-    
     public:
       /** Offer default Impl. */
       static shared_ptr<Impl> nullimpl()
@@ -155,15 +152,6 @@ namespace devel
   : _pimpl( Impl::nullimpl() )
   {}
 
-  ///////////////////////////////////////////////////////////////////
-  //
-  //   METHOD NAME : PublicKey::PublicKey
-  //   METHOD TYPE : Ctor
-  //
-  PublicKey::PublicKey( const std::istream &data )
-  : _pimpl( new Impl(data) )
-  {}
-
   PublicKey::PublicKey(   const Pathname &file )
   : _pimpl( new Impl(file) )
   {}
index e3fde7b..6742af3 100644 (file)
@@ -45,7 +45,6 @@ namespace devel
    /** Ctor 
     * \throws when data does not make a key
     */
-    PublicKey(const std::istream &data);
     PublicKey(const Pathname &file);
     ~PublicKey();