Author: dmacvicar Date: Tue Jun 19 15:23:33 2007 New Revision: 5787 URL: http://svn.opensuse.org/viewcvs/zypp?rev=5787&view=rev Log: - repo deletion, test does not passes, still fixing Added: trunk/libzypp/tests/zypp/data/RepoManager/proprietary.repo trunk/libzypp/tests/zypp/data/RepoManager/repos.d/proprietary.repo Modified: trunk/libzypp/tests/zypp/RepoManager_test.cc trunk/libzypp/zypp/RepoManager.cc trunk/libzypp/zypp/RepoManager.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=5787&r1=5786&r2=5787&view=diff ============================================================================== --- trunk/libzypp/tests/zypp/RepoManager_test.cc (original) +++ trunk/libzypp/tests/zypp/RepoManager_test.cc Tue Jun 19 15:23:33 2007 @@ -34,16 +34,51 @@ TmpDir tmpCachePath; TmpDir tmpRawCachePath; + TmpDir tmpKnownReposPath; + + BOOST_CHECK_EQUAL( filesystem::copy_dir_content( Pathname(dir) + "/repos.d", tmpKnownReposPath.path() ), 0 ); opts.repoCachePath = tmpCachePath.path(); opts.repoRawCachePath = tmpRawCachePath.path(); - opts.knownReposPath = Pathname(dir) + "/repos.d"; + opts.knownReposPath = tmpKnownReposPath.path(); RepoManager manager(opts); list<RepoInfo> repos = manager.knownRepositories(); + BOOST_CHECK_EQUAL(repos.size(), (unsigned) 4); + + // now add a .repo file with 2 repositories in it + Url url; + url.setPathName((Pathname(dir) + "/proprietary.repo").asString()); + url.setScheme("file"); + + manager.addRepositories(url); + + // check it was not overwriten the proprietary.repo file + BOOST_CHECK( PathInfo(Pathname(dir) + "/repos.d/proprietary_1.repo").isExist() ); - BOOST_CHECK_EQUAL(repos.size(), (unsigned) 3); + // now there should be 6 repos + repos = manager.knownRepositories(); + BOOST_CHECK_EQUAL(repos.size(), (unsigned) 6); + + // delete the office repo inside the propietary_1.repo + RepoInfo office; + office.setAlias("office"); + manager.removeRepository(office); + // now there should be 5 repos + repos = manager.knownRepositories(); + BOOST_CHECK_EQUAL(repos.size(), (unsigned) 5); + // the file still contained one repo, so it should still exists + BOOST_CHECK( PathInfo(Pathname(dir) + "/repos.d/proprietary_1.repo").isExist() ); + + // now delete the macromedia one + RepoInfo macromedia; + macromedia.setAlias("macromedia"); + manager.removeRepository(macromedia); + repos = manager.knownRepositories(); + BOOST_CHECK_EQUAL(repos.size(), (unsigned) 4); + // the file should not exist anymore + BOOST_CHECK( ! PathInfo(Pathname(dir) + "/repos.d/proprietary_1.repo").isExist() ); RepoInfo repo(repos.front()); manager.refreshMetadata(repo); Added: trunk/libzypp/tests/zypp/data/RepoManager/proprietary.repo URL: http://svn.opensuse.org/viewcvs/zypp/trunk/libzypp/tests/zypp/data/RepoManager/proprietary.repo?rev=5787&view=auto ============================================================================== --- trunk/libzypp/tests/zypp/data/RepoManager/proprietary.repo (added) +++ trunk/libzypp/tests/zypp/data/RepoManager/proprietary.repo Tue Jun 19 15:23:33 2007 @@ -0,0 +1,14 @@ +[macromedia] +name=Macromedia for i386 Linux +baseurl=http://macromedia.rediris.es/rpm/ +enabled=1 +gpgcheck=1 +gpgkey=http://macromedia.mplug.org/FEDORA-GPG-KEY + +[office] +name=Microsoft Office for Linux +baseurl=http://www.microsoft.com/linux/office +enabled=1 +gpgcheck=1 +gpgkey=http://www.microsoft.com/~sballmer/gpgkey.txt + Added: trunk/libzypp/tests/zypp/data/RepoManager/repos.d/proprietary.repo URL: http://svn.opensuse.org/viewcvs/zypp/trunk/libzypp/tests/zypp/data/RepoManager/repos.d/proprietary.repo?rev=5787&view=auto ============================================================================== --- trunk/libzypp/tests/zypp/data/RepoManager/repos.d/proprietary.repo (added) +++ trunk/libzypp/tests/zypp/data/RepoManager/repos.d/proprietary.repo Tue Jun 19 15:23:33 2007 @@ -0,0 +1,5 @@ + +[adobe] +name=acrobat reader +baseurl=http://www.adobe.com/reader/linux + Modified: trunk/libzypp/zypp/RepoManager.cc URL: http://svn.opensuse.org/viewcvs/zypp/trunk/libzypp/zypp/RepoManager.cc?rev=5787&r1=5786&r2=5787&view=diff ============================================================================== --- trunk/libzypp/zypp/RepoManager.cc (original) +++ trunk/libzypp/zypp/RepoManager.cc Tue Jun 19 15:23:33 2007 @@ -248,7 +248,7 @@ std::list<RepoInfo> RepoManager::knownRepositories() const { MIL << endl; - return repositories_in_dir("/etc/zypp/repos.d"); + return repositories_in_dir(_pimpl->options.knownReposPath); MIL << endl; } @@ -300,95 +300,105 @@ // try urls one by one for ( RepoInfo::urls_const_iterator it = info.baseUrlsBegin(); it != info.baseUrlsEnd(); ++it ) { - Url url(*it); - filesystem::TmpDir tmpdir; - - repo::RepoType repokind = info.type(); - - // if the type is unknown, try probing. - switch ( repokind.toEnum() ) - { - case RepoType::NONE_e: - // unknown, probe it - repokind = probe(*it); - break; - default: - break; - } - - Pathname rawpath = rawcache_path_for_repoinfo( _pimpl->options, info ); - oldstatus = rawMetadataStatus(info); - - switch ( repokind.toEnum() ) + try { - case RepoType::RPMMD_e : + Url url(*it); + filesystem::TmpDir tmpdir; + + repo::RepoType repokind = info.type(); + + // if the type is unknown, try probing. + switch ( repokind.toEnum() ) { - yum::Downloader downloader( url, "/" ); - - RepoStatus newstatus = downloader.status(); - bool refresh = false; - if ( oldstatus.checksum() == newstatus.checksum() ) + case RepoType::NONE_e: + // unknown, probe it + repokind = probe(*it); + break; + default: + break; + } + + Pathname rawpath = rawcache_path_for_repoinfo( _pimpl->options, info ); + oldstatus = rawMetadataStatus(info); + + switch ( repokind.toEnum() ) + { + case RepoType::RPMMD_e : { - MIL << "repo has not changed" << endl; - if ( policy == RefreshForced ) + yum::Downloader downloader( url, "/" ); + + 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; + } + } + else { - MIL << "refresh set to forced" << endl; refresh = true; } + + if ( refresh ) + downloader.download(tmpdir.path()); + else + return; + // no error } - else - { - refresh = true; - } - - if ( refresh ) - downloader.download(tmpdir.path()); - else - return; - // no error - } - break; - case RepoType::YAST2_e : - { - susetags::Downloader downloader( url, "/" ); - - RepoStatus newstatus = downloader.status(); - bool refresh = false; - if ( oldstatus.checksum() == newstatus.checksum() ) + break; + case RepoType::YAST2_e : { - MIL << "repo has not changed" << endl; - if ( policy == RefreshForced ) + susetags::Downloader downloader( url, "/" ); + + 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; + } + } + else { - MIL << "refresh set to forced" << endl; refresh = true; } + + if ( refresh ) + downloader.download(tmpdir.path()); + else + return; + // no error } - else - { - refresh = true; - } - - if ( refresh ) - downloader.download(tmpdir.path()); - else - return; - // no error + break; + default: + ZYPP_THROW(RepoUnknownTypeException()); } - break; - default: - ZYPP_THROW(RepoUnknownTypeException()); + + // ok we have the metadata, now exchange + // the contents + TmpDir oldmetadata; + filesystem::assert_dir(rawpath); + filesystem::rename( rawpath, oldmetadata.path() ); + // move the just downloaded there + filesystem::rename( tmpdir.path(), rawpath ); + // we are done. + return; } - - // ok we have the metadata, now exchange - // the contents - TmpDir oldmetadata; - filesystem::assert_dir(rawpath); - filesystem::rename( rawpath, oldmetadata.path() ); - // move the just downloaded there - filesystem::rename( tmpdir.path(), rawpath ); - - // we are done. - } + catch ( const Exception &e ) + { + ZYPP_CAUGHT(e); + ERR << "Trying another url..." << endl; + } + } // for every url + ERR << "No more urls..." << endl; + ZYPP_THROW(RepoException("Cant refresh metadata")); } //////////////////////////////////////////////////////////////////////////// @@ -601,11 +611,14 @@ { // look if the alias is in the known repos. for ( std::list<RepoInfo>::const_iterator kit = knownrepos.begin(); - kit != repos.end(); + kit != knownrepos.end(); ++kit ) { if ( (*it).alias() == (*kit).alias() ) + { + ERR << "To be added repo " << (*it).alias() << " conflicts with existing repo " << (*kit).alias() << endl; ZYPP_THROW(RepoAlreadyExistsException((*it).alias())); + } } } @@ -635,6 +648,68 @@ //////////////////////////////////////////////////////////////////////////// + void RepoManager::removeRepository( const RepoInfo & info, + const ProgressData::ReceiverFnc & progressrcv) + { + std::list<RepoInfo> repos = knownRepositories(); + for ( std::list<RepoInfo>::const_iterator it = repos.begin(); + it != repos.end(); + ++it ) + { + // they can be the same only if the provided is empty, that means + // the provided repo has no alias + // then skip + if ( (!info.alias().empty()) && ( info.alias() != (*it).alias() ) ) + continue; + + // TODO match by url + + // we have a matcing repository, now we need to know + // where it does come from. + if (info.filepath().empty()) + { + ZYPP_THROW(RepoException("Can't figure where the repo is stored")); + } + else + { + // figure how many repos are there in the file: + std::list<RepoInfo> filerepos = repositories_in_file(info.filepath()); + if ( (filerepos.size() == 1) && ( filerepos.front().alias() == info.alias() ) ) + { + // easy, only this one, just delete the file + if ( filesystem::unlink(info.filepath()) != 0 ) + { + ZYPP_THROW(RepoException("Can't delete " + info.filepath().asString())); + } + return; + } + else + { + // there are more repos in the same file + // write them back except the deleted one. + TmpFile tmp; + std::ofstream file(tmp.path().c_str()); + if (!file) { + ZYPP_THROW (Exception( "Can't open " + tmp.path().asString() ) ); + } + for ( std::list<RepoInfo>::const_iterator fit = filerepos.begin(); + fit != filerepos.end(); + ++fit ) + { + if ( (*fit).alias() != info.alias() ) + (*fit).dumpRepoOn(file); + } + return; + } + } // else filepath is empty + + } + // should not be reached on a sucess workflow + ZYPP_THROW(RepoNotFoundException(info)); + } + + //////////////////////////////////////////////////////////////////////////// + std::ostream & operator<<( std::ostream & str, const RepoManager & obj ) { return str << *obj._pimpl; Modified: trunk/libzypp/zypp/RepoManager.h URL: http://svn.opensuse.org/viewcvs/zypp/trunk/libzypp/zypp/RepoManager.h?rev=5787&r1=5786&r2=5787&view=diff ============================================================================== --- trunk/libzypp/zypp/RepoManager.h (original) +++ trunk/libzypp/zypp/RepoManager.h Tue Jun 19 15:23:33 2007 @@ -86,8 +86,9 @@ BuildForced }; - enum RepoAddPolicy + enum RepoRemovePolicy { + }; /** @@ -209,9 +210,11 @@ void addRepositories( const Url &url, const ProgressData::ReceiverFnc & progressrcv = ProgressData::ReceiverFnc() ); /** - * PROPOSAL + * \short Remove the best matching repository from known repos list + * + * \throws RepoNotFoundException If no repo match */ - void removeRepository( const std::string & alias, + void removeRepository( const RepoInfo & info, const ProgressData::ReceiverFnc & progressrcv = ProgressData::ReceiverFnc() ); protected: Modified: trunk/libzypp/zypp/repo/RepoException.h URL: http://svn.opensuse.org/viewcvs/zypp/trunk/libzypp/zypp/repo/RepoException.h?rev=5787&r1=5786&r2=5787&view=diff ============================================================================== --- trunk/libzypp/zypp/repo/RepoException.h (original) +++ trunk/libzypp/zypp/repo/RepoException.h Tue Jun 19 15:23:33 2007 @@ -17,7 +17,7 @@ #include "zypp/base/Exception.h" #include "zypp/base/UserRequestException.h" - +#include "zypp/RepoInfo.h" /////////////////////////////////////////////////////////////////// namespace zypp { ///////////////////////////////////////////////////////////////// @@ -76,7 +76,17 @@ */ class RepoNotFoundException : public RepoException { - RepoNotFoundException(){} + public: + RepoNotFoundException( const RepoInfo &info) + : _info(info) + {} + ~RepoNotFoundException() throw() + {} + + RepoInfo info() + { return _info; } + private: + RepoInfo _info; }; /** -- To unsubscribe, e-mail: zypp-commit+unsubscribe@opensuse.org For additional commands, e-mail: zypp-commit+help@opensuse.org