Author: dmacvicar Date: Mon Jun 18 18:05:43 2007 New Revision: 5772 URL: http://svn.opensuse.org/viewcvs/zypp?rev=5772&view=rev Log: backup implementing smart refresh, addding and deletion of repos Modified: trunk/libzypp/zypp/RepoManager.cc trunk/libzypp/zypp/RepoManager.h trunk/libzypp/zypp/RepoStatus.cc trunk/libzypp/zypp/RepoStatus.h trunk/libzypp/zypp/cache/CacheStore.cc trunk/libzypp/zypp/parser/IniDict.cc trunk/libzypp/zypp/parser/IniDict.h trunk/libzypp/zypp/parser/RepoFileReader.cc trunk/libzypp/zypp/repo/susetags/Downloader.cc trunk/libzypp/zypp/repo/susetags/Downloader.h trunk/libzypp/zypp/repo/yum/Downloader.cc trunk/libzypp/zypp/repo/yum/Downloader.h Modified: trunk/libzypp/zypp/RepoManager.cc URL: http://svn.opensuse.org/viewcvs/zypp/trunk/libzypp/zypp/RepoManager.cc?rev=5772&r1=5771&r2=5772&view=diff ============================================================================== --- trunk/libzypp/zypp/RepoManager.cc (original) +++ trunk/libzypp/zypp/RepoManager.cc Mon Jun 18 18:05:43 2007 @@ -253,12 +253,52 @@ //////////////////////////////////////////////////////////////////////////// + RepoStatus RepoManager::rawMetadataStatus( const RepoInfo &info ) + { + Pathname rawpath = rawcache_path_for_repoinfo( _pimpl->options, info ); + RepoType repokind = info.type(); + switch ( repokind.toEnum() ) + { + case RepoType::NONE_e: + // unknown, probe the local metadata + repokind = probe(Url(rawpath.asString())); + break; + default: + break; + } + + switch ( repokind.toEnum() ) + { + case RepoType::RPMMD_e : + { + return RepoStatus( rawpath + "/repodata/repomd.xml"); + } + break; + case RepoType::YAST2_e : + { + return RepoStatus( rawpath + "/content"); + } + break; + default: + ZYPP_THROW(RepoUnknownTypeException()); + } + } + + RepoStatus RepoManager::cacheStatus( const RepoInfo &info ) + { + return RepoStatus(); + } + + void RepoManager::refreshMetadata( const RepoInfo &info, + RepoRefreshPolicy policy, const ProgressData::ReceiverFnc & progress ) { assert_alias(info); assert_urls(info); + RepoStatus oldstatus; + RepoStatus newstatus; // try urls one by one for ( RepoInfo::urls_const_iterator it = info.baseUrlsBegin(); it != info.baseUrlsEnd(); ++it ) { @@ -278,19 +318,51 @@ break; } + Pathname rawpath = rawcache_path_for_repoinfo( _pimpl->options, info ); + oldstatus = rawMetadataStatus(info); + switch ( repokind.toEnum() ) { case RepoType::RPMMD_e : { yum::Downloader downloader( url, "/" ); - downloader.download(tmpdir.path()); + + RepoStatus newstatus = downloader.status(); + bool refresh = false; + if ( oldstatus.checksum() == newstatus.checksum() ) + { + MIL << "repo has not changed" << endl; + if ( policy == RefreshForced ) + { + MIL << "refresh set to forced" << endl; + refresh = true; + } + } + + if ( refresh ) + downloader.download(tmpdir.path()); + // no error } break; case RepoType::YAST2_e : { susetags::Downloader downloader( url, "/" ); - downloader.download(tmpdir.path()); + + RepoStatus newstatus = downloader.status(); + bool refresh = false; + if ( oldstatus.checksum() == newstatus.checksum() ) + { + MIL << "repo has not changed" << endl; + if ( policy == RefreshForced ) + { + MIL << "refresh set to forced" << endl; + refresh = true; + } + } + + if ( refresh ) + downloader.download(tmpdir.path()); // no error } break; @@ -300,7 +372,6 @@ // ok we have the metadata, now exchange // the contents - Pathname rawpath = rawcache_path_for_repoinfo(_pimpl->options, info); TmpDir oldmetadata; filesystem::assert_dir(rawpath); filesystem::rename( rawpath, oldmetadata.path() ); @@ -322,6 +393,7 @@ //////////////////////////////////////////////////////////////////////////// void RepoManager::buildCache( const RepoInfo &info, + CacheBuildPolicy policy, const ProgressData::ReceiverFnc & progress ) { assert_alias(info); @@ -372,6 +444,9 @@ ZYPP_THROW(RepoUnknownTypeException()); } + // update timestamp and checksum + //store.updateRepository(id, ) + MIL << "Commit cache.." << endl; store.commit(); } @@ -476,8 +551,11 @@ int counter = 1; while ( PathInfo(_pimpl->options.knownReposPath + filename).isExist() ) { - filename = Pathname( filename.asString() ); + filename = Pathname( filename.asString() + "_" + str::numstring(counter)); + counter++; } + // now we have a filename that does not exists + } //////////////////////////////////////////////////////////////////////////// Modified: trunk/libzypp/zypp/RepoManager.h URL: http://svn.opensuse.org/viewcvs/zypp/trunk/libzypp/zypp/RepoManager.h?rev=5772&r1=5771&r2=5772&view=diff ============================================================================== --- trunk/libzypp/zypp/RepoManager.h (original) +++ trunk/libzypp/zypp/RepoManager.h Mon Jun 18 18:05:43 2007 @@ -24,6 +24,7 @@ #include "zypp/RepoInfo.h" #include "zypp/repo/RepoException.h" #include "zypp/repo/RepoType.h" +#include "zypp/RepoStatus.h" #include "zypp/ProgressData.h" /////////////////////////////////////////////////////////////////// @@ -75,10 +76,16 @@ enum RepoRefreshPolicy { - RefreshIfChanged, + RefreshIfNeeded, RefreshForced }; + enum CacheBuildPolicy + { + BuildIfNeeded, + BuildForced + }; + enum RepoAddPolicy { }; @@ -107,6 +114,7 @@ * \throws Exception on unknown error. */ void refreshMetadata( const RepoInfo &info, + RepoRefreshPolicy policy = RefreshIfNeeded, const ProgressData::ReceiverFnc & progressrcv = ProgressData::ReceiverFnc() ); /** @@ -134,6 +142,7 @@ * \throws Exception on unknown error. */ void buildCache( const RepoInfo &info, + CacheBuildPolicy policy = BuildIfNeeded, const ProgressData::ReceiverFnc & progressrcv = ProgressData::ReceiverFnc() ); /** @@ -205,6 +214,10 @@ void removeRepository( const std::string & alias, const ProgressData::ReceiverFnc & progressrcv = ProgressData::ReceiverFnc() ); + RepoStatus rawMetadataStatus( const RepoInfo &info ); + RepoStatus cacheStatus( const RepoInfo &info ); + + public: private: Modified: trunk/libzypp/zypp/RepoStatus.cc URL: http://svn.opensuse.org/viewcvs/zypp/trunk/libzypp/zypp/RepoStatus.cc?rev=5772&r1=5771&r2=5772&view=diff ============================================================================== --- trunk/libzypp/zypp/RepoStatus.cc (original) +++ trunk/libzypp/zypp/RepoStatus.cc Mon Jun 18 18:05:43 2007 @@ -12,7 +12,7 @@ #include <iostream> //#include "zypp/base/Logger.h" #include "zypp/RepoStatus.h" - +#include "zypp/PathInfo.h" using namespace std; @@ -66,7 +66,7 @@ // METHOD TYPE : Ctor // RepoStatus::RepoStatus() - : _pimpl( Impl::nullimpl() ) + : _pimpl( new Impl() ) {} /////////////////////////////////////////////////////////////////// @@ -77,6 +77,11 @@ RepoStatus::~RepoStatus() {} + RepoStatus::RepoStatus( const Pathname &path ) + { + _pimpl->checksum = filesystem::sha1sum(path); + } + 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=5772&r1=5771&r2=5772&view=diff ============================================================================== --- trunk/libzypp/zypp/RepoStatus.h (original) +++ trunk/libzypp/zypp/RepoStatus.h Mon Jun 18 18:05:43 2007 @@ -73,6 +73,15 @@ public: /** Default ctor */ RepoStatus(); + + /** + * \short Status from a single file + * As most repository state is represented + * by the status of the index file, you can + * construct the status from a file. + */ + RepoStatus( const Pathname &file ); + /** Dtor */ ~RepoStatus(); Modified: trunk/libzypp/zypp/cache/CacheStore.cc URL: http://svn.opensuse.org/viewcvs/zypp/trunk/libzypp/zypp/cache/CacheStore.cc?rev=5772&r1=5771&r2=5772&view=diff ============================================================================== --- trunk/libzypp/zypp/cache/CacheStore.cc (original) +++ trunk/libzypp/zypp/cache/CacheStore.cc Mon Jun 18 18:05:43 2007 @@ -717,8 +717,8 @@ } void CacheStore::updateRepository( const RecordId &id, - const string &checksum, - const Date ×tamp ) + const string &checksum, + const Date ×tamp ) { _pimpl->update_repository_cmd->bind(":repository_id", id); _pimpl->update_repository_cmd->bind(":checksum", checksum); @@ -782,7 +782,7 @@ { sqlite3_reader reader = cmd.executereader(); RepoStatus status; - while ( reader.read() ) + if ( reader.read() ) { status.setChecksum( reader.getstring(2) ); status.setTimestamp( reader.getstring(3) ); Modified: trunk/libzypp/zypp/parser/IniDict.cc URL: http://svn.opensuse.org/viewcvs/zypp/trunk/libzypp/zypp/parser/IniDict.cc?rev=5772&r1=5771&r2=5772&view=diff ============================================================================== --- trunk/libzypp/zypp/parser/IniDict.cc (original) +++ trunk/libzypp/zypp/parser/IniDict.cc Mon Jun 18 18:05:43 2007 @@ -91,7 +91,19 @@ { return make_map_key_end( _dict ); } + + void IniDict::insertEntry( const std::string §ion, + const std::string &key, + const std::string &value ) + { + consume( section, key, value ); + } + void IniDict::deleteSection( const std::string §ion ) + { + _dict.erase(section); + } + /****************************************************************** ** ** FUNCTION NAME : operator<< @@ -99,6 +111,19 @@ */ std::ostream & operator<<( std::ostream & str, const IniDict & obj ) { + for ( IniDict::section_const_iterator si = obj.sectionsBegin(); + si != obj.sectionsEnd(); + ++si ) + { + str << "[" << *si << "]" << endl; + for ( IniDict::entry_const_iterator ei = obj.entriesBegin(*si); + ei != obj.entriesEnd(*si); + ++ei ) + { + str << ei->first << " = " << ei->second << endl; + } + str << endl; + } return str; } Modified: trunk/libzypp/zypp/parser/IniDict.h URL: http://svn.opensuse.org/viewcvs/zypp/trunk/libzypp/zypp/parser/IniDict.h?rev=5772&r1=5771&r2=5772&view=diff ============================================================================== --- trunk/libzypp/zypp/parser/IniDict.h (original) +++ trunk/libzypp/zypp/parser/IniDict.h Mon Jun 18 18:05:43 2007 @@ -85,21 +85,41 @@ * Creates a dictionary from a InputStream * containing a ini structured file */ - IniDict( const InputStream &is, const ProgressData::ReceiverFnc & progress = ProgressData::ReceiverFnc() ); + IniDict( const InputStream &is, + const ProgressData::ReceiverFnc & progress = ProgressData::ReceiverFnc() ); /** Dtor */ ~IniDict(); + /** + * \short add an entry + * \param section + * \param key + * \param value + */ + void insertEntry( const std::string §ion, + const std::string &key, + const std::string &value ); + + /** + * \short add an entry + * \param section + * \param key + * \param value + */ + void deleteSection( const std::string §ion ); + public: /** Called when a section is found. */ virtual void consume( const std::string §ion ); /** Called when a key value is found. */ - virtual void consume( const std::string §ion, const std::string &key, const std::string &value ); + virtual void consume( const std::string §ion, + const std::string &key, + const std::string &value ); private: SectionSet _dict; - /** * empty map used to simulate * iteration in non existant Modified: trunk/libzypp/zypp/parser/RepoFileReader.cc URL: http://svn.opensuse.org/viewcvs/zypp/trunk/libzypp/zypp/parser/RepoFileReader.cc?rev=5772&r1=5771&r2=5772&view=diff ============================================================================== --- trunk/libzypp/zypp/parser/RepoFileReader.cc (original) +++ trunk/libzypp/zypp/parser/RepoFileReader.cc Mon Jun 18 18:05:43 2007 @@ -61,7 +61,7 @@ else if ( it->first == "type" ) info.setType(repo::RepoType(it->second)); } - + info.setFilepath(file); // add it to the list. callback(info); //if (!progress.tick()) Modified: trunk/libzypp/zypp/repo/susetags/Downloader.cc URL: http://svn.opensuse.org/viewcvs/zypp/trunk/libzypp/zypp/repo/susetags/Downloader.cc?rev=5772&r1=5771&r2=5772&view=diff ============================================================================== --- trunk/libzypp/zypp/repo/susetags/Downloader.cc (original) +++ trunk/libzypp/zypp/repo/susetags/Downloader.cc Mon Jun 18 18:05:43 2007 @@ -23,6 +23,13 @@ } +RepoStatus Downloader::status() +{ + MediaSetAccess media(_url, _path); + Pathname content = media.provideFile("/content"); + return RepoStatus(content); +} + void Downloader::download( const Pathname &dest_dir, const ProgressData::ReceiverFnc & progress ) { Modified: trunk/libzypp/zypp/repo/susetags/Downloader.h URL: http://svn.opensuse.org/viewcvs/zypp/trunk/libzypp/zypp/repo/susetags/Downloader.h?rev=5772&r1=5771&r2=5772&view=diff ============================================================================== --- trunk/libzypp/zypp/repo/susetags/Downloader.h (original) +++ trunk/libzypp/zypp/repo/susetags/Downloader.h Mon Jun 18 18:05:43 2007 @@ -13,6 +13,7 @@ #include "zypp/Url.h" #include "zypp/Pathname.h" #include "zypp/ProgressData.h" +#include "zypp/RepoStatus.h" namespace zypp { @@ -27,6 +28,10 @@ Downloader( const Url &url, const Pathname &path ); void download( const Pathname &dest_dir, const ProgressData::ReceiverFnc & progress = ProgressData::ReceiverFnc() ); + /** + * \short Status of the remote repository + */ + RepoStatus status(); private: Url _url; Pathname _path; Modified: trunk/libzypp/zypp/repo/yum/Downloader.cc URL: http://svn.opensuse.org/viewcvs/zypp/trunk/libzypp/zypp/repo/yum/Downloader.cc?rev=5772&r1=5771&r2=5772&view=diff ============================================================================== --- trunk/libzypp/zypp/repo/yum/Downloader.cc (original) +++ trunk/libzypp/zypp/repo/yum/Downloader.cc Mon Jun 18 18:05:43 2007 @@ -35,6 +35,12 @@ { } +RepoStatus Downloader::status() +{ + Pathname repomd = _media.provideFile("/repodata/repomd.xml"); + return RepoStatus(repomd); +} + bool Downloader::patches_Callback( const OnMediaLocation &loc, const string &id ) { MIL << id << " : " << loc << endl; Modified: trunk/libzypp/zypp/repo/yum/Downloader.h URL: http://svn.opensuse.org/viewcvs/zypp/trunk/libzypp/zypp/repo/yum/Downloader.h?rev=5772&r1=5771&r2=5772&view=diff ============================================================================== --- trunk/libzypp/zypp/repo/yum/Downloader.h (original) +++ trunk/libzypp/zypp/repo/yum/Downloader.h Mon Jun 18 18:05:43 2007 @@ -18,6 +18,7 @@ #include "zypp/parser/xml/Reader.h" #include "zypp/repo/yum/ResourceType.h" #include "zypp/ProgressData.h" +#include "zypp/RepoStatus.h" namespace zypp { @@ -48,6 +49,11 @@ void download( const Pathname &dest_dir, const ProgressData::ReceiverFnc & progress = ProgressData::ReceiverFnc() ); + /** + * \short Status of the remote repository + */ + RepoStatus status(); + protected: bool repomd_Callback( const OnMediaLocation &loc, const ResourceType &dtype ); bool patches_Callback( const OnMediaLocation &loc, const std::string &id ); -- To unsubscribe, e-mail: zypp-commit+unsubscribe@opensuse.org For additional commands, e-mail: zypp-commit+help@opensuse.org