ProvideFilePolicy.cc
OnMediaLocation.cc
Fetcher.cc
+ FileChecker.cc
)
SET( zypp_HEADERSZ
ZYppCommitPolicy.h
ZYppCommitResult.h
ZYppFactory.h
+ FileChecker.h
)
INSTALL( FILES ${zypp_HEADERS} DESTINATION "${CMAKE_INSTALL_PREFIX}/include/zypp" )
#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;
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 ( list<Fetcher::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
{
}
OnMediaLocation location;
- Fetcher::CompositeFileChecker checkers;
+ CompositeFileChecker checkers;
};
///////////////////////////////////////////////////////////////////
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 );
// 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
}
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);
}
#include "zypp/OnMediaLocation.h"
#include "zypp/Digest.h"
#include "zypp/MediaSetAccess.h"
+#include "zypp/FileChecker.h"
///////////////////////////////////////////////////////////////////
namespace zypp
public:
/** Implementation */
class Impl;
-
- /**
- * Functor signature used to check files.
- * \param file File to check.
- */
- typedef boost::function<bool ( const Pathname &file )> 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();
--- /dev/null
+/*---------------------------------------------------------------------\
+| ____ _ __ __ ___ |
+| |__ / \ / / . \ . \ |
+| / / \ 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
+///////////////////////////////////////////////////////////////////
--- /dev/null
+/*---------------------------------------------------------------------\
+| ____ _ __ __ ___ |
+| |__ / \ / / . \ . \ |
+| / / \ 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<void ( const Pathname &file )> 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
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
// now the patches.xml file must exists
PatchesFileReader( _dest_dir + loc.filename(), bind( &YUMDownloader::patches_Callback, this, _1, _2));
}
+
return true;
}
_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 );
#ifndef YUMRESOURCETYPE_H_
#define YUMRESOURCETYPE_H_
+#include <iosfwd>
#include<string>
-
namespace zypp
{
namespace source