Author: dmacvicar
Date: Tue May 22 18:04:20 2007
New Revision: 5587
URL: http://svn.opensuse.org/viewcvs/zypp?rev=5587&view=rev
Log:
- make FileChecker use exceptions instead of bool
- Move it out of Fetcher
- port..
Added:
trunk/libzypp/zypp/FileChecker.cc
trunk/libzypp/zypp/FileChecker.h
Modified:
trunk/libzypp/zypp/CMakeLists.txt
trunk/libzypp/zypp/Fetcher.cc
trunk/libzypp/zypp/Fetcher.h
trunk/libzypp/zypp/source/yum/YUMDownloader.cc
trunk/libzypp/zypp/source/yum/YUMResourceType.h
Modified: trunk/libzypp/zypp/CMakeLists.txt
URL: http://svn.opensuse.org/viewcvs/zypp/trunk/libzypp/zypp/CMakeLists.txt?rev=5587&r1=5586&r2=5587&view=diff
==============================================================================
--- trunk/libzypp/zypp/CMakeLists.txt (original)
+++ trunk/libzypp/zypp/CMakeLists.txt Tue May 22 18:04:20 2007
@@ -86,6 +86,7 @@
ProvideFilePolicy.cc
OnMediaLocation.cc
Fetcher.cc
+ FileChecker.cc
)
SET( zypp_HEADERSZ
@@ -182,6 +183,7 @@
ZYppCommitPolicy.h
ZYppCommitResult.h
ZYppFactory.h
+ FileChecker.h
)
INSTALL( FILES ${zypp_HEADERS} DESTINATION "${CMAKE_INSTALL_PREFIX}/include/zypp" )
Modified: trunk/libzypp/zypp/Fetcher.cc
URL: http://svn.opensuse.org/viewcvs/zypp/trunk/libzypp/zypp/Fetcher.cc?rev=5587&r1=5586&r2=5587&view=diff
==============================================================================
--- trunk/libzypp/zypp/Fetcher.cc (original)
+++ trunk/libzypp/zypp/Fetcher.cc Tue May 22 18:04:20 2007
@@ -14,9 +14,7 @@
#include "zypp/base/Logger.h"
#include "zypp/base/DefaultIntegral.h"
-#include "zypp/ZYppFactory.h"
#include "zypp/Fetcher.h"
-#include "zypp/KeyRing.h"
using namespace std;
@@ -24,96 +22,9 @@
namespace zypp
{ /////////////////////////////////////////////////////////////////
- Fetcher::ChecksumFileChecker::ChecksumFileChecker( const CheckSum &checksum )
- : _checksum(checksum)
- {
- }
-
- bool Fetcher::ChecksumFileChecker::operator()( const Pathname &file ) const
- {
- callback::SendReport<DigestReport> report;
- CheckSum real_checksum( _checksum.type(), filesystem::checksum( file, _checksum.type() ));
-
- if ( _checksum.empty() )
- {
- MIL << "File " << file << " has no checksum available." << std::endl;
- if ( report->askUserToAcceptNoDigest(file) )
- {
- MIL << "User accepted " << file << " with no checksum." << std::endl;
- return true;
- }
- else
- {
- return false;
- }
- }
- else
- {
- if ( (real_checksum == _checksum) )
- {
- if ( report->askUserToAcceptWrongDigest( file, _checksum.checksum(), real_checksum.checksum() ) )
- {
- WAR << "User accepted " << file << " with WRONG CHECKSUM." << std::endl;
- return true;
- }
- else
- {
- return false;
- }
- }
- else
- {
- return true;
- }
- }
- }
-
- bool Fetcher::NullFileChecker::operator()(const Pathname &file ) const
- {
- return true;
- }
-
- bool Fetcher::CompositeFileChecker::operator()(const Pathname &file ) const
- {
- bool result = true;
- for ( listFetcher::FileChecker::const_iterator it = _checkers.begin(); it != _checkers.end(); ++it )
- {
- result = result && (*it)(file);
- }
- return result;
- }
-
- void Fetcher::CompositeFileChecker::add( const FileChecker &checker )
- {
- _checkers.push_back(checker);
- }
-
- Fetcher::SignatureFileChecker::SignatureFileChecker( const Pathname &signature )
- : _signature(signature)
- {
- }
-
- Fetcher::SignatureFileChecker::SignatureFileChecker()
- {
- }
-
- void Fetcher::SignatureFileChecker::addPublicKey( const Pathname &publickey )
- {
- ZYpp::Ptr z = getZYpp();
- z->keyRing()->importKey(publickey, false);
- }
-
- bool Fetcher::SignatureFileChecker::operator()(const Pathname &file ) const
- {
- ZYpp::Ptr z = getZYpp();
- MIL << "checking " << file << " file validity using digital signature.." << endl;
- bool valid = z->keyRing()->verifyFileSignatureWorkflow( file, string(), _signature);
- return valid;
- }
-
/**
* Class to encapsulate the \ref OnMediaLocation object
- * and the \ref Fetcher::FileChcker together
+ * and the \ref FileChcker together
*/
struct FetcherJob
{
@@ -124,7 +35,7 @@
}
OnMediaLocation location;
- Fetcher::CompositeFileChecker checkers;
+ CompositeFileChecker checkers;
};
///////////////////////////////////////////////////////////////////
@@ -137,8 +48,8 @@
public:
- void enqueue( const OnMediaLocation &resource, const Fetcher::FileChecker &checker );
- void enqueueDigested( const OnMediaLocation &resource, const Fetcher::FileChecker &checker );
+ void enqueue( const OnMediaLocation &resource, const FileChecker &checker );
+ void enqueueDigested( const OnMediaLocation &resource, const FileChecker &checker );
void addCachePath( const Pathname &cache_dir );
void reset();
void start( const Pathname &dest_dir, MediaSetAccess &media );
@@ -275,13 +186,21 @@
// no matter where did we got the file, try to validate it:
Pathname localfile = dest_dir + (*it_res).location.filename();
// call the checker function
- bool good = (*it_res).checkers(localfile);
- if (!good)
+ try {
+ (*it_res).checkers(localfile);
+ }
+ catch ( const FileCheckException &e )
{
- //FIXME better message
- ZYPP_THROW(Exception("File " + (*it_res).location.filename().asString() + " does not validate." ));
+ ZYPP_RETHROW(e);
+ }
+ catch ( const Exception &e )
+ {
+ ZYPP_RETHROW(e);
+ }
+ catch (...)
+ {
+ ZYPP_THROW(Exception("Unknown error while validating " + (*it_res).location.filename().asString()));
}
-
} // for each job
}
@@ -314,12 +233,12 @@
Fetcher::~Fetcher()
{}
- void Fetcher::enqueueDigested( const OnMediaLocation &resource, const Fetcher::FileChecker &checker )
+ void Fetcher::enqueueDigested( const OnMediaLocation &resource, const FileChecker &checker )
{
_pimpl->enqueue(resource, checker);
}
- void Fetcher::enqueue( const OnMediaLocation &resource, const Fetcher::FileChecker &checker )
+ void Fetcher::enqueue( const OnMediaLocation &resource, const FileChecker &checker )
{
_pimpl->enqueue(resource, checker);
}
Modified: trunk/libzypp/zypp/Fetcher.h
URL: http://svn.opensuse.org/viewcvs/zypp/trunk/libzypp/zypp/Fetcher.h?rev=5587&r1=5586&r2=5587&view=diff
==============================================================================
--- trunk/libzypp/zypp/Fetcher.h (original)
+++ trunk/libzypp/zypp/Fetcher.h Tue May 22 18:04:20 2007
@@ -21,6 +21,7 @@
#include "zypp/OnMediaLocation.h"
#include "zypp/Digest.h"
#include "zypp/MediaSetAccess.h"
+#include "zypp/FileChecker.h"
///////////////////////////////////////////////////////////////////
namespace zypp
@@ -66,106 +67,6 @@
public:
/** Implementation */
class Impl;
-
- /**
- * Functor signature used to check files.
- * \param file File to check.
- */
- typedef boost::function FileChecker;
-
- /**
- * Built in file checkers
- */
-
- /**
- * \short Checks for a valid checksum and interacts with the user.
- */
- class ChecksumFileChecker
- {
- public:
- /**
- * Constructor.
- * \param checksum Checksum that validates the file
- */
- ChecksumFileChecker( const CheckSum &checksum );
- /**
- * \short Try to validate the file
- * \param file File to validate.
- */
- bool operator()( const Pathname &file ) const;
-
- private:
- CheckSum _checksum;
- };
-
- /**
- * \short Checks for the validity of a signature
- */
- class SignatureFileChecker
- {
- public:
- /**
- * Constructor.
- * \param signature Signature that validates the file
- */
- SignatureFileChecker( const Pathname &signature );
-
- /**
- * Default Constructor.
- * \short Signature for unsigned files
- * Use it when you dont have a signature but you want
- * to check the user to accept an unsigned file.
- */
- SignatureFileChecker();
-
-
- /**
- * add a public key to the list of known keys
- */
- void addPublicKey( const Pathname &publickey );
- /**
- * \short Try to validate the file
- * \param file File to validate.
- */
- bool operator()( const Pathname &file ) const;
-
- private:
- Pathname _signature;
- };
-
- /**
- * \short Checks for nothing
- * Used as the default checker
- */
- class NullFileChecker
- {
- public:
- bool operator()( const Pathname &file ) const;
- };
-
- /**
- * \short Checker composed of more checkers.
- *
- * Allows to create a checker composed of various
- * checkers altothether. It will only
- * validate if all the checkers validate.
- *
- * \code
- * CompositeFileChecker com;
- * com.add(checker1);
- * com.add(checker2);
- * fetcher.enqueue(location, com);
- * \endcode
- */
- class CompositeFileChecker
- {
- public:
- void add( const FileChecker &checker );
- bool operator()( const Pathname &file ) const;
- private:
- std::list<FileChecker> _checkers;
- };
-
public:
/** Default ctor */
Fetcher();
Added: trunk/libzypp/zypp/FileChecker.cc
URL: http://svn.opensuse.org/viewcvs/zypp/trunk/libzypp/zypp/FileChecker.cc?rev=5587&view=auto
==============================================================================
--- trunk/libzypp/zypp/FileChecker.cc (added)
+++ trunk/libzypp/zypp/FileChecker.cc Tue May 22 18:04:20 2007
@@ -0,0 +1,119 @@
+/*---------------------------------------------------------------------\
+| ____ _ __ __ ___ |
+| |__ / \ / / . \ . \ |
+| / / \ V /| _/ _/ |
+| / /__ | | | | | | |
+| /_____||_| |_| |_| |
+| |
+\---------------------------------------------------------------------*/
+/** \file zypp/FileChecker.cc
+ *
+*/
+#include <iostream>
+#include "zypp/base/Logger.h"
+#include "zypp/FileChecker.h"
+#include "zypp/ZYppFactory.h"
+#include "zypp/Digest.h"
+#include "zypp/KeyRing.h"
+
+using namespace std;
+
+///////////////////////////////////////////////////////////////////
+namespace zypp
+{ /////////////////////////////////////////////////////////////////
+
+ ChecksumFileChecker::ChecksumFileChecker( const CheckSum &checksum )
+ : _checksum(checksum)
+ {
+ }
+
+ void ChecksumFileChecker::operator()( const Pathname &file ) const
+ {
+ callback::SendReport<DigestReport> report;
+ CheckSum real_checksum( _checksum.type(), filesystem::checksum( file, _checksum.type() ));
+
+ if ( _checksum.empty() )
+ {
+ MIL << "File " << file << " has no checksum available." << std::endl;
+ if ( report->askUserToAcceptNoDigest(file) )
+ {
+ MIL << "User accepted " << file << " with no checksum." << std::endl;
+ return;
+ }
+ else
+ {
+ ZYPP_THROW(FileCheckException("No checksum available"));
+ }
+ }
+ else
+ {
+ if ( (real_checksum == _checksum) )
+ {
+ if ( report->askUserToAcceptWrongDigest( file, _checksum.checksum(), real_checksum.checksum() ) )
+ {
+ WAR << "User accepted " << file << " with WRONG CHECKSUM." << std::endl;
+ return;
+ }
+ else
+ {
+ ZYPP_THROW(FileCheckException("Wrong checksum"));
+ }
+ }
+ }
+ }
+
+ void NullFileChecker::operator()(const Pathname &file ) const
+ {
+ return;
+ }
+
+ void CompositeFileChecker::operator()(const Pathname &file ) const
+ {
+ for ( list<FileChecker>::const_iterator it = _checkers.begin(); it != _checkers.end(); ++it )
+ {
+ (*it)(file);
+ }
+ }
+
+ void CompositeFileChecker::add( const FileChecker &checker )
+ {
+ _checkers.push_back(checker);
+ }
+
+ SignatureFileChecker::SignatureFileChecker( const Pathname &signature )
+ : _signature(signature)
+ {
+ }
+
+ SignatureFileChecker::SignatureFileChecker()
+ {
+ }
+
+ void SignatureFileChecker::addPublicKey( const Pathname &publickey )
+ {
+ ZYpp::Ptr z = getZYpp();
+ z->keyRing()->importKey(publickey, false);
+ }
+
+ void SignatureFileChecker::operator()(const Pathname &file ) const
+ {
+ ZYpp::Ptr z = getZYpp();
+ MIL << "checking " << file << " file validity using digital signature.." << endl;
+ bool valid = z->keyRing()->verifyFileSignatureWorkflow( file, string(), _signature);
+ if (!valid)
+ ZYPP_THROW(FileCheckException("Signature verification failed"));
+ }
+
+ /******************************************************************
+ **
+ ** FUNCTION NAME : operator<<
+ ** FUNCTION TYPE : std::ostream &
+ */
+ std::ostream & operator<<( std::ostream & str, const FileChecker & obj )
+ {
+ return str;
+ }
+
+ /////////////////////////////////////////////////////////////////
+} // namespace zypp
+///////////////////////////////////////////////////////////////////
Added: trunk/libzypp/zypp/FileChecker.h
URL: http://svn.opensuse.org/viewcvs/zypp/trunk/libzypp/zypp/FileChecker.h?rev=5587&view=auto
==============================================================================
--- trunk/libzypp/zypp/FileChecker.h (added)
+++ trunk/libzypp/zypp/FileChecker.h Tue May 22 18:04:20 2007
@@ -0,0 +1,158 @@
+/*---------------------------------------------------------------------\
+| ____ _ __ __ ___ |
+| |__ / \ / / . \ . \ |
+| / / \ V /| _/ _/ |
+| / /__ | | | | | | |
+| /_____||_| |_| |_| |
+| |
+\---------------------------------------------------------------------*/
+/** \file zypp/FileChecker.h
+ *
+*/
+#ifndef ZYPP_FILECHECKER_H
+#define ZYPP_FILECHECKER_H
+
+#include <iosfwd>
+#include <list>
+#include "zypp/base/Exception.h"
+#include "zypp/base/Function.h"
+#include "zypp/Pathname.h"
+#include "zypp/CheckSum.h"
+
+///////////////////////////////////////////////////////////////////
+namespace zypp
+{ /////////////////////////////////////////////////////////////////
+
+ /**
+ * Functor signature used to check files.
+ * \param file File to check.
+ *
+ * \throws FileCheckException when the file does not
+ * validate and the user don't want to continue.
+ */
+ typedef function FileChecker;
+
+ class FileCheckException : public Exception
+ {
+ public:
+ FileCheckException(const std::string &msg)
+ : Exception(msg)
+ {}
+ };
+
+ class CheckSumCheckException : public FileCheckException
+ {
+ //TODO
+ };
+
+ class SignatureCheckException : public FileCheckException
+ {
+ //TODO
+ };
+
+ /**
+ * Built in file checkers
+ */
+
+ /**
+ * \short Checks for a valid checksum and interacts with the user.
+ */
+ class ChecksumFileChecker
+ {
+ public:
+ /**
+ * Constructor.
+ * \param checksum Checksum that validates the file
+ */
+ ChecksumFileChecker( const CheckSum &checksum );
+ /**
+ * \short Try to validate the file
+ * \param file File to validate.
+ *
+ * \throws CheckSumCheckException if validation fails
+ */
+ void operator()( const Pathname &file ) const;
+ private:
+ CheckSum _checksum;
+ };
+
+ /**
+ * \short Checks for the validity of a signature
+ */
+ class SignatureFileChecker
+ {
+ public:
+ /**
+ * Constructor.
+ * \param signature Signature that validates the file
+ */
+ SignatureFileChecker( const Pathname &signature );
+
+ /**
+ * Default Constructor.
+ * \short Signature for unsigned files
+ * Use it when you dont have a signature but you want
+ * to check the user to accept an unsigned file.
+ */
+ SignatureFileChecker();
+
+
+ /**
+ * add a public key to the list of known keys
+ */
+ void addPublicKey( const Pathname &publickey );
+ /**
+ * \short Try to validate the file
+ * \param file File to validate.
+ *
+ * \throws SignatureCheckException if validation fails
+ */
+ void operator()( const Pathname &file ) const;
+
+ private:
+ Pathname _signature;
+ };
+
+ /**
+ * \short Checks for nothing
+ * Used as the default checker
+ */
+ class NullFileChecker
+ {
+ public:
+ void operator()( const Pathname &file ) const;
+ };
+
+ /**
+ * \short Checker composed of more checkers.
+ *
+ * Allows to create a checker composed of various
+ * checkers altothether. It will only
+ * validate if all the checkers validate.
+ *
+ * \code
+ * CompositeFileChecker com;
+ * com.add(checker1);
+ * com.add(checker2);
+ * fetcher.enqueue(location, com);
+ * \endcode
+ */
+ class CompositeFileChecker
+ {
+ public:
+ void add( const FileChecker &checker );
+ /**
+ * \throws FileCheckException if validation fails
+ */
+ void operator()( const Pathname &file ) const;
+ private:
+ std::list<FileChecker> _checkers;
+ };
+
+ /** \relates FileChecker Stream output */
+ std::ostream & operator<<( std::ostream & str, const FileChecker & obj );
+
+ /////////////////////////////////////////////////////////////////
+} // namespace zypp
+///////////////////////////////////////////////////////////////////
+#endif // ZYPP_FILECHECKER_H
Modified: trunk/libzypp/zypp/source/yum/YUMDownloader.cc
URL: http://svn.opensuse.org/viewcvs/zypp/trunk/libzypp/zypp/source/yum/YUMDownloader.cc?rev=5587&r1=5586&r2=5587&view=diff
==============================================================================
--- trunk/libzypp/zypp/source/yum/YUMDownloader.cc (original)
+++ trunk/libzypp/zypp/source/yum/YUMDownloader.cc Tue May 22 18:04:20 2007
@@ -45,6 +45,14 @@
bool YUMDownloader::repomd_Callback( const OnMediaLocation &loc, const YUMResourceType &dtype )
{
MIL << dtype << " : " << loc << endl;
+
+ // skip other
+ if ( dtype == YUMResourceType::OTHER )
+ {
+ MIL << "Skipping other.xml" << endl;
+ return true;
+ }
+
_fetcher.enqueueDigested(loc);
// We got a patches file we need to read, to add patches listed
@@ -56,6 +64,7 @@
// now the patches.xml file must exists
PatchesFileReader( _dest_dir + loc.filename(), bind( &YUMDownloader::patches_Callback, this, _1, _2));
}
+
return true;
}
@@ -75,10 +84,10 @@
_fetcher.start( dest_dir, _media );
- Fetcher::SignatureFileChecker sigchecker;
+ SignatureFileChecker sigchecker;
if ( PathInfo( dest_dir + sigpath ).isExist() )
- sigchecker = Fetcher::SignatureFileChecker(dest_dir + sigpath);
+ sigchecker = SignatureFileChecker(dest_dir + sigpath);
if ( PathInfo( dest_dir + keypath ).isExist() )
sigchecker.addPublicKey(dest_dir + keypath );
Modified: trunk/libzypp/zypp/source/yum/YUMResourceType.h
URL: http://svn.opensuse.org/viewcvs/zypp/trunk/libzypp/zypp/source/yum/YUMResourceType.h?rev=5587&r1=5586&r2=5587&view=diff
==============================================================================
--- trunk/libzypp/zypp/source/yum/YUMResourceType.h (original)
+++ trunk/libzypp/zypp/source/yum/YUMResourceType.h Tue May 22 18:04:20 2007
@@ -10,9 +10,9 @@
#ifndef YUMRESOURCETYPE_H_
#define YUMRESOURCETYPE_H_
+#include <iosfwd>
#include<string>
-
namespace zypp
{
namespace source
--
To unsubscribe, e-mail: zypp-commit+unsubscribe@opensuse.org
For additional commands, e-mail: zypp-commit+help@opensuse.org