From: Duncan Mac-Vicar P Date: Tue, 19 Jun 2007 09:05:05 +0000 (+0000) Subject: add repo by custom repoinfo or a complete remote .repo file X-Git-Tag: BASE-SuSE-Linux-10_3-Branch~596 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=e963b2342ad254299543dd2393da19ab86098bef;p=platform%2Fupstream%2Flibzypp.git add repo by custom repoinfo or a complete remote .repo file implemented (not tested) --- diff --git a/zypp/RepoManager.cc b/zypp/RepoManager.cc index d7534b2..e30dfb7 100644 --- a/zypp/RepoManager.cc +++ b/zypp/RepoManager.cc @@ -11,6 +11,7 @@ */ #include +#include #include #include #include "zypp/base/InputStream.h" @@ -531,6 +532,36 @@ namespace zypp } //////////////////////////////////////////////////////////////////////////// + + /** + * Generate a non existing filename in a directory, using a base + * name. For example if a directory contains 3 files + * + * |-- bar + * |-- foo + * `-- moo + * + * 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" + * + * \param dir Directory where the file needs to be unique + * \param basefilename string to base the filename on. + */ + static Pathname generate_non_existing_name( const Pathname &dir, + const std::string &basefilename ) + { + string final_filename = basefilename; + int counter = 1; + while ( PathInfo(dir + final_filename).isExist() ) + { + final_filename = basefilename + "_" + str::numstring(counter); + counter++; + } + return dir + Pathname(final_filename); + } + + //////////////////////////////////////////////////////////////////////////// void RepoManager::addRepository( const RepoInfo &info, const ProgressData::ReceiverFnc & progressrcv ) @@ -545,6 +576,18 @@ namespace zypp if ( info.alias() == (*it).alias() ) ZYPP_THROW(RepoAlreadyExistsException(info.alias())); } + + Pathname repofile = generate_non_existing_name(_pimpl->options.knownReposPath, info.alias()).extend(".repo"); + // 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, @@ -566,21 +609,28 @@ namespace zypp } } - Pathname filename = Pathname(url.getPathName()).basename(); + string filename = Pathname(url.getPathName()).basename(); if ( filename == Pathname() ) ZYPP_THROW(RepoException("Invalid repo file name at " + url.asString() )); - // FIXME move this code to a separate function - Pathname final_filename = filename; - int counter = 1; - while ( PathInfo(_pimpl->options.knownReposPath + filename).isExist() ) - { - filename = Pathname( filename.asString() + "_" + str::numstring(counter)); - counter++; - } + Pathname repofile = generate_non_existing_name(_pimpl->options.knownReposPath, filename).extend(".repo"); // 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::const_iterator it = repos.begin(); + it != repos.end(); + ++it ) + { + MIL << "Saving " << (*it).alias() << endl; + (*it).dumpRepoOn(file); + } + MIL << "done" << endl; } //////////////////////////////////////////////////////////////////////////// diff --git a/zypp/RepoManager.h b/zypp/RepoManager.h index 3f0ceae..54f5f94 100644 --- a/zypp/RepoManager.h +++ b/zypp/RepoManager.h @@ -206,18 +206,17 @@ namespace zypp * \throws ParseException If the file parsing fails * \throws Exception On other errors. */ - void addRepositories( const Url &url, + void addRepositories( const Url &url, const ProgressData::ReceiverFnc & progressrcv = ProgressData::ReceiverFnc() ); /** * PROPOSAL */ void removeRepository( const std::string & alias, const ProgressData::ReceiverFnc & progressrcv = ProgressData::ReceiverFnc() ); - + + protected: RepoStatus rawMetadataStatus( const RepoInfo &info ); RepoStatus cacheStatus( const RepoInfo &info ); - - public: private: