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 )
604 RepoException enew("Error trying to read from " + url.asString());
608 catch ( const Exception &e )
611 Exception enew("Unknown error reading from " + url.asString());
616 return repo::RepoType::NONE;
619 ////////////////////////////////////////////////////////////////////////////
621 void RepoManager::cleanCache( const RepoInfo &info,
622 const ProgressData::ReceiverFnc & progressrcv )
624 ProgressData progress;
625 callback::SendReport<ProgressReport> report;
626 progress.sendTo( ProgressReportAdaptor( progressrcv, report ) );
627 progress.name(str::form(_("Cleaning repository '%s' cache"), info.alias().c_str()));
629 cache::CacheStore store(_pimpl->options.repoCachePath);
631 if ( !store.isCached(info.alias()) )
634 MIL << info.alias() << " cleaning cache..." << endl;
635 data::RecordId id = store.lookupRepository(info.alias());
637 CombinedProgressData subprogrcv(progress);
639 store.cleanRepository(id, subprogrcv);
643 ////////////////////////////////////////////////////////////////////////////
645 bool RepoManager::isCached( const RepoInfo &info ) const
647 cache::CacheStore store(_pimpl->options.repoCachePath);
648 return store.isCached(info.alias());
651 RepoStatus RepoManager::cacheStatus( const RepoInfo &info ) const
653 cache::CacheStore store(_pimpl->options.repoCachePath);
654 data::RecordId id = store.lookupRepository(info.alias());
655 RepoStatus cache_status = store.repositoryStatus(id);
659 Repository RepoManager::createFromCache( const RepoInfo &info,
660 const ProgressData::ReceiverFnc & progressrcv )
662 callback::SendReport<ProgressReport> report;
663 ProgressData progress;
664 progress.sendTo(ProgressReportAdaptor( progressrcv, report ));
665 //progress.sendTo( progressrcv );
666 progress.name(str::form(_("Reading repository '%s' cache"), info.alias().c_str()));
668 cache::CacheStore store(_pimpl->options.repoCachePath);
670 if ( ! store.isCached( info.alias() ) )
671 ZYPP_THROW(RepoNotCachedException());
673 MIL << "Repository " << info.alias() << " is cached" << endl;
675 data::RecordId id = store.lookupRepository(info.alias());
677 CombinedProgressData subprogrcv(progress);
679 repo::cached::RepoOptions opts( info, _pimpl->options.repoCachePath, id );
680 opts.readingResolvablesProgress = subprogrcv;
681 repo::cached::RepoImpl::Ptr repoimpl =
682 new repo::cached::RepoImpl( opts );
684 repoimpl->resolvables();
685 // read the resolvables from cache
686 return Repository(repoimpl);
689 ////////////////////////////////////////////////////////////////////////////
692 * Generate a non existing filename in a directory, using a base
693 * name. For example if a directory contains 3 files
699 * If you try to generate a unique filename for this directory,
700 * based on "ruu" you will get "ruu", but if you use the base
701 * "foo" you will get "foo_1"
703 * \param dir Directory where the file needs to be unique
704 * \param basefilename string to base the filename on.
706 static Pathname generate_non_existing_name( const Pathname &dir,
707 const std::string &basefilename )
709 string final_filename = basefilename;
711 while ( PathInfo(dir + final_filename).isExist() )
713 final_filename = basefilename + "_" + str::numstring(counter);
716 return dir + Pathname(final_filename);
719 ////////////////////////////////////////////////////////////////////////////
722 * \short Generate a related filename from a repo info
724 * From a repo info, it will try to use the alias as a filename
725 * escaping it if necessary. Other fallbacks can be added to
726 * this function in case there is no way to use the alias
728 static std::string generate_filename( const RepoInfo &info )
732 std::string filename = info.alias();
733 // replace slashes with underscores
734 size_t pos = filename.find(fnd);
735 while(pos!=string::npos)
737 filename.replace(pos,fnd.length(),rep);
738 pos = filename.find(fnd,pos+rep.length());
740 filename = Pathname(filename).extend(".repo").asString();
741 MIL << "generating filename for repo [" << info.alias() << "] : '" << filename << "'" << endl;
746 ////////////////////////////////////////////////////////////////////////////
748 void RepoManager::addRepository( const RepoInfo &info,
749 const ProgressData::ReceiverFnc & progressrcv )
753 ProgressData progress(100);
754 callback::SendReport<ProgressReport> report;
755 progress.sendTo( ProgressReportAdaptor( progressrcv, report ) );
756 progress.name(str::form(_("Adding repository '%s'"), info.alias().c_str()));
759 std::list<RepoInfo> repos = knownRepositories();
760 for ( std::list<RepoInfo>::const_iterator it = repos.begin();
764 if ( info.alias() == (*it).alias() )
765 ZYPP_THROW(RepoAlreadyExistsException(info.alias()));
768 RepoInfo tosave = info;
770 // check the first url for now
771 if ( ZConfig::instance().repo_add_probe() || ( tosave.type() == RepoType::NONE ) )
774 probedtype = probe(*tosave.baseUrlsBegin());
775 if ( tosave.baseUrlsSize() > 0 )
777 if ( probedtype == RepoType::NONE )
778 ZYPP_THROW(RepoUnknownTypeException());
780 tosave.setType(probedtype);
786 // assert the directory exists
787 filesystem::assert_dir(_pimpl->options.knownReposPath);
789 Pathname repofile = generate_non_existing_name(_pimpl->options.knownReposPath,
790 generate_filename(tosave));
791 // now we have a filename that does not exists
792 MIL << "Saving repo in " << repofile << endl;
794 std::ofstream file(repofile.c_str());
796 ZYPP_THROW (Exception( "Can't open " + repofile.asString() ) );
799 tosave.dumpRepoOn(file);
801 MIL << "done" << endl;
804 void RepoManager::addRepositories( const Url &url,
805 const ProgressData::ReceiverFnc & progressrcv )
807 std::list<RepoInfo> knownrepos = knownRepositories();
808 std::list<RepoInfo> repos = readRepoFile(url);
809 for ( std::list<RepoInfo>::const_iterator it = repos.begin();
813 // look if the alias is in the known repos.
814 for ( std::list<RepoInfo>::const_iterator kit = knownrepos.begin();
815 kit != knownrepos.end();
818 if ( (*it).alias() == (*kit).alias() )
820 ERR << "To be added repo " << (*it).alias() << " conflicts with existing repo " << (*kit).alias() << endl;
821 ZYPP_THROW(RepoAlreadyExistsException((*it).alias()));
826 string filename = Pathname(url.getPathName()).basename();
828 if ( filename == Pathname() )
829 ZYPP_THROW(RepoException("Invalid repo file name at " + url.asString() ));
831 // assert the directory exists
832 filesystem::assert_dir(_pimpl->options.knownReposPath);
834 Pathname repofile = generate_non_existing_name(_pimpl->options.knownReposPath, filename);
835 // now we have a filename that does not exists
836 MIL << "Saving " << repos.size() << " repo" << ( repos.size() ? "s" : "" ) << " in " << repofile << endl;
838 std::ofstream file(repofile.c_str());
840 ZYPP_THROW (Exception( "Can't open " + repofile.asString() ) );
843 for ( std::list<RepoInfo>::const_iterator it = repos.begin();
847 MIL << "Saving " << (*it).alias() << endl;
848 (*it).dumpRepoOn(file);
850 MIL << "done" << endl;
853 ////////////////////////////////////////////////////////////////////////////
855 void RepoManager::removeRepository( const RepoInfo & info,
856 const ProgressData::ReceiverFnc & progressrcv)
858 ProgressData progress;
859 callback::SendReport<ProgressReport> report;
860 progress.sendTo( ProgressReportAdaptor( progressrcv, report ) );
861 progress.name(str::form(_("Removing repository '%s'"), info.alias().c_str()));
863 MIL << "Going to delete repo " << info.alias() << endl;
865 std::list<RepoInfo> repos = knownRepositories();
866 for ( std::list<RepoInfo>::const_iterator it = repos.begin();
870 // they can be the same only if the provided is empty, that means
871 // the provided repo has no alias
873 if ( (!info.alias().empty()) && ( info.alias() != (*it).alias() ) )
878 // we have a matcing repository, now we need to know
879 // where it does come from.
880 RepoInfo todelete = *it;
881 if (todelete.filepath().empty())
883 ZYPP_THROW(RepoException("Can't figure where the repo is stored"));
887 // figure how many repos are there in the file:
888 std::list<RepoInfo> filerepos = repositories_in_file(todelete.filepath());
889 if ( (filerepos.size() == 1) && ( filerepos.front().alias() == todelete.alias() ) )
891 // easy, only this one, just delete the file
892 if ( filesystem::unlink(todelete.filepath()) != 0 )
894 ZYPP_THROW(RepoException("Can't delete " + todelete.filepath().asString()));
896 MIL << todelete.alias() << " sucessfully deleted." << endl;
900 // there are more repos in the same file
901 // write them back except the deleted one.
903 //std::ofstream file(tmp.path().c_str());
905 // assert the directory exists
906 filesystem::assert_dir(todelete.filepath().dirname());
908 std::ofstream file(todelete.filepath().c_str());
910 //ZYPP_THROW (Exception( "Can't open " + tmp.path().asString() ) );
911 ZYPP_THROW (Exception( "Can't open " + todelete.filepath().asString() ) );
913 for ( std::list<RepoInfo>::const_iterator fit = filerepos.begin();
914 fit != filerepos.end();
917 if ( (*fit).alias() != todelete.alias() )
918 (*fit).dumpRepoOn(file);
922 CombinedProgressData subprogrcv(progress);
924 // now delete it from cache
925 cleanCache(todelete, subprogrcv);
927 MIL << todelete.alias() << " sucessfully deleted." << endl;
929 } // else filepath is empty
932 // should not be reached on a sucess workflow
933 ZYPP_THROW(RepoNotFoundException(info));
936 ////////////////////////////////////////////////////////////////////////////
938 void RepoManager::modifyRepository( const std::string &alias,
939 const RepoInfo & newinfo,
940 const ProgressData::ReceiverFnc & progressrcv )
942 RepoInfo toedit = getRepositoryInfo(alias);
944 if (toedit.filepath().empty())
946 ZYPP_THROW(RepoException("Can't figure where the repo is stored"));
950 // figure how many repos are there in the file:
951 std::list<RepoInfo> filerepos = repositories_in_file(toedit.filepath());
953 // there are more repos in the same file
954 // write them back except the deleted one.
956 //std::ofstream file(tmp.path().c_str());
958 // assert the directory exists
959 filesystem::assert_dir(toedit.filepath().dirname());
961 std::ofstream file(toedit.filepath().c_str());
963 //ZYPP_THROW (Exception( "Can't open " + tmp.path().asString() ) );
964 ZYPP_THROW (Exception( "Can't open " + toedit.filepath().asString() ) );
966 for ( std::list<RepoInfo>::const_iterator fit = filerepos.begin();
967 fit != filerepos.end();
970 // if the alias is different, dump the original
971 // if it is the same, dump the provided one
972 if ( (*fit).alias() != toedit.alias() )
973 (*fit).dumpRepoOn(file);
975 newinfo.dumpRepoOn(file);
980 ////////////////////////////////////////////////////////////////////////////
982 RepoInfo RepoManager::getRepositoryInfo( const std::string &alias,
983 const ProgressData::ReceiverFnc & progressrcv )
985 std::list<RepoInfo> repos = knownRepositories();
986 for ( std::list<RepoInfo>::const_iterator it = repos.begin();
990 if ( (*it).alias() == alias )
994 info.setAlias(info.alias());
995 ZYPP_THROW(RepoNotFoundException(info));
998 ////////////////////////////////////////////////////////////////////////////
1000 RepoInfo RepoManager::getRepositoryInfo( const Url & url,
1001 const url::ViewOption & urlview,
1002 const ProgressData::ReceiverFnc & progressrcv )
1004 std::list<RepoInfo> repos = knownRepositories();
1005 for ( std::list<RepoInfo>::const_iterator it = repos.begin();
1009 for(RepoInfo::urls_const_iterator urlit = (*it).baseUrlsBegin();
1010 urlit != (*it).baseUrlsEnd();
1013 if ((*urlit).asString(urlview) == url.asString(urlview))
1018 info.setAlias(info.alias());
1019 info.setBaseUrl(url);
1020 ZYPP_THROW(RepoNotFoundException(info));
1023 ////////////////////////////////////////////////////////////////////////////
1025 std::ostream & operator<<( std::ostream & str, const RepoManager & obj )
1027 return str << *obj._pimpl;
1030 /////////////////////////////////////////////////////////////////
1032 ///////////////////////////////////////////////////////////////////