1 /*---------------------------------------------------------------------\
3 | |__ / \ / / . \ . \ |
8 \---------------------------------------------------------------------*/
9 /** \file zypp/RepoManager.cc
17 #include "zypp/base/InputStream.h"
18 #include "zypp/base/Logger.h"
19 #include "zypp/base/Gettext.h"
20 #include "zypp/base/Function.h"
21 #include "zypp/PathInfo.h"
22 #include "zypp/TmpPath.h"
24 #include "zypp/repo/RepoException.h"
25 #include "zypp/RepoManager.h"
27 #include "zypp/cache/CacheStore.h"
28 #include "zypp/repo/cached/RepoImpl.h"
29 #include "zypp/media/MediaManager.h"
30 #include "zypp/MediaSetAccess.h"
32 #include "zypp/parser/RepoFileReader.h"
33 #include "zypp/repo/yum/Downloader.h"
34 #include "zypp/parser/yum/RepoParser.h"
35 #include "zypp/parser/plaindir/RepoParser.h"
36 #include "zypp/repo/susetags/Downloader.h"
37 #include "zypp/parser/susetags/RepoParser.h"
39 #include "zypp/ZYppCallbacks.h"
43 using namespace zypp::repo;
44 using namespace zypp::filesystem;
46 using namespace zypp::repo;
48 ///////////////////////////////////////////////////////////////////
50 { /////////////////////////////////////////////////////////////////
52 ///////////////////////////////////////////////////////////////////
54 // CLASS NAME : RepoManagerOptions
56 ///////////////////////////////////////////////////////////////////
58 RepoManagerOptions::RepoManagerOptions()
60 repoCachePath = ZConfig::instance().repoCachePath();
61 repoRawCachePath = ZConfig::instance().repoMetadataPath();
62 knownReposPath = ZConfig::instance().knownReposPath();
65 ////////////////////////////////////////////////////////////////////////////
68 * \short Simple callback to collect the results
70 * Classes like RepoFileParser call the callback
71 * once per each repo in a file.
73 * Passing this functor as callback, you can collect
74 * all resuls at the end, without dealing with async
89 bool collect( const RepoInfo &repo )
91 //MIL << "here in collector: " << repo.alias() << endl;
92 repos.push_back(repo);
93 //MIL << "added: " << repo.alias() << endl;
100 ////////////////////////////////////////////////////////////////////////////
103 * Reads RepoInfo's from a repo file.
105 * \param file pathname of the file to read.
107 static std::list<RepoInfo> repositories_in_file( const Pathname & file )
109 MIL << "repo file: " << file << endl;
110 RepoCollector collector;
111 parser::RepoFileReader parser( file, bind( &RepoCollector::collect, &collector, _1 ) );
112 return collector.repos;
115 ////////////////////////////////////////////////////////////////////////////
117 std::list<RepoInfo> readRepoFile(const Url & repo_file)
119 // no interface to download a specific file, using workaround:
120 //! \todo add MediaManager::provideFile(Url file_url) to easily access any file URLs? (no need for media access id or media_nr)
122 Pathname path(url.getPathName());
123 url.setPathName ("/");
124 MediaSetAccess access(url);
125 Pathname local = access.provideFile(path);
127 DBG << "reading repo file " << repo_file << ", local path: " << local << endl;
129 return repositories_in_file(local);
132 ////////////////////////////////////////////////////////////////////////////
135 * \short List of RepoInfo's from a directory
137 * Goes trough every file in a directory and adds all
138 * RepoInfo's contained in that file.
140 * \param dir pathname of the directory to read.
142 static std::list<RepoInfo> repositories_in_dir( const Pathname &dir )
144 MIL << "directory " << dir << endl;
145 list<RepoInfo> repos;
146 list<Pathname> entries;
147 if ( filesystem::readdir( entries, Pathname(dir), false ) != 0 )
148 ZYPP_THROW(Exception("failed to read directory"));
150 for ( list<Pathname>::const_iterator it = entries.begin(); it != entries.end(); ++it )
152 list<RepoInfo> tmp = repositories_in_file( *it );
153 repos.insert( repos.end(), tmp.begin(), tmp.end() );
155 //std::copy( collector.repos.begin(), collector.repos.end(), std::back_inserter(repos));
156 //MIL << "ok" << endl;
161 ////////////////////////////////////////////////////////////////////////////
163 static void assert_alias( const RepoInfo &info )
165 if (info.alias().empty())
166 ZYPP_THROW(RepoNoAliasException());
169 ////////////////////////////////////////////////////////////////////////////
171 static void assert_urls( const RepoInfo &info )
173 if (info.baseUrlsEmpty())
174 ZYPP_THROW(RepoNoUrlException());
177 ////////////////////////////////////////////////////////////////////////////
180 * \short Calculates the raw cache path for a repository
182 static Pathname rawcache_path_for_repoinfo( const RepoManagerOptions &opt, const RepoInfo &info )
185 return opt.repoRawCachePath + info.alias();
188 ///////////////////////////////////////////////////////////////////
190 // CLASS NAME : RepoManager::Impl
192 ///////////////////////////////////////////////////////////////////
195 * \short RepoManager implementation.
197 struct RepoManager::Impl
199 Impl( const RepoManagerOptions &opt )
210 RepoManagerOptions options;
213 /** Offer default Impl. */
214 static shared_ptr<Impl> nullimpl()
216 static shared_ptr<Impl> _nullimpl( new Impl );
221 friend Impl * rwcowClone<Impl>( const Impl * rhs );
222 /** clone for RWCOW_pointer */
224 { return new Impl( *this ); }
226 ///////////////////////////////////////////////////////////////////
228 /** \relates RepoManager::Impl Stream output */
229 inline std::ostream & operator<<( std::ostream & str, const RepoManager::Impl & obj )
231 return str << "RepoManager::Impl";
234 ///////////////////////////////////////////////////////////////////
236 // CLASS NAME : RepoManager
238 ///////////////////////////////////////////////////////////////////
240 RepoManager::RepoManager( const RepoManagerOptions &opt )
241 : _pimpl( new Impl(opt) )
244 ////////////////////////////////////////////////////////////////////////////
246 RepoManager::~RepoManager()
249 ////////////////////////////////////////////////////////////////////////////
251 std::list<RepoInfo> RepoManager::knownRepositories() const
255 if ( PathInfo(_pimpl->options.knownReposPath).isExist() )
257 RepoInfoList repos = repositories_in_dir(_pimpl->options.knownReposPath);
258 for ( RepoInfoList::iterator it = repos.begin();
262 // set the metadata path for the repo
263 Pathname metadata_path = rawcache_path_for_repoinfo(_pimpl->options, (*it));
264 (*it).setMetadataPath(metadata_path);
269 return std::list<RepoInfo>();
274 ////////////////////////////////////////////////////////////////////////////
276 RepoStatus RepoManager::metadataStatus( const RepoInfo &info ) const
278 Pathname rawpath = rawcache_path_for_repoinfo( _pimpl->options, info );
279 RepoType repokind = info.type();
282 switch ( repokind.toEnum() )
284 case RepoType::NONE_e:
285 // unknown, probe the local metadata
286 repokind = probe(rawpath.asUrl());
292 switch ( repokind.toEnum() )
294 case RepoType::RPMMD_e :
296 status = RepoStatus( rawpath + "/repodata/repomd.xml");
300 case RepoType::YAST2_e :
302 status = RepoStatus( rawpath + "/content");
306 case RepoType::RPMPLAINDIR_e :
308 if ( PathInfo(Pathname(rawpath + "/cookie")).isExist() )
309 status = RepoStatus( rawpath + "/cookie");
313 case RepoType::NONE_e :
314 // Return default RepoStatus in case of RepoType::NONE
315 // indicating it should be created?
316 // ZYPP_THROW(RepoUnknownTypeException());
322 void RepoManager::refreshMetadata( const RepoInfo &info,
323 RawMetadataRefreshPolicy policy,
324 const ProgressData::ReceiverFnc & progress )
329 RepoStatus oldstatus;
330 RepoStatus newstatus;
331 // try urls one by one
332 for ( RepoInfo::urls_const_iterator it = info.baseUrlsBegin(); it != info.baseUrlsEnd(); ++it )
338 MIL << "Going to try to check and refresh metadata from " << url << endl;
340 repo::RepoType repokind = info.type();
342 // if the type is unknown, try probing.
343 switch ( repokind.toEnum() )
345 case RepoType::NONE_e:
347 repokind = probe(*it);
353 Pathname rawpath = rawcache_path_for_repoinfo( _pimpl->options, info );
354 filesystem::assert_dir(rawpath);
355 oldstatus = metadataStatus(info);
357 // create temp dir as sibling of rawpath
358 filesystem::TmpDir tmpdir( filesystem::TmpDir::makeSibling( rawpath ) );
360 if ( ( repokind.toEnum() == RepoType::RPMMD_e ) ||
361 ( repokind.toEnum() == RepoType::YAST2_e ) )
363 MediaSetAccess media(url);
364 shared_ptr<repo::Downloader> downloader_ptr;
366 if ( repokind.toEnum() == RepoType::RPMMD_e )
367 downloader_ptr.reset(new yum::Downloader(info.path()));
369 downloader_ptr.reset( new susetags::Downloader(info.path()));
372 * Given a downloader, sets the other repos raw metadata
373 * path as cache paths for the fetcher, so if another
374 * repo has the same file, it will not download it
375 * but copy it from the other repository
377 std::list<RepoInfo> repos = knownRepositories();
378 for ( std::list<RepoInfo>::const_iterator it = repos.begin();
382 downloader_ptr->addCachePath(rawcache_path_for_repoinfo( _pimpl->options, *it ));
385 RepoStatus newstatus = downloader_ptr->status(media);
386 bool refresh = false;
387 if ( oldstatus.checksum() == newstatus.checksum() )
389 MIL << "repo has not changed" << endl;
390 if ( policy == RefreshForced )
392 MIL << "refresh set to forced" << endl;
398 MIL << "repo has changed, going to refresh" << endl;
402 downloader_ptr->download( media, tmpdir.path());
407 else if ( repokind.toEnum() == RepoType::RPMPLAINDIR_e )
409 RepoStatus newstatus = parser::plaindir::dirStatus(url.getPathName());
410 bool refresh = false;
411 if ( oldstatus.checksum() == newstatus.checksum() )
413 MIL << "repo has not changed" << endl;
414 if ( policy == RefreshForced )
416 MIL << "refresh set to forced" << endl;
422 MIL << "repo has changed, going to refresh" << endl;
428 std::ofstream file(( tmpdir.path() + "/cookie").c_str());
430 ZYPP_THROW (Exception( "Can't open " + tmpdir.path().asString() + "/cookie" ) );
433 file << newstatus.checksum() << endl;
443 ZYPP_THROW(RepoUnknownTypeException());
446 // ok we have the metadata, now exchange
448 TmpDir oldmetadata( TmpDir::makeSibling( rawpath ) );
449 filesystem::rename( rawpath, oldmetadata.path() );
450 // move the just downloaded there
451 filesystem::rename( tmpdir.path(), rawpath );
455 catch ( const Exception &e )
458 ERR << "Trying another url..." << endl;
461 ERR << "No more urls..." << endl;
462 ZYPP_THROW(RepoException(_("Valid metadata not found at specified URL(s)")));
465 ////////////////////////////////////////////////////////////////////////////
467 void RepoManager::cleanMetadata( const RepoInfo &info,
468 const ProgressData::ReceiverFnc & progress )
470 filesystem::recursive_rmdir(rawcache_path_for_repoinfo(_pimpl->options, info));
473 void RepoManager::buildCache( const RepoInfo &info,
474 CacheBuildPolicy policy,
475 const ProgressData::ReceiverFnc & progressrcv )
477 ProgressData progress(100);
478 callback::SendReport<ProgressReport> report;
479 progress.sendTo( ProgressReportAdaptor( progressrcv, report ) );
480 progress.name(str::form(_("Building repository '%s' cache"), info.alias().c_str()));
484 Pathname rawpath = rawcache_path_for_repoinfo(_pimpl->options, info);
486 cache::CacheStore store(_pimpl->options.repoCachePath);
488 RepoStatus raw_metadata_status = metadataStatus(info);
489 if ( raw_metadata_status.empty() )
491 ZYPP_THROW(RepoMetadataException(info));
494 if ( store.isCached( info.alias() ) )
496 MIL << info.alias() << " is already cached." << endl;
497 data::RecordId id = store.lookupRepository(info.alias());
498 RepoStatus cache_status = store.repositoryStatus(id);
500 if ( cache_status.checksum() == raw_metadata_status.checksum() )
502 MIL << info.alias() << " cache is up to date with metadata." << endl;
503 if ( policy == BuildIfNeeded ) {
508 MIL << info.alias() << " cache rebuild is forced" << endl;
515 MIL << info.alias() << " building cache..." << endl;
516 data::RecordId id = store.lookupOrAppendRepository(info.alias());
518 repo::RepoType repokind = info.type();
520 // if the type is unknown, try probing.
521 switch ( repokind.toEnum() )
523 case RepoType::NONE_e:
524 // unknown, probe the local metadata
525 repokind = probe(rawpath.asUrl());
531 CombinedProgressData subprogrcv( progress, 100);
533 switch ( repokind.toEnum() )
535 case RepoType::RPMMD_e :
537 parser::yum::RepoParser parser(id, store, parser::yum::RepoParserOpts(), subprogrcv);
538 parser.parse(rawpath);
542 case RepoType::YAST2_e :
544 parser::susetags::RepoParser parser(id, store, subprogrcv);
545 parser.parse(rawpath);
549 case RepoType::RPMPLAINDIR_e :
551 InputStream is(rawpath + "cookie");
553 getline( is.stream(), buffer);
555 parser::plaindir::RepoParser parser(id, store, subprogrcv);
556 parser.parse(url.getPathName());
560 ZYPP_THROW(RepoUnknownTypeException());
563 // update timestamp and checksum
564 store.updateRepositoryStatus(id, raw_metadata_status);
566 MIL << "Commit cache.." << endl;
571 ////////////////////////////////////////////////////////////////////////////
573 repo::RepoType RepoManager::probe( const Url &url ) const
575 if ( url.getScheme() == "dir" && ! PathInfo( url.getPathName() ).isDir() )
577 // Handle non existing local directory in advance, as
578 // MediaSetAccess does not support it.
579 return repo::RepoType::NONE;
584 MediaSetAccess access(url);
585 if ( access.doesFileExist("/repodata/repomd.xml") )
586 return repo::RepoType::RPMMD;
587 if ( access.doesFileExist("/content") )
588 return repo::RepoType::YAST2;
590 // if it is a local url of type dir
591 if ( (! media::MediaManager::downloads(url)) && ( url.getScheme() == "dir" ) )
593 Pathname path = Pathname(url.getPathName());
594 if ( PathInfo(path).isDir() )
596 // allow empty dirs for now
597 return repo::RepoType::RPMPLAINDIR;
601 catch ( const media::MediaException &e )
603 ZYPP_THROW(RepoException("Error trying to read from " + url.asString()));
605 catch ( const Exception &e )
607 ZYPP_THROW(Exception("Unknown error reading from " + url.asString()));
610 return repo::RepoType::NONE;
613 ////////////////////////////////////////////////////////////////////////////
615 void RepoManager::cleanCache( const RepoInfo &info,
616 const ProgressData::ReceiverFnc & progressrcv )
618 ProgressData progress;
619 callback::SendReport<ProgressReport> report;
620 progress.sendTo( ProgressReportAdaptor( progressrcv, report ) );
621 progress.name(str::form(_("Cleaning repository '%s' cache"), info.alias().c_str()));
623 cache::CacheStore store(_pimpl->options.repoCachePath);
625 if ( !store.isCached(info.alias()) )
628 MIL << info.alias() << " cleaning cache..." << endl;
629 data::RecordId id = store.lookupRepository(info.alias());
631 CombinedProgressData subprogrcv(progress);
633 store.cleanRepository(id, subprogrcv);
637 ////////////////////////////////////////////////////////////////////////////
639 bool RepoManager::isCached( const RepoInfo &info ) const
641 cache::CacheStore store(_pimpl->options.repoCachePath);
642 return store.isCached(info.alias());
645 RepoStatus RepoManager::cacheStatus( const RepoInfo &info ) const
647 cache::CacheStore store(_pimpl->options.repoCachePath);
648 data::RecordId id = store.lookupRepository(info.alias());
649 RepoStatus cache_status = store.repositoryStatus(id);
653 Repository RepoManager::createFromCache( const RepoInfo &info,
654 const ProgressData::ReceiverFnc & progressrcv )
656 callback::SendReport<ProgressReport> report;
657 ProgressData progress;
658 progress.sendTo(ProgressReportAdaptor( progressrcv, report ));
659 //progress.sendTo( progressrcv );
660 progress.name(str::form(_("Reading repository '%s' cache"), info.alias().c_str()));
662 cache::CacheStore store(_pimpl->options.repoCachePath);
664 if ( ! store.isCached( info.alias() ) )
665 ZYPP_THROW(RepoNotCachedException());
667 MIL << "Repository " << info.alias() << " is cached" << endl;
669 data::RecordId id = store.lookupRepository(info.alias());
671 CombinedProgressData subprogrcv(progress);
673 repo::cached::RepoOptions opts( info, _pimpl->options.repoCachePath, id );
674 opts.readingResolvablesProgress = subprogrcv;
675 repo::cached::RepoImpl::Ptr repoimpl =
676 new repo::cached::RepoImpl( opts );
678 repoimpl->resolvables();
679 // read the resolvables from cache
680 return Repository(repoimpl);
683 ////////////////////////////////////////////////////////////////////////////
686 * Generate a non existing filename in a directory, using a base
687 * name. For example if a directory contains 3 files
693 * If you try to generate a unique filename for this directory,
694 * based on "ruu" you will get "ruu", but if you use the base
695 * "foo" you will get "foo_1"
697 * \param dir Directory where the file needs to be unique
698 * \param basefilename string to base the filename on.
700 static Pathname generate_non_existing_name( const Pathname &dir,
701 const std::string &basefilename )
703 string final_filename = basefilename;
705 while ( PathInfo(dir + final_filename).isExist() )
707 final_filename = basefilename + "_" + str::numstring(counter);
710 return dir + Pathname(final_filename);
713 ////////////////////////////////////////////////////////////////////////////
716 * \short Generate a related filename from a repo info
718 * From a repo info, it will try to use the alias as a filename
719 * escaping it if necessary. Other fallbacks can be added to
720 * this function in case there is no way to use the alias
722 static std::string generate_filename( const RepoInfo &info )
726 std::string filename = info.alias();
727 // replace slashes with underscores
728 size_t pos = filename.find(fnd);
729 while(pos!=string::npos)
731 filename.replace(pos,fnd.length(),rep);
732 pos = filename.find(fnd,pos+rep.length());
734 filename = Pathname(filename).extend(".repo").asString();
735 MIL << "generating filename for repo [" << info.alias() << "] : '" << filename << "'" << endl;
740 ////////////////////////////////////////////////////////////////////////////
742 void RepoManager::addRepository( const RepoInfo &info,
743 const ProgressData::ReceiverFnc & progressrcv )
747 ProgressData progress(100);
748 callback::SendReport<ProgressReport> report;
749 progress.sendTo( ProgressReportAdaptor( progressrcv, report ) );
750 progress.name(str::form(_("Adding repository '%s'"), info.alias().c_str()));
753 std::list<RepoInfo> repos = knownRepositories();
754 for ( std::list<RepoInfo>::const_iterator it = repos.begin();
758 if ( info.alias() == (*it).alias() )
759 ZYPP_THROW(RepoAlreadyExistsException(info.alias()));
762 RepoInfo tosave = info;
764 // check the first url for now
765 if ( ZConfig::instance().repo_add_probe() || ( tosave.type() == RepoType::NONE ) )
768 probedtype = probe(*tosave.baseUrlsBegin());
769 if ( tosave.baseUrlsSize() > 0 )
771 if ( probedtype == RepoType::NONE )
772 ZYPP_THROW(RepoUnknownTypeException());
774 tosave.setType(probedtype);
780 // assert the directory exists
781 filesystem::assert_dir(_pimpl->options.knownReposPath);
783 Pathname repofile = generate_non_existing_name(_pimpl->options.knownReposPath,
784 generate_filename(tosave));
785 // now we have a filename that does not exists
786 MIL << "Saving repo in " << repofile << endl;
788 std::ofstream file(repofile.c_str());
790 ZYPP_THROW (Exception( "Can't open " + repofile.asString() ) );
793 tosave.dumpRepoOn(file);
795 MIL << "done" << endl;
798 void RepoManager::addRepositories( const Url &url,
799 const ProgressData::ReceiverFnc & progressrcv )
801 std::list<RepoInfo> knownrepos = knownRepositories();
802 std::list<RepoInfo> repos = readRepoFile(url);
803 for ( std::list<RepoInfo>::const_iterator it = repos.begin();
807 // look if the alias is in the known repos.
808 for ( std::list<RepoInfo>::const_iterator kit = knownrepos.begin();
809 kit != knownrepos.end();
812 if ( (*it).alias() == (*kit).alias() )
814 ERR << "To be added repo " << (*it).alias() << " conflicts with existing repo " << (*kit).alias() << endl;
815 ZYPP_THROW(RepoAlreadyExistsException((*it).alias()));
820 string filename = Pathname(url.getPathName()).basename();
822 if ( filename == Pathname() )
823 ZYPP_THROW(RepoException("Invalid repo file name at " + url.asString() ));
825 // assert the directory exists
826 filesystem::assert_dir(_pimpl->options.knownReposPath);
828 Pathname repofile = generate_non_existing_name(_pimpl->options.knownReposPath, filename);
829 // now we have a filename that does not exists
830 MIL << "Saving " << repos.size() << " repo" << ( repos.size() ? "s" : "" ) << " in " << repofile << endl;
832 std::ofstream file(repofile.c_str());
834 ZYPP_THROW (Exception( "Can't open " + repofile.asString() ) );
837 for ( std::list<RepoInfo>::const_iterator it = repos.begin();
841 MIL << "Saving " << (*it).alias() << endl;
842 (*it).dumpRepoOn(file);
844 MIL << "done" << endl;
847 ////////////////////////////////////////////////////////////////////////////
849 void RepoManager::removeRepository( const RepoInfo & info,
850 const ProgressData::ReceiverFnc & progressrcv)
852 ProgressData progress;
853 callback::SendReport<ProgressReport> report;
854 progress.sendTo( ProgressReportAdaptor( progressrcv, report ) );
855 progress.name(str::form(_("Removing repository '%s'"), info.alias().c_str()));
857 MIL << "Going to delete repo " << info.alias() << endl;
859 std::list<RepoInfo> repos = knownRepositories();
860 for ( std::list<RepoInfo>::const_iterator it = repos.begin();
864 // they can be the same only if the provided is empty, that means
865 // the provided repo has no alias
867 if ( (!info.alias().empty()) && ( info.alias() != (*it).alias() ) )
872 // we have a matcing repository, now we need to know
873 // where it does come from.
874 RepoInfo todelete = *it;
875 if (todelete.filepath().empty())
877 ZYPP_THROW(RepoException("Can't figure where the repo is stored"));
881 // figure how many repos are there in the file:
882 std::list<RepoInfo> filerepos = repositories_in_file(todelete.filepath());
883 if ( (filerepos.size() == 1) && ( filerepos.front().alias() == todelete.alias() ) )
885 // easy, only this one, just delete the file
886 if ( filesystem::unlink(todelete.filepath()) != 0 )
888 ZYPP_THROW(RepoException("Can't delete " + todelete.filepath().asString()));
890 MIL << todelete.alias() << " sucessfully deleted." << endl;
894 // there are more repos in the same file
895 // write them back except the deleted one.
897 //std::ofstream file(tmp.path().c_str());
899 // assert the directory exists
900 filesystem::assert_dir(todelete.filepath().dirname());
902 std::ofstream file(todelete.filepath().c_str());
904 //ZYPP_THROW (Exception( "Can't open " + tmp.path().asString() ) );
905 ZYPP_THROW (Exception( "Can't open " + todelete.filepath().asString() ) );
907 for ( std::list<RepoInfo>::const_iterator fit = filerepos.begin();
908 fit != filerepos.end();
911 if ( (*fit).alias() != todelete.alias() )
912 (*fit).dumpRepoOn(file);
916 CombinedProgressData subprogrcv(progress);
918 // now delete it from cache
919 cleanCache(todelete, subprogrcv);
921 MIL << todelete.alias() << " sucessfully deleted." << endl;
923 } // else filepath is empty
926 // should not be reached on a sucess workflow
927 ZYPP_THROW(RepoNotFoundException(info));
930 ////////////////////////////////////////////////////////////////////////////
932 void RepoManager::modifyRepository( const std::string &alias,
933 const RepoInfo & newinfo,
934 const ProgressData::ReceiverFnc & progressrcv )
936 RepoInfo toedit = getRepositoryInfo(alias);
938 if (toedit.filepath().empty())
940 ZYPP_THROW(RepoException("Can't figure where the repo is stored"));
944 // figure how many repos are there in the file:
945 std::list<RepoInfo> filerepos = repositories_in_file(toedit.filepath());
947 // there are more repos in the same file
948 // write them back except the deleted one.
950 //std::ofstream file(tmp.path().c_str());
952 // assert the directory exists
953 filesystem::assert_dir(toedit.filepath().dirname());
955 std::ofstream file(toedit.filepath().c_str());
957 //ZYPP_THROW (Exception( "Can't open " + tmp.path().asString() ) );
958 ZYPP_THROW (Exception( "Can't open " + toedit.filepath().asString() ) );
960 for ( std::list<RepoInfo>::const_iterator fit = filerepos.begin();
961 fit != filerepos.end();
964 // if the alias is different, dump the original
965 // if it is the same, dump the provided one
966 if ( (*fit).alias() != toedit.alias() )
967 (*fit).dumpRepoOn(file);
969 newinfo.dumpRepoOn(file);
974 ////////////////////////////////////////////////////////////////////////////
976 RepoInfo RepoManager::getRepositoryInfo( const std::string &alias,
977 const ProgressData::ReceiverFnc & progressrcv )
979 std::list<RepoInfo> repos = knownRepositories();
980 for ( std::list<RepoInfo>::const_iterator it = repos.begin();
984 if ( (*it).alias() == alias )
988 info.setAlias(info.alias());
989 ZYPP_THROW(RepoNotFoundException(info));
992 ////////////////////////////////////////////////////////////////////////////
994 RepoInfo RepoManager::getRepositoryInfo( const Url & url,
995 const url::ViewOption & urlview,
996 const ProgressData::ReceiverFnc & progressrcv )
998 std::list<RepoInfo> repos = knownRepositories();
999 for ( std::list<RepoInfo>::const_iterator it = repos.begin();
1003 for(RepoInfo::urls_const_iterator urlit = (*it).baseUrlsBegin();
1004 urlit != (*it).baseUrlsEnd();
1007 if ((*urlit).asString(urlview) == url.asString(urlview))
1012 info.setAlias(info.alias());
1013 info.setBaseUrl(url);
1014 ZYPP_THROW(RepoNotFoundException(info));
1017 ////////////////////////////////////////////////////////////////////////////
1019 std::ostream & operator<<( std::ostream & str, const RepoManager & obj )
1021 return str << *obj._pimpl;
1024 /////////////////////////////////////////////////////////////////
1026 ///////////////////////////////////////////////////////////////////