From: Duncan Mac-Vicar P Date: Wed, 18 Jul 2007 12:17:48 +0000 (+0000) Subject: - allow / in aliases (#292628) X-Git-Tag: BASE-SuSE-Linux-10_3-Branch~545 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=99dc011147321ff6d8f74047898a19248b1b7f42;p=platform%2Fupstream%2Flibzypp.git - allow / in aliases (#292628) --- diff --git a/package/libzypp.changes b/package/libzypp.changes index b239a9d..6e85143 100644 --- a/package/libzypp.changes +++ b/package/libzypp.changes @@ -7,6 +7,11 @@ Wed Jul 18 12:38:55 CEST 2007 - ma@suse.de - revision 6058 ------------------------------------------------------------------- +Wed Jul 18 14:16:59 CEST 2007 - duncan@suse.de + +- allow / in alias (#292628) + +------------------------------------------------------------------- Tue Jul 17 15:57:03 CEST 2007 - ma@suse.de - Fixed OnMediLocation to use safe defaults. Added setLocaltion and diff --git a/tests/zypp/RepoManager_test.cc b/tests/zypp/RepoManager_test.cc index 381bc99..6bd750d 100644 --- a/tests/zypp/RepoManager_test.cc +++ b/tests/zypp/RepoManager_test.cc @@ -62,6 +62,10 @@ void repomanager_test( const string &dir ) repos = manager.knownRepositories(); BOOST_CHECK_EQUAL(repos.size(), (unsigned) 6); + RepoInfo office_dup; + office_dup.setAlias("office"); + BOOST_CHECK_THROW(manager.addRepository(office_dup), RepoAlreadyExistsException); + // delete the office repo inside the propietary_1.repo RepoInfo office; office.setAlias("office"); diff --git a/zypp/RepoManager.cc b/zypp/RepoManager.cc index 3dad1ec..e59c046 100644 --- a/zypp/RepoManager.cc +++ b/zypp/RepoManager.cc @@ -682,6 +682,33 @@ namespace zypp //////////////////////////////////////////////////////////////////////////// + /** + * \short Generate a related filename from a repo info + * + * From a repo info, it will try to use the alias as a filename + * escaping it if necessary. Other fallbacks can be added to + * this function in case there is no way to use the alias + */ + static std::string generate_filename( const RepoInfo &info ) + { + std::string fnd="/"; + std::string rep="_"; + std::string filename = info.alias(); + // replace slashes with underscores + size_t pos = filename.find(fnd); + while(pos!=string::npos) + { + filename.replace(pos,fnd.length(),rep); + pos = filename.find(fnd,pos+rep.length()); + } + filename = Pathname(filename).extend(".repo").asString(); + MIL << "generating filename for repo [" << info.alias() << "] : '" << filename << "'" << endl; + return filename; + } + + + //////////////////////////////////////////////////////////////////////////// + void RepoManager::addRepository( const RepoInfo &info, const ProgressData::ReceiverFnc & progressrcv ) { @@ -708,7 +735,7 @@ namespace zypp filesystem::assert_dir(_pimpl->options.knownReposPath); Pathname repofile = generate_non_existing_name(_pimpl->options.knownReposPath, - Pathname(info.alias()).extend(".repo").asString()); + generate_filename(info)); // now we have a filename that does not exists MIL << "Saving repo in " << repofile << endl;