Author: dmacvicar Date: Fri Aug 3 16:39:19 2007 New Revision: 6451 URL: http://svn.opensuse.org/viewcvs/zypp?rev=6451&view=rev Log: - implement repo.add.probe option Modified: trunk/libzypp/zypp/RepoManager.cc trunk/libzypp/zypp/RepoManager.h trunk/libzypp/zypp/ZConfig.cc trunk/libzypp/zypp/ZConfig.h trunk/libzypp/zypp/repo/RepoException.h Modified: trunk/libzypp/zypp/RepoManager.cc URL: http://svn.opensuse.org/viewcvs/zypp/trunk/libzypp/zypp/RepoManager.cc?rev=6451&r1=6450&r2=6451&view=diff ============================================================================== --- trunk/libzypp/zypp/RepoManager.cc (original) +++ trunk/libzypp/zypp/RepoManager.cc Fri Aug 3 16:39:19 2007 @@ -575,23 +575,34 @@ 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" ) ) + try { - Pathname path = Pathname(url.getPathName()); - if ( PathInfo(path).isDir() ) + 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" ) ) { - // allow empty dirs for now - return repo::RepoType::RPMPLAINDIR; + Pathname path = Pathname(url.getPathName()); + if ( PathInfo(path).isDir() ) + { + // allow empty dirs for now + return repo::RepoType::RPMPLAINDIR; + } } } - + catch ( const media::MediaException &e ) + { + ZYPP_THROW(RepoException("Error trying to read from " + url.asString())); + } + catch ( const Exception &e ) + { + ZYPP_THROW(Exception("Unknown error reading from " + url.asString())); + } + return repo::RepoType::NONE; } @@ -744,13 +755,29 @@ ZYPP_THROW(RepoAlreadyExistsException(info.alias())); } + RepoInfo tosave = info; + + // check the first url for now + if ( ZConfig::instance().repo_add_probe() || ( tosave.type() == RepoType::NONE ) ) + { + RepoType probedtype; + probedtype = probe(*tosave.baseUrlsBegin()); + if ( tosave.baseUrlsSize() > 0 ) + { + if ( probedtype == RepoType::NONE ) + ZYPP_THROW(RepoUnknownTypeException()); + else + tosave.setType(probedtype); + } + } + progress.set(50); // assert the directory exists filesystem::assert_dir(_pimpl->options.knownReposPath); Pathname repofile = generate_non_existing_name(_pimpl->options.knownReposPath, - generate_filename(info)); + generate_filename(tosave)); // now we have a filename that does not exists MIL << "Saving repo in " << repofile << endl; @@ -759,7 +786,7 @@ ZYPP_THROW (Exception( "Can't open " + repofile.asString() ) ); } - info.dumpRepoOn(file); + tosave.dumpRepoOn(file); progress.toMax(); MIL << "done" << endl; } Modified: trunk/libzypp/zypp/RepoManager.h URL: http://svn.opensuse.org/viewcvs/zypp/trunk/libzypp/zypp/RepoManager.h?rev=6451&r1=6450&r2=6451&view=diff ============================================================================== --- trunk/libzypp/zypp/RepoManager.h (original) +++ trunk/libzypp/zypp/RepoManager.h Fri Aug 3 16:39:19 2007 @@ -222,8 +222,11 @@ * * \throws repo::RepoAlreadyExistsException If the repo clash some * unique attribute like alias - * - * \throws RepoAlreadyExistsException + * \throws MediaException If the access to the url fails + * \throws ParseException If the file parsing fails + * \throws RepoUnknownType If repository type can't be determined + * \throws RepoException ON other repository related errors + * \throws Exception On other errors. */ void addRepository( const RepoInfo &info, const ProgressData::ReceiverFnc & progressrcv = ProgressData::ReceiverFnc() ); @@ -238,6 +241,8 @@ * \throws RepoAlreadyExistsException * \throws MediaException If the access to the url fails * \throws ParseException If the file parsing fails + * \throws RepoUnknownType If repository type can't be determined + * \throws RepoException ON other repository related errors * \throws Exception On other errors. */ void addRepositories( const Url &url, Modified: trunk/libzypp/zypp/ZConfig.cc URL: http://svn.opensuse.org/viewcvs/zypp/trunk/libzypp/zypp/ZConfig.cc?rev=6451&r1=6450&r2=6451&view=diff ============================================================================== --- trunk/libzypp/zypp/ZConfig.cc (original) +++ trunk/libzypp/zypp/ZConfig.cc Fri Aug 3 16:39:19 2007 @@ -36,6 +36,7 @@ { public: Impl() + : repo_add_probe(false) { MIL << "ZConfig singleton created." << endl; Pathname confpath("/etc/zypp/zypp.conf"); @@ -80,6 +81,10 @@ { cfg_cache_path = Pathname(value); } + else if ( entry == "repo.add.probe" ) + { + repo_add_probe = (value == "1"); + } } } @@ -99,6 +104,8 @@ Pathname cfg_cache_path; Pathname cfg_known_repos_path; + bool repo_add_probe; + }; /////////////////////////////////////////////////////////////////// @@ -180,6 +187,11 @@ return s; } + bool ZConfig::repo_add_probe() const + { + return _pimpl->repo_add_probe; + } + ///////////////////////////////////////////////////////////////// } // namespace zypp /////////////////////////////////////////////////////////////////// Modified: trunk/libzypp/zypp/ZConfig.h URL: http://svn.opensuse.org/viewcvs/zypp/trunk/libzypp/zypp/ZConfig.h?rev=6451&r1=6450&r2=6451&view=diff ============================================================================== --- trunk/libzypp/zypp/ZConfig.h (original) +++ trunk/libzypp/zypp/ZConfig.h Fri Aug 3 16:39:19 2007 @@ -73,6 +73,13 @@ */ const std::string & cacheDBSplitJoinSeparator() const; + /** + * Whether repository urls should be probed. + / config option + * repo.add.probe + */ + bool repo_add_probe() const; + public: class Impl; /** Dtor */ Modified: trunk/libzypp/zypp/repo/RepoException.h URL: http://svn.opensuse.org/viewcvs/zypp/trunk/libzypp/zypp/repo/RepoException.h?rev=6451&r1=6450&r2=6451&view=diff ============================================================================== --- trunk/libzypp/zypp/repo/RepoException.h (original) +++ trunk/libzypp/zypp/repo/RepoException.h Fri Aug 3 16:39:19 2007 @@ -118,7 +118,7 @@ /** * thrown when it was impossible to - * determine an alias for this repo. + * determine this repo type. */ class RepoUnknownTypeException : public RepoException { -- To unsubscribe, e-mail: zypp-commit+unsubscribe@opensuse.org For additional commands, e-mail: zypp-commit+help@opensuse.org