Author: mlandres Date: Tue Jun 26 11:29:40 2007 New Revision: 5842 URL: http://svn.opensuse.org/viewcvs/zypp?rev=5842&view=rev Log: Fixes to autoprobing and path to Url consversion Modified: branches/REFACTORING-10_3/libzypp/zypp/RepoManager.cc Modified: branches/REFACTORING-10_3/libzypp/zypp/RepoManager.cc URL: http://svn.opensuse.org/viewcvs/zypp/branches/REFACTORING-10_3/libzypp/zypp/RepoManager.cc?rev=5842&r1=5841&r2=5842&view=diff ============================================================================== --- branches/REFACTORING-10_3/libzypp/zypp/RepoManager.cc (original) +++ branches/REFACTORING-10_3/libzypp/zypp/RepoManager.cc Tue Jun 26 11:29:40 2007 @@ -51,7 +51,7 @@ // CLASS NAME : RepoManagerOptions // /////////////////////////////////////////////////////////////////// - + RepoManagerOptions::RepoManagerOptions() { ZConfig globalConfig; @@ -78,12 +78,12 @@ { MIL << endl; } - + ~RepoCollector() { MIL << endl; } - + bool collect( const RepoInfo &repo ) { //MIL << "here in collector: " << repo.alias() << endl; @@ -91,12 +91,12 @@ //MIL << "added: " << repo.alias() << endl; return true; } - + RepoInfoList repos; }; - + //////////////////////////////////////////////////////////////////////////// - + /** * Reads RepoInfo's from a repo file. * @@ -115,20 +115,20 @@ std::list<RepoInfo> readRepoFile(const Url & repo_file) { // no interface to download a specific file, using workaround: - //! \todo add MediaManager::provideFile(Url file_url) to easily access any file URLs? (no need for media access id or media_nr) + //! \todo add MediaManager::provideFile(Url file_url) to easily access any file URLs? (no need for media access id or media_nr) Url url(repo_file); Pathname path(url.getPathName()); url.setPathName ("/"); MediaSetAccess access(url); Pathname local = access.provideFile(path); - + DBG << "reading repo file " << repo_file << ", local path: " << local << endl; - + return repositories_in_file(local); } //////////////////////////////////////////////////////////////////////////// - + /** * \short List of RepoInfo's from a directory * @@ -144,10 +144,10 @@ list<Pathname> entries; if ( filesystem::readdir( entries, Pathname(dir), false ) != 0 ) ZYPP_THROW(Exception("failed to read directory")); - + for ( list<Pathname>::const_iterator it = entries.begin(); it != entries.end(); ++it ) { - list<RepoInfo> tmp = repositories_in_file( *it ); + list<RepoInfo> tmp = repositories_in_file( *it ); repos.insert( repos.end(), tmp.begin(), tmp.end() ); //std::copy( collector.repos.begin(), collector.repos.end(), std::back_inserter(repos)); @@ -157,23 +157,23 @@ } //////////////////////////////////////////////////////////////////////////// - + static void assert_alias( const RepoInfo &info ) { if (info.alias().empty()) ZYPP_THROW(RepoNoAliasException()); } - + //////////////////////////////////////////////////////////////////////////// - + static void assert_urls( const RepoInfo &info ) { if (info.baseUrls().empty()) ZYPP_THROW(RepoNoUrlException()); } - + //////////////////////////////////////////////////////////////////////////// - + /** * \short Calculates the raw cache path for a repository */ @@ -188,7 +188,7 @@ // CLASS NAME : RepoManager::Impl // /////////////////////////////////////////////////////////////////// - + /** * \short RepoManager implementation. */ @@ -197,16 +197,16 @@ Impl( const RepoManagerOptions &opt ) : options(opt) { - + } - + Impl() { - + } - + RepoManagerOptions options; - + public: /** Offer default Impl. */ static shared_ptr<Impl> nullimpl() @@ -240,10 +240,10 @@ {} //////////////////////////////////////////////////////////////////////////// - + RepoManager::~RepoManager() {} - + //////////////////////////////////////////////////////////////////////////// std::list<RepoInfo> RepoManager::knownRepositories() const @@ -254,22 +254,23 @@ } //////////////////////////////////////////////////////////////////////////// - + RepoStatus RepoManager::rawMetadataStatus( const RepoInfo &info ) { Pathname rawpath = rawcache_path_for_repoinfo( _pimpl->options, info ); RepoType repokind = info.type(); RepoStatus status; + switch ( repokind.toEnum() ) { case RepoType::NONE_e: // unknown, probe the local metadata - repokind = probe(Url(rawpath.asString())); + repokind = probe(rawpath.asUrl()); break; default: break; } - + switch ( repokind.toEnum() ) { case RepoType::RPMMD_e : @@ -277,6 +278,7 @@ status = RepoStatus( rawpath + "/repodata/repomd.xml"); } break; + case RepoType::YAST2_e : { status = RepoStatus( rawpath + "/content"); @@ -284,23 +286,27 @@ case RepoType::RPMPLAINDIR_e : { if ( PathInfo(Pathname(rawpath + "/cookie")).isExist() ) - status = RepoStatus( rawpath + "/content"); + status = RepoStatus( rawpath + "/cookie"); } break; - default: - ZYPP_THROW(RepoUnknownTypeException()); + + case RepoType::NONE_e : + // Return default RepoStatus in case of RepoType::NONE + // indicating it should be created? + // ZYPP_THROW(RepoUnknownTypeException()); + break; } return status; } - - + + void RepoManager::refreshMetadata( const RepoInfo &info, RawMetadataRefreshPolicy policy, const ProgressData::ReceiverFnc & progress ) { assert_alias(info); assert_urls(info); - + RepoStatus oldstatus; RepoStatus newstatus; // try urls one by one @@ -310,9 +316,9 @@ { Url url(*it); filesystem::TmpDir tmpdir; - + repo::RepoType repokind = info.type(); - + // if the type is unknown, try probing. switch ( repokind.toEnum() ) { @@ -323,16 +329,16 @@ default: break; } - + Pathname rawpath = rawcache_path_for_repoinfo( _pimpl->options, info ); oldstatus = rawMetadataStatus(info); - + switch ( repokind.toEnum() ) { case RepoType::RPMMD_e : { yum::Downloader downloader( url, "/" ); - + RepoStatus newstatus = downloader.status(); bool refresh = false; if ( oldstatus.checksum() == newstatus.checksum() ) @@ -348,7 +354,7 @@ { refresh = true; } - + if ( refresh ) downloader.download(tmpdir.path()); else @@ -359,7 +365,7 @@ case RepoType::YAST2_e : { susetags::Downloader downloader( url, "/" ); - + RepoStatus newstatus = downloader.status(); bool refresh = false; if ( oldstatus.checksum() == newstatus.checksum() ) @@ -375,7 +381,7 @@ { refresh = true; } - + if ( refresh ) downloader.download(tmpdir.path()); else @@ -399,7 +405,7 @@ { refresh = true; } - + if ( refresh ) { std::ofstream file(( tmpdir.path() + "/cookie").c_str()); @@ -408,7 +414,7 @@ } file << url << endl; file << newstatus.checksum() << endl; - + file.close(); } else @@ -419,7 +425,7 @@ default: ZYPP_THROW(RepoUnknownTypeException()); } - + // ok we have the metadata, now exchange // the contents TmpDir oldmetadata; @@ -439,17 +445,17 @@ ERR << "No more urls..." << endl; ZYPP_THROW(RepoException("Cant refresh metadata")); } - + //////////////////////////////////////////////////////////////////////////// - + void RepoManager::cleanMetadata( const RepoInfo &info, const ProgressData::ReceiverFnc & progress ) { filesystem::recursive_rmdir(rawcache_path_for_repoinfo(_pimpl->options, info)); } - + //////////////////////////////////////////////////////////////////////////// - + void RepoManager::buildCache( const RepoInfo &info, CacheBuildPolicy policy, const ProgressData::ReceiverFnc & progressrcv ) @@ -459,9 +465,9 @@ progress.toMin(); assert_alias(info); Pathname rawpath = rawcache_path_for_repoinfo(_pimpl->options, info); - + cache::CacheStore store(_pimpl->options.repoCachePath); - + RepoStatus raw_metadata_status = rawMetadataStatus(info); if ( store.isCached( info.alias() ) ) { @@ -477,27 +483,28 @@ return; } else { - MIL << "Build cache is forced" << endl; + MIL << info.alias() << " cache rebuild is forced" << endl; } } store.cleanRepository(id); } - + + MIL << info.alias() << " building cache..." << endl; data::RecordId id = store.lookupOrAppendRepository(info.alias()); // do we have type? repo::RepoType repokind = info.type(); - + // if the type is unknown, try probing. switch ( repokind.toEnum() ) { case RepoType::NONE_e: // unknown, probe the local metadata - repokind = probe(Url(rawpath.asString())); + repokind = probe(rawpath.asUrl()); break; default: break; } - + switch ( repokind.toEnum() ) { case RepoType::RPMMD_e : @@ -526,25 +533,32 @@ default: ZYPP_THROW(RepoUnknownTypeException()); } - + // update timestamp and checksum store.updateRepositoryStatus(id, raw_metadata_status); - + MIL << "Commit cache.." << endl; store.commit(); progress.toMax(); } - + //////////////////////////////////////////////////////////////////////////// - + repo::RepoType RepoManager::probe( const Url &url ) { + if ( url.getScheme() == "dir" && ! PathInfo( url.getPathName() ).isDir() ) + { + // Handle non existing local directory in advance, as + // MediaSetAccess does not support it. + return repo::RepoType::NONE; + } + MediaSetAccess access(url); if ( access.doesFileExist("/repodata/repomd.xml") ) return repo::RepoType::RPMMD; if ( access.doesFileExist("/content") ) return repo::RepoType::YAST2; - + // if it is a local url of type dir if ( (! media::MediaManager::downloads(url)) && ( url.getScheme() == "dir" ) ) { @@ -555,12 +569,12 @@ return repo::RepoType::RPMPLAINDIR; } } - - return repo::RepoType("UNKNOWN"); + + return repo::RepoType::NONE; } - + //////////////////////////////////////////////////////////////////////////// - + void RepoManager::cleanCache( const RepoInfo &info, const ProgressData::ReceiverFnc & progressrcv ) { @@ -573,25 +587,25 @@ store.cleanRepository(id); store.commit(); } - + //////////////////////////////////////////////////////////////////////////// - + bool RepoManager::isCached( const RepoInfo &info ) const { cache::CacheStore store(_pimpl->options.repoCachePath); return store.isCached(info.alias()); } - + Repository RepoManager::createFromCache( const RepoInfo &info, const ProgressData::ReceiverFnc & progress ) { cache::CacheStore store(_pimpl->options.repoCachePath); - + if ( ! store.isCached( info.alias() ) ) ZYPP_THROW(RepoNotCachedException()); - + MIL << "Repository " << info.alias() << " is cached" << endl; - + data::RecordId id = store.lookupRepository(info.alias()); repo::cached::RepoImpl::Ptr repoimpl = new repo::cached::RepoImpl( info, _pimpl->options.repoCachePath, id ); @@ -599,9 +613,9 @@ repoimpl->createResolvables(); return Repository(repoimpl); } - + //////////////////////////////////////////////////////////////////////////// - + /** * Generate a non existing filename in a directory, using a base * name. For example if a directory contains 3 files @@ -610,7 +624,7 @@ * |-- foo * `-- moo * - * If you try to generate a unique filename for this directory, + * If you try to generate a unique filename for this directory, * based on "ruu" you will get "ruu", but if you use the base * "foo" you will get "foo_1" * @@ -629,14 +643,14 @@ } return dir + Pathname(final_filename); } - + //////////////////////////////////////////////////////////////////////////// void RepoManager::addRepository( const RepoInfo &info, const ProgressData::ReceiverFnc & progressrcv ) { assert_alias(info); - + std::list<RepoInfo> repos = knownRepositories(); for ( std::list<RepoInfo>::const_iterator it = repos.begin(); it != repos.end(); @@ -645,21 +659,21 @@ if ( info.alias() == (*it).alias() ) ZYPP_THROW(RepoAlreadyExistsException(info.alias())); } - + Pathname repofile = generate_non_existing_name(_pimpl->options.knownReposPath, Pathname(info.alias()).extend(".repo").asString()); // now we have a filename that does not exists MIL << "Saving repo in " << repofile << endl; - + std::ofstream file(repofile.c_str()); if (!file) { ZYPP_THROW (Exception( "Can't open " + repofile.asString() ) ); } - + info.dumpRepoOn(file); MIL << "done" << endl; } - + void RepoManager::addRepositories( const Url &url, const ProgressData::ReceiverFnc & progressrcv ) { @@ -681,21 +695,21 @@ } } } - + string filename = Pathname(url.getPathName()).basename(); - + if ( filename == Pathname() ) ZYPP_THROW(RepoException("Invalid repo file name at " + url.asString() )); - + Pathname repofile = generate_non_existing_name(_pimpl->options.knownReposPath, filename); // now we have a filename that does not exists MIL << "Saving " << repos.size() << " repo" << ( repos.size() ? "s" : "" ) << " in " << repofile << endl; - + std::ofstream file(repofile.c_str()); if (!file) { ZYPP_THROW (Exception( "Can't open " + repofile.asString() ) ); } - + for ( std::list<RepoInfo>::const_iterator it = repos.begin(); it != repos.end(); ++it ) @@ -705,9 +719,9 @@ } MIL << "done" << endl; } - + //////////////////////////////////////////////////////////////////////////// - + void RepoManager::removeRepository( const RepoInfo & info, const ProgressData::ReceiverFnc & progressrcv) { @@ -721,9 +735,9 @@ // 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. RepoInfo todelete = *it; @@ -762,31 +776,31 @@ if ( (*fit).alias() != todelete.alias() ) (*fit).dumpRepoOn(file); } - + cache::CacheStore store(_pimpl->options.repoCachePath); - + if ( store.isCached( todelete.alias() ) ) { MIL << "repository was cached. cleaning cache" << endl; store.cleanRepository(todelete.alias()); } - + return; } } // else filepath is empty - + } // should not be reached on a sucess workflow ZYPP_THROW(RepoNotFoundException(info)); } - + //////////////////////////////////////////////////////////////////////////// - + void RepoManager::modifyRepository( const std::string &alias, const RepoInfo & newinfo, const ProgressData::ReceiverFnc & progressrcv ) { RepoInfo toedit = getRepositoryInfo(alias); - + if (toedit.filepath().empty()) { ZYPP_THROW(RepoException("Can't figure where the repo is stored")); @@ -818,9 +832,9 @@ } } } - + //////////////////////////////////////////////////////////////////////////// - + RepoInfo RepoManager::getRepositoryInfo( const std::string &alias, const ProgressData::ReceiverFnc & progressrcv ) { @@ -836,9 +850,9 @@ info.setAlias(info.alias()); ZYPP_THROW(RepoNotFoundException(info)); } - + //////////////////////////////////////////////////////////////////////////// - + std::ostream & operator<<( std::ostream & str, const RepoManager & obj ) { return str << *obj._pimpl; -- To unsubscribe, e-mail: zypp-commit+unsubscribe@opensuse.org For additional commands, e-mail: zypp-commit+help@opensuse.org