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 * \short Internal version of clean cache
105 * Takes an extra CacheStore reference, so we avoid internally
106 * having 2 CacheStores writing to the same database.
108 static void cleanCacheInternal( cache::CacheStore &store,
109 const RepoInfo &info,
110 const ProgressData::ReceiverFnc & progressrcv = ProgressData::ReceiverFnc() )
112 ProgressData progress;
113 callback::SendReport<ProgressReport> report;
114 progress.sendTo( ProgressReportAdaptor( progressrcv, report ) );
115 progress.name(str::form(_("Cleaning repository '%s' cache"), info.alias().c_str()));
117 if ( !store.isCached(info.alias()) )
120 MIL << info.alias() << " cleaning cache..." << endl;
121 data::RecordId id = store.lookupRepository(info.alias());
123 CombinedProgressData subprogrcv(progress);
125 store.cleanRepository(id, subprogrcv);
128 ////////////////////////////////////////////////////////////////////////////
131 * Reads RepoInfo's from a repo file.
133 * \param file pathname of the file to read.
135 static std::list<RepoInfo> repositories_in_file( const Pathname & file )
137 MIL << "repo file: " << file << endl;
138 RepoCollector collector;
139 parser::RepoFileReader parser( file, bind( &RepoCollector::collect, &collector, _1 ) );
140 return collector.repos;
143 ////////////////////////////////////////////////////////////////////////////
145 std::list<RepoInfo> readRepoFile(const Url & repo_file)
147 // no interface to download a specific file, using workaround:
148 //! \todo add MediaManager::provideFile(Url file_url) to easily access any file URLs? (no need for media access id or media_nr)
150 Pathname path(url.getPathName());
151 url.setPathName ("/");
152 MediaSetAccess access(url);
153 Pathname local = access.provideFile(path);
155 DBG << "reading repo file " << repo_file << ", local path: " << local << endl;
157 return repositories_in_file(local);
160 ////////////////////////////////////////////////////////////////////////////
163 * \short List of RepoInfo's from a directory
165 * Goes trough every file in a directory and adds all
166 * RepoInfo's contained in that file.
168 * \param dir pathname of the directory to read.
170 static std::list<RepoInfo> repositories_in_dir( const Pathname &dir )
172 MIL << "directory " << dir << endl;
173 list<RepoInfo> repos;
174 list<Pathname> entries;
175 if ( filesystem::readdir( entries, Pathname(dir), false ) != 0 )
176 ZYPP_THROW(Exception("failed to read directory"));
178 for ( list<Pathname>::const_iterator it = entries.begin(); it != entries.end(); ++it )
180 list<RepoInfo> tmp = repositories_in_file( *it );
181 repos.insert( repos.end(), tmp.begin(), tmp.end() );
183 //std::copy( collector.repos.begin(), collector.repos.end(), std::back_inserter(repos));
184 //MIL << "ok" << endl;
189 ////////////////////////////////////////////////////////////////////////////
191 static void assert_alias( const RepoInfo &info )
193 if (info.alias().empty())
194 ZYPP_THROW(RepoNoAliasException());
197 ////////////////////////////////////////////////////////////////////////////
199 static void assert_urls( const RepoInfo &info )
201 if (info.baseUrlsEmpty())
202 ZYPP_THROW(RepoNoUrlException());
205 ////////////////////////////////////////////////////////////////////////////
208 * \short Calculates the raw cache path for a repository
210 static Pathname rawcache_path_for_repoinfo( const RepoManagerOptions &opt, const RepoInfo &info )
213 return opt.repoRawCachePath + info.alias();
216 ///////////////////////////////////////////////////////////////////
218 // CLASS NAME : RepoManager::Impl
220 ///////////////////////////////////////////////////////////////////
223 * \short RepoManager implementation.
225 struct RepoManager::Impl
227 Impl( const RepoManagerOptions &opt )
238 RepoManagerOptions options;
241 /** Offer default Impl. */
242 static shared_ptr<Impl> nullimpl()
244 static shared_ptr<Impl> _nullimpl( new Impl );
249 friend Impl * rwcowClone<Impl>( const Impl * rhs );
250 /** clone for RWCOW_pointer */
252 { return new Impl( *this ); }
254 ///////////////////////////////////////////////////////////////////
256 /** \relates RepoManager::Impl Stream output */
257 inline std::ostream & operator<<( std::ostream & str, const RepoManager::Impl & obj )
259 return str << "RepoManager::Impl";
262 ///////////////////////////////////////////////////////////////////
264 // CLASS NAME : RepoManager
266 ///////////////////////////////////////////////////////////////////
268 RepoManager::RepoManager( const RepoManagerOptions &opt )
269 : _pimpl( new Impl(opt) )
272 ////////////////////////////////////////////////////////////////////////////
274 RepoManager::~RepoManager()
277 ////////////////////////////////////////////////////////////////////////////
279 std::list<RepoInfo> RepoManager::knownRepositories() const
283 if ( PathInfo(_pimpl->options.knownReposPath).isExist() )
285 RepoInfoList repos = repositories_in_dir(_pimpl->options.knownReposPath);
286 for ( RepoInfoList::iterator it = repos.begin();
290 // set the metadata path for the repo
291 Pathname metadata_path = rawcache_path_for_repoinfo(_pimpl->options, (*it));
292 (*it).setMetadataPath(metadata_path);
297 return std::list<RepoInfo>();
302 ////////////////////////////////////////////////////////////////////////////
304 RepoStatus RepoManager::metadataStatus( const RepoInfo &info ) const
306 Pathname rawpath = rawcache_path_for_repoinfo( _pimpl->options, info );
307 RepoType repokind = info.type();
310 switch ( repokind.toEnum() )
312 case RepoType::NONE_e:
313 // unknown, probe the local metadata
314 repokind = probe(rawpath.asUrl());
320 switch ( repokind.toEnum() )
322 case RepoType::RPMMD_e :
324 status = RepoStatus( rawpath + "/repodata/repomd.xml");
328 case RepoType::YAST2_e :
330 status = RepoStatus( rawpath + "/content");
334 case RepoType::RPMPLAINDIR_e :
336 if ( PathInfo(Pathname(rawpath + "/cookie")).isExist() )
337 status = RepoStatus( rawpath + "/cookie");
341 case RepoType::NONE_e :
342 // Return default RepoStatus in case of RepoType::NONE
343 // indicating it should be created?
344 // ZYPP_THROW(RepoUnknownTypeException());
350 void RepoManager::refreshMetadata( const RepoInfo &info,
351 RawMetadataRefreshPolicy policy,
352 const ProgressData::ReceiverFnc & progress )
357 RepoStatus oldstatus;
358 RepoStatus newstatus;
359 // try urls one by one
360 for ( RepoInfo::urls_const_iterator it = info.baseUrlsBegin(); it != info.baseUrlsEnd(); ++it )
366 MIL << "Going to try to check and refresh metadata from " << url << endl;
368 repo::RepoType repokind = info.type();
370 // if the type is unknown, try probing.
371 switch ( repokind.toEnum() )
373 case RepoType::NONE_e:
375 repokind = probe(*it);
381 Pathname rawpath = rawcache_path_for_repoinfo( _pimpl->options, info );
382 filesystem::assert_dir(rawpath);
383 oldstatus = metadataStatus(info);
385 // create temp dir as sibling of rawpath
386 filesystem::TmpDir tmpdir( filesystem::TmpDir::makeSibling( rawpath ) );
388 if ( ( repokind.toEnum() == RepoType::RPMMD_e ) ||
389 ( repokind.toEnum() == RepoType::YAST2_e ) )
391 MediaSetAccess media(url);
392 shared_ptr<repo::Downloader> downloader_ptr;
394 if ( repokind.toEnum() == RepoType::RPMMD_e )
395 downloader_ptr.reset(new yum::Downloader(info.path()));
397 downloader_ptr.reset( new susetags::Downloader(info.path()));
400 * Given a downloader, sets the other repos raw metadata
401 * path as cache paths for the fetcher, so if another
402 * repo has the same file, it will not download it
403 * but copy it from the other repository
405 std::list<RepoInfo> repos = knownRepositories();
406 for ( std::list<RepoInfo>::const_iterator it = repos.begin();
410 downloader_ptr->addCachePath(rawcache_path_for_repoinfo( _pimpl->options, *it ));
413 RepoStatus newstatus = downloader_ptr->status(media);
414 bool refresh = false;
415 if ( oldstatus.checksum() == newstatus.checksum() )
417 MIL << "repo has not changed" << endl;
418 if ( policy == RefreshForced )
420 MIL << "refresh set to forced" << endl;
426 MIL << "repo has changed, going to refresh" << endl;
430 downloader_ptr->download( media, tmpdir.path());
435 else if ( repokind.toEnum() == RepoType::RPMPLAINDIR_e )
437 RepoStatus newstatus = parser::plaindir::dirStatus(url.getPathName());
438 bool refresh = false;
439 if ( oldstatus.checksum() == newstatus.checksum() )
441 MIL << "repo has not changed" << endl;
442 if ( policy == RefreshForced )
444 MIL << "refresh set to forced" << endl;
450 MIL << "repo has changed, going to refresh" << endl;
456 std::ofstream file(( tmpdir.path() + "/cookie").c_str());
458 ZYPP_THROW (Exception( "Can't open " + tmpdir.path().asString() + "/cookie" ) );
461 file << newstatus.checksum() << endl;
471 ZYPP_THROW(RepoUnknownTypeException());
474 // ok we have the metadata, now exchange
476 TmpDir oldmetadata( TmpDir::makeSibling( rawpath ) );
477 filesystem::rename( rawpath, oldmetadata.path() );
478 // move the just downloaded there
479 filesystem::rename( tmpdir.path(), rawpath );
483 catch ( const Exception &e )
486 ERR << "Trying another url..." << endl;
489 ERR << "No more urls..." << endl;
490 ZYPP_THROW(RepoException(_("Valid metadata not found at specified URL(s)")));
493 ////////////////////////////////////////////////////////////////////////////
495 void RepoManager::cleanMetadata( const RepoInfo &info,
496 const ProgressData::ReceiverFnc & progress )
498 filesystem::recursive_rmdir(rawcache_path_for_repoinfo(_pimpl->options, info));
501 void RepoManager::buildCache( const RepoInfo &info,
502 CacheBuildPolicy policy,
503 const ProgressData::ReceiverFnc & progressrcv )
505 ProgressData progress(100);
506 callback::SendReport<ProgressReport> report;
507 progress.sendTo( ProgressReportAdaptor( progressrcv, report ) );
508 progress.name(str::form(_("Building repository '%s' cache"), info.alias().c_str()));
512 Pathname rawpath = rawcache_path_for_repoinfo(_pimpl->options, info);
514 cache::CacheStore store(_pimpl->options.repoCachePath);
516 RepoStatus raw_metadata_status = metadataStatus(info);
517 if ( raw_metadata_status.empty() )
519 ZYPP_THROW(RepoMetadataException(info));
522 if ( store.isCached( info.alias() ) )
524 MIL << info.alias() << " is already cached." << endl;
525 data::RecordId id = store.lookupRepository(info.alias());
526 RepoStatus cache_status = store.repositoryStatus(id);
528 if ( cache_status.checksum() == raw_metadata_status.checksum() )
530 MIL << info.alias() << " cache is up to date with metadata." << endl;
531 if ( policy == BuildIfNeeded ) {
536 MIL << info.alias() << " cache rebuild is forced" << endl;
540 cleanCacheInternal( store, info);
543 MIL << info.alias() << " building cache..." << endl;
544 data::RecordId id = store.lookupOrAppendRepository(info.alias());
546 repo::RepoType repokind = info.type();
548 // if the type is unknown, try probing.
549 switch ( repokind.toEnum() )
551 case RepoType::NONE_e:
552 // unknown, probe the local metadata
553 repokind = probe(rawpath.asUrl());
559 CombinedProgressData subprogrcv( progress, 100);
561 switch ( repokind.toEnum() )
563 case RepoType::RPMMD_e :
565 parser::yum::RepoParser parser(id, store, parser::yum::RepoParserOpts(), subprogrcv);
566 parser.parse(rawpath);
570 case RepoType::YAST2_e :
572 parser::susetags::RepoParser parser(id, store, subprogrcv);
573 parser.parse(rawpath);
577 case RepoType::RPMPLAINDIR_e :
579 InputStream is(rawpath + "cookie");
581 getline( is.stream(), buffer);
583 parser::plaindir::RepoParser parser(id, store, subprogrcv);
584 parser.parse(url.getPathName());
588 ZYPP_THROW(RepoUnknownTypeException());
591 // update timestamp and checksum
592 store.updateRepositoryStatus(id, raw_metadata_status);
594 MIL << "Commit cache.." << endl;
599 ////////////////////////////////////////////////////////////////////////////
601 repo::RepoType RepoManager::probe( const Url &url ) const
603 if ( url.getScheme() == "dir" && ! PathInfo( url.getPathName() ).isDir() )
605 // Handle non existing local directory in advance, as
606 // MediaSetAccess does not support it.
607 return repo::RepoType::NONE;
612 MediaSetAccess access(url);
613 if ( access.doesFileExist("/repodata/repomd.xml") )
614 return repo::RepoType::RPMMD;
615 if ( access.doesFileExist("/content") )
616 return repo::RepoType::YAST2;
618 // if it is a local url of type dir
619 if ( (! media::MediaManager::downloads(url)) && ( url.getScheme() == "dir" ) )
621 Pathname path = Pathname(url.getPathName());
622 if ( PathInfo(path).isDir() )
624 // allow empty dirs for now
625 return repo::RepoType::RPMPLAINDIR;
629 catch ( const media::MediaException &e )
632 RepoException enew("Error trying to read from " + url.asString());
636 catch ( const Exception &e )
639 Exception enew("Unknown error reading from " + url.asString());
644 return repo::RepoType::NONE;
647 ////////////////////////////////////////////////////////////////////////////
649 void RepoManager::cleanCache( const RepoInfo &info,
650 const ProgressData::ReceiverFnc & progressrcv )
652 cache::CacheStore store(_pimpl->options.repoCachePath);
653 cleanCacheInternal( store, info, progressrcv );
657 ////////////////////////////////////////////////////////////////////////////
659 bool RepoManager::isCached( const RepoInfo &info ) const
661 cache::CacheStore store(_pimpl->options.repoCachePath);
662 return store.isCached(info.alias());
665 RepoStatus RepoManager::cacheStatus( const RepoInfo &info ) const
667 cache::CacheStore store(_pimpl->options.repoCachePath);
668 data::RecordId id = store.lookupRepository(info.alias());
669 RepoStatus cache_status = store.repositoryStatus(id);
673 Repository RepoManager::createFromCache( const RepoInfo &info,
674 const ProgressData::ReceiverFnc & progressrcv )
676 callback::SendReport<ProgressReport> report;
677 ProgressData progress;
678 progress.sendTo(ProgressReportAdaptor( progressrcv, report ));
679 //progress.sendTo( progressrcv );
680 progress.name(str::form(_("Reading repository '%s' cache"), info.alias().c_str()));
682 cache::CacheStore store(_pimpl->options.repoCachePath);
684 if ( ! store.isCached( info.alias() ) )
685 ZYPP_THROW(RepoNotCachedException());
687 MIL << "Repository " << info.alias() << " is cached" << endl;
689 data::RecordId id = store.lookupRepository(info.alias());
691 CombinedProgressData subprogrcv(progress);
693 repo::cached::RepoOptions opts( info, _pimpl->options.repoCachePath, id );
694 opts.readingResolvablesProgress = subprogrcv;
695 repo::cached::RepoImpl::Ptr repoimpl =
696 new repo::cached::RepoImpl( opts );
698 repoimpl->resolvables();
699 // read the resolvables from cache
700 return Repository(repoimpl);
703 ////////////////////////////////////////////////////////////////////////////
706 * Generate a non existing filename in a directory, using a base
707 * name. For example if a directory contains 3 files
713 * If you try to generate a unique filename for this directory,
714 * based on "ruu" you will get "ruu", but if you use the base
715 * "foo" you will get "foo_1"
717 * \param dir Directory where the file needs to be unique
718 * \param basefilename string to base the filename on.
720 static Pathname generate_non_existing_name( const Pathname &dir,
721 const std::string &basefilename )
723 string final_filename = basefilename;
725 while ( PathInfo(dir + final_filename).isExist() )
727 final_filename = basefilename + "_" + str::numstring(counter);
730 return dir + Pathname(final_filename);
733 ////////////////////////////////////////////////////////////////////////////
736 * \short Generate a related filename from a repo info
738 * From a repo info, it will try to use the alias as a filename
739 * escaping it if necessary. Other fallbacks can be added to
740 * this function in case there is no way to use the alias
742 static std::string generate_filename( const RepoInfo &info )
746 std::string filename = info.alias();
747 // replace slashes with underscores
748 size_t pos = filename.find(fnd);
749 while(pos!=string::npos)
751 filename.replace(pos,fnd.length(),rep);
752 pos = filename.find(fnd,pos+rep.length());
754 filename = Pathname(filename).extend(".repo").asString();
755 MIL << "generating filename for repo [" << info.alias() << "] : '" << filename << "'" << endl;
760 ////////////////////////////////////////////////////////////////////////////
762 void RepoManager::addRepository( const RepoInfo &info,
763 const ProgressData::ReceiverFnc & progressrcv )
767 ProgressData progress(100);
768 callback::SendReport<ProgressReport> report;
769 progress.sendTo( ProgressReportAdaptor( progressrcv, report ) );
770 progress.name(str::form(_("Adding repository '%s'"), info.alias().c_str()));
773 std::list<RepoInfo> repos = knownRepositories();
774 for ( std::list<RepoInfo>::const_iterator it = repos.begin();
778 if ( info.alias() == (*it).alias() )
779 ZYPP_THROW(RepoAlreadyExistsException(info.alias()));
782 RepoInfo tosave = info;
784 // check the first url for now
785 if ( ZConfig::instance().repo_add_probe() || ( tosave.type() == RepoType::NONE ) )
788 probedtype = probe(*tosave.baseUrlsBegin());
789 if ( tosave.baseUrlsSize() > 0 )
791 if ( probedtype == RepoType::NONE )
792 ZYPP_THROW(RepoUnknownTypeException());
794 tosave.setType(probedtype);
800 // assert the directory exists
801 filesystem::assert_dir(_pimpl->options.knownReposPath);
803 Pathname repofile = generate_non_existing_name(_pimpl->options.knownReposPath,
804 generate_filename(tosave));
805 // now we have a filename that does not exists
806 MIL << "Saving repo in " << repofile << endl;
808 std::ofstream file(repofile.c_str());
810 ZYPP_THROW (Exception( "Can't open " + repofile.asString() ) );
813 tosave.dumpRepoOn(file);
815 MIL << "done" << endl;
818 void RepoManager::addRepositories( const Url &url,
819 const ProgressData::ReceiverFnc & progressrcv )
821 std::list<RepoInfo> knownrepos = knownRepositories();
822 std::list<RepoInfo> repos = readRepoFile(url);
823 for ( std::list<RepoInfo>::const_iterator it = repos.begin();
827 // look if the alias is in the known repos.
828 for ( std::list<RepoInfo>::const_iterator kit = knownrepos.begin();
829 kit != knownrepos.end();
832 if ( (*it).alias() == (*kit).alias() )
834 ERR << "To be added repo " << (*it).alias() << " conflicts with existing repo " << (*kit).alias() << endl;
835 ZYPP_THROW(RepoAlreadyExistsException((*it).alias()));
840 string filename = Pathname(url.getPathName()).basename();
842 if ( filename == Pathname() )
843 ZYPP_THROW(RepoException("Invalid repo file name at " + url.asString() ));
845 // assert the directory exists
846 filesystem::assert_dir(_pimpl->options.knownReposPath);
848 Pathname repofile = generate_non_existing_name(_pimpl->options.knownReposPath, filename);
849 // now we have a filename that does not exists
850 MIL << "Saving " << repos.size() << " repo" << ( repos.size() ? "s" : "" ) << " in " << repofile << endl;
852 std::ofstream file(repofile.c_str());
854 ZYPP_THROW (Exception( "Can't open " + repofile.asString() ) );
857 for ( std::list<RepoInfo>::const_iterator it = repos.begin();
861 MIL << "Saving " << (*it).alias() << endl;
862 (*it).dumpRepoOn(file);
864 MIL << "done" << endl;
867 ////////////////////////////////////////////////////////////////////////////
869 void RepoManager::removeRepository( const RepoInfo & info,
870 const ProgressData::ReceiverFnc & progressrcv)
872 ProgressData progress;
873 callback::SendReport<ProgressReport> report;
874 progress.sendTo( ProgressReportAdaptor( progressrcv, report ) );
875 progress.name(str::form(_("Removing repository '%s'"), info.alias().c_str()));
877 MIL << "Going to delete repo " << info.alias() << endl;
879 std::list<RepoInfo> repos = knownRepositories();
880 for ( std::list<RepoInfo>::const_iterator it = repos.begin();
884 // they can be the same only if the provided is empty, that means
885 // the provided repo has no alias
887 if ( (!info.alias().empty()) && ( info.alias() != (*it).alias() ) )
892 // we have a matcing repository, now we need to know
893 // where it does come from.
894 RepoInfo todelete = *it;
895 if (todelete.filepath().empty())
897 ZYPP_THROW(RepoException("Can't figure where the repo is stored"));
901 // figure how many repos are there in the file:
902 std::list<RepoInfo> filerepos = repositories_in_file(todelete.filepath());
903 if ( (filerepos.size() == 1) && ( filerepos.front().alias() == todelete.alias() ) )
905 // easy, only this one, just delete the file
906 if ( filesystem::unlink(todelete.filepath()) != 0 )
908 ZYPP_THROW(RepoException("Can't delete " + todelete.filepath().asString()));
910 MIL << todelete.alias() << " sucessfully deleted." << endl;
914 // there are more repos in the same file
915 // write them back except the deleted one.
917 //std::ofstream file(tmp.path().c_str());
919 // assert the directory exists
920 filesystem::assert_dir(todelete.filepath().dirname());
922 std::ofstream file(todelete.filepath().c_str());
924 //ZYPP_THROW (Exception( "Can't open " + tmp.path().asString() ) );
925 ZYPP_THROW (Exception( "Can't open " + todelete.filepath().asString() ) );
927 for ( std::list<RepoInfo>::const_iterator fit = filerepos.begin();
928 fit != filerepos.end();
931 if ( (*fit).alias() != todelete.alias() )
932 (*fit).dumpRepoOn(file);
936 CombinedProgressData subprogrcv(progress);
938 // now delete it from cache
939 cleanCache( todelete, subprogrcv);
941 MIL << todelete.alias() << " sucessfully deleted." << endl;
943 } // else filepath is empty
946 // should not be reached on a sucess workflow
947 ZYPP_THROW(RepoNotFoundException(info));
950 ////////////////////////////////////////////////////////////////////////////
952 void RepoManager::modifyRepository( const std::string &alias,
953 const RepoInfo & newinfo,
954 const ProgressData::ReceiverFnc & progressrcv )
956 RepoInfo toedit = getRepositoryInfo(alias);
958 if (toedit.filepath().empty())
960 ZYPP_THROW(RepoException("Can't figure where the repo is stored"));
964 // figure how many repos are there in the file:
965 std::list<RepoInfo> filerepos = repositories_in_file(toedit.filepath());
967 // there are more repos in the same file
968 // write them back except the deleted one.
970 //std::ofstream file(tmp.path().c_str());
972 // assert the directory exists
973 filesystem::assert_dir(toedit.filepath().dirname());
975 std::ofstream file(toedit.filepath().c_str());
977 //ZYPP_THROW (Exception( "Can't open " + tmp.path().asString() ) );
978 ZYPP_THROW (Exception( "Can't open " + toedit.filepath().asString() ) );
980 for ( std::list<RepoInfo>::const_iterator fit = filerepos.begin();
981 fit != filerepos.end();
984 // if the alias is different, dump the original
985 // if it is the same, dump the provided one
986 if ( (*fit).alias() != toedit.alias() )
987 (*fit).dumpRepoOn(file);
989 newinfo.dumpRepoOn(file);
994 ////////////////////////////////////////////////////////////////////////////
996 RepoInfo RepoManager::getRepositoryInfo( const std::string &alias,
997 const ProgressData::ReceiverFnc & progressrcv )
999 std::list<RepoInfo> repos = knownRepositories();
1000 for ( std::list<RepoInfo>::const_iterator it = repos.begin();
1004 if ( (*it).alias() == alias )
1008 info.setAlias(info.alias());
1009 ZYPP_THROW(RepoNotFoundException(info));
1012 ////////////////////////////////////////////////////////////////////////////
1014 RepoInfo RepoManager::getRepositoryInfo( const Url & url,
1015 const url::ViewOption & urlview,
1016 const ProgressData::ReceiverFnc & progressrcv )
1018 std::list<RepoInfo> repos = knownRepositories();
1019 for ( std::list<RepoInfo>::const_iterator it = repos.begin();
1023 for(RepoInfo::urls_const_iterator urlit = (*it).baseUrlsBegin();
1024 urlit != (*it).baseUrlsEnd();
1027 if ((*urlit).asString(urlview) == url.asString(urlview))
1032 info.setAlias(info.alias());
1033 info.setBaseUrl(url);
1034 ZYPP_THROW(RepoNotFoundException(info));
1037 ////////////////////////////////////////////////////////////////////////////
1039 std::ostream & operator<<( std::ostream & str, const RepoManager & obj )
1041 return str << *obj._pimpl;
1044 /////////////////////////////////////////////////////////////////
1046 ///////////////////////////////////////////////////////////////////