From 594f69c5ee9a8844a41bb4a4003aa08b4d12e5b9 Mon Sep 17 00:00:00 2001 From: Duncan Mac-Vicar P Date: Fri, 3 Aug 2007 14:39:19 +0000 Subject: [PATCH] - implement repo.add.probe option --- zypp/RepoManager.cc | 57 ++++++++++++++++++++++++++++++++++------------- zypp/RepoManager.h | 9 ++++++-- zypp/ZConfig.cc | 12 ++++++++++ zypp/ZConfig.h | 7 ++++++ zypp/repo/RepoException.h | 2 +- 5 files changed, 69 insertions(+), 18 deletions(-) diff --git a/zypp/RepoManager.cc b/zypp/RepoManager.cc index 5e639f8..e2a0f35 100644 --- a/zypp/RepoManager.cc +++ b/zypp/RepoManager.cc @@ -575,23 +575,34 @@ namespace zypp 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 @@ namespace zypp 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 @@ namespace zypp ZYPP_THROW (Exception( "Can't open " + repofile.asString() ) ); } - info.dumpRepoOn(file); + tosave.dumpRepoOn(file); progress.toMax(); MIL << "done" << endl; } diff --git a/zypp/RepoManager.h b/zypp/RepoManager.h index 1801efe..d93bb67 100644 --- a/zypp/RepoManager.h +++ b/zypp/RepoManager.h @@ -222,8 +222,11 @@ namespace zypp * * \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 @@ namespace zypp * \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, diff --git a/zypp/ZConfig.cc b/zypp/ZConfig.cc index c2c451e..a31666d 100644 --- a/zypp/ZConfig.cc +++ b/zypp/ZConfig.cc @@ -36,6 +36,7 @@ namespace zypp { public: Impl() + : repo_add_probe(false) { MIL << "ZConfig singleton created." << endl; Pathname confpath("/etc/zypp/zypp.conf"); @@ -80,6 +81,10 @@ namespace zypp { cfg_cache_path = Pathname(value); } + else if ( entry == "repo.add.probe" ) + { + repo_add_probe = (value == "1"); + } } } @@ -99,6 +104,8 @@ namespace zypp Pathname cfg_cache_path; Pathname cfg_known_repos_path; + bool repo_add_probe; + }; /////////////////////////////////////////////////////////////////// @@ -180,6 +187,11 @@ namespace zypp return s; } + bool ZConfig::repo_add_probe() const + { + return _pimpl->repo_add_probe; + } + ///////////////////////////////////////////////////////////////// } // namespace zypp /////////////////////////////////////////////////////////////////// diff --git a/zypp/ZConfig.h b/zypp/ZConfig.h index ec77784..79ef4c0 100644 --- a/zypp/ZConfig.h +++ b/zypp/ZConfig.h @@ -73,6 +73,13 @@ namespace zypp */ 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 */ diff --git a/zypp/repo/RepoException.h b/zypp/repo/RepoException.h index f128753..ab8c6f1 100644 --- a/zypp/repo/RepoException.h +++ b/zypp/repo/RepoException.h @@ -118,7 +118,7 @@ namespace zypp /** * thrown when it was impossible to - * determine an alias for this repo. + * determine this repo type. */ class RepoUnknownTypeException : public RepoException { -- 2.7.4