Author: dmacvicar Date: Wed Jul 18 11:26:36 2007 New Revision: 6055 URL: http://svn.opensuse.org/viewcvs/zypp?rev=6055&view=rev Log: - Throw a known exception if trying to build the cache without metadata so zypper could ask to the user wether to refresh - update testcases Modified: trunk/libzypp/tests/zypp/RepoManager_test.cc trunk/libzypp/zypp/RepoManager.cc trunk/libzypp/zypp/RepoManager.h trunk/libzypp/zypp/RepoStatus.cc trunk/libzypp/zypp/RepoStatus.h trunk/libzypp/zypp/repo/RepoException.h Modified: trunk/libzypp/tests/zypp/RepoManager_test.cc URL: http://svn.opensuse.org/viewcvs/zypp/trunk/libzypp/tests/zypp/RepoManager_test.cc?rev=6055&r1=6054&r2=6055&view=diff ============================================================================== --- trunk/libzypp/tests/zypp/RepoManager_test.cc (original) +++ trunk/libzypp/tests/zypp/RepoManager_test.cc Wed Jul 18 11:26:36 2007 @@ -85,20 +85,29 @@ return; RepoInfo repo(repos.front()); + + // we have no metadata yet so this should throw + BOOST_CHECK_THROW( manager.buildCache(repo), + RepoMetadataException ); + manager.refreshMetadata(repo); + BOOST_CHECK_MESSAGE( ! manager.isCached(repo), + "Repo is not yet cached" ); + Repository repository; - try { - repository = manager.createFromCache(repo); - } - catch ( const RepoNotCachedException &e ) - { - ZYPP_CAUGHT(e); - MIL << "repo " << repo.alias() << " not cached yet. Caching..." << endl; - manager.buildCache(repo); - repository = manager.createFromCache(repo); - } + + // it is not cached, this should throw + BOOST_CHECK_THROW( manager.createFromCache(repo), + RepoNotCachedException ); + + MIL << "repo " << repo.alias() << " not cached yet. Caching..." << endl; + manager.buildCache(repo); + repository = manager.createFromCache(repo); + BOOST_CHECK_MESSAGE( manager.isCached(repo), + "Repo is cached" ); + ResStore store = repository.resolvables(); MIL << store.size() << " resolvables" << endl; Modified: trunk/libzypp/zypp/RepoManager.cc URL: http://svn.opensuse.org/viewcvs/zypp/trunk/libzypp/zypp/RepoManager.cc?rev=6055&r1=6054&r2=6055&view=diff ============================================================================== --- trunk/libzypp/zypp/RepoManager.cc (original) +++ trunk/libzypp/zypp/RepoManager.cc Wed Jul 18 11:26:36 2007 @@ -482,6 +482,11 @@ cache::CacheStore store(_pimpl->options.repoCachePath); RepoStatus raw_metadata_status = rawMetadataStatus(info); + if ( raw_metadata_status.empty() ) + { + ZYPP_THROW(RepoMetadataException(info)); + } + if ( store.isCached( info.alias() ) ) { MIL << info.alias() << " is already cached." << endl; Modified: trunk/libzypp/zypp/RepoManager.h URL: http://svn.opensuse.org/viewcvs/zypp/trunk/libzypp/zypp/RepoManager.h?rev=6055&r1=6054&r2=6055&view=diff ============================================================================== --- trunk/libzypp/zypp/RepoManager.h (original) +++ trunk/libzypp/zypp/RepoManager.h Wed Jul 18 11:26:36 2007 @@ -139,7 +139,12 @@ * * \note the local metadata must be valid. * - * \throws repo::RepoNoAliasException if can't figure an alias to look in cache + * \throws repo::RepoNoAliasException if can't figure + * an alias to look in cache + * + * \throws repo::RepoMetadataException if the metadata + * is not enough to build a cache (empty, incorrect, or + * refresh needed) * \throws Exception on unknown error. */ void buildCache( const RepoInfo &info, Modified: trunk/libzypp/zypp/RepoStatus.cc URL: http://svn.opensuse.org/viewcvs/zypp/trunk/libzypp/zypp/RepoStatus.cc?rev=6055&r1=6054&r2=6055&view=diff ============================================================================== --- trunk/libzypp/zypp/RepoStatus.cc (original) +++ trunk/libzypp/zypp/RepoStatus.cc Wed Jul 18 11:26:36 2007 @@ -80,9 +80,19 @@ RepoStatus::RepoStatus( const Pathname &path ) : _pimpl( new Impl() ) { - _pimpl->checksum = filesystem::sha1sum(path); + PathInfo info(path); + if ( info.isExist() ) + { + _pimpl->checksum = filesystem::sha1sum(path); + _pimpl->timestamp = Date(info.mtime()); + } } + bool RepoStatus::empty() const + { + return _pimpl->checksum.empty(); + } + RepoStatus & RepoStatus::setChecksum( const string &checksum ) { _pimpl->checksum = checksum; Modified: trunk/libzypp/zypp/RepoStatus.h URL: http://svn.opensuse.org/viewcvs/zypp/trunk/libzypp/zypp/RepoStatus.h?rev=6055&r1=6054&r2=6055&view=diff ============================================================================== --- trunk/libzypp/zypp/RepoStatus.h (original) +++ trunk/libzypp/zypp/RepoStatus.h Wed Jul 18 11:26:36 2007 @@ -56,6 +56,14 @@ Date timestamp() const; /** + * \short Is the status empty? + * + * An empty status means that the status + * was not calculated. + */ + bool empty() const; + + /** * set the repository checksum \see checksum * \param checksum */ @@ -79,6 +87,9 @@ * As most repository state is represented * by the status of the index file, you can * construct the status from a file. + * + * \note construct from a non existing + * file will result in an empty status */ RepoStatus( const Pathname &file ); Modified: trunk/libzypp/zypp/repo/RepoException.h URL: http://svn.opensuse.org/viewcvs/zypp/trunk/libzypp/zypp/repo/RepoException.h?rev=6055&r1=6054&r2=6055&view=diff ============================================================================== --- trunk/libzypp/zypp/repo/RepoException.h (original) +++ trunk/libzypp/zypp/repo/RepoException.h Wed Jul 18 11:26:36 2007 @@ -133,6 +133,29 @@ ~RepoUnknownTypeException() throw() {} }; + + /** + * thrown when it was impossible to + * use the raw metadata for this repo. + */ + class RepoMetadataException : public RepoException + { + public: + RepoMetadataException( const RepoInfo &info) + : _info(info) + {} + + RepoMetadataException() + {} + + ~RepoMetadataException() throw() + {} + + RepoInfo info() + { return _info; } + private: + RepoInfo _info; + }; ///////////////////////////////////////////////////////////////// } // namespace parser -- To unsubscribe, e-mail: zypp-commit+unsubscribe@opensuse.org For additional commands, e-mail: zypp-commit+help@opensuse.org