Mailinglist Archive: zypp-commit (223 mails)

< Previous Next >
[zypp-commit] r10663 - in /trunk/libzypp: tests/zypp/RepoManager_test.cc zypp/RepoManager.cc zypp/RepoManager.h zypp/Service.cc zypp/Service.h zypp/parser/RepoindexFileReader.cc zypp/parser/ServiceFileReader.cc
  • From: jkupec@xxxxxxxxxxxxxxxx
  • Date: Fri, 25 Jul 2008 16:12:14 -0000
  • Message-id: <20080725161214.910E156FD6@xxxxxxxxxxxxxxxx>
Author: jkupec
Date: Fri Jul 25 18:12:14 2008
New Revision: 10663

URL: http://svn.opensuse.org/viewcvs/zypp?rev=10663&view=rev
Log:
- use alias and name in services much like in repos
- should Service be renamed to ServiceInfo (it's very similar to RepoInfo).

Modified:
trunk/libzypp/tests/zypp/RepoManager_test.cc
trunk/libzypp/zypp/RepoManager.cc
trunk/libzypp/zypp/RepoManager.h
trunk/libzypp/zypp/Service.cc
trunk/libzypp/zypp/Service.h
trunk/libzypp/zypp/parser/RepoindexFileReader.cc
trunk/libzypp/zypp/parser/ServiceFileReader.cc

Modified: trunk/libzypp/tests/zypp/RepoManager_test.cc
URL:
http://svn.opensuse.org/viewcvs/zypp/trunk/libzypp/tests/zypp/RepoManager_test.cc?rev=10663&r1=10662&r2=10663&view=diff
==============================================================================
--- trunk/libzypp/tests/zypp/RepoManager_test.cc (original)
+++ trunk/libzypp/tests/zypp/RepoManager_test.cc Fri Jul 25 18:12:14 2008
@@ -96,7 +96,7 @@
service.setUrl(urlS);
service.setEnabled(true);

- manager.modifyService(service.name(),service);
+ manager.modifyService(service.alias(), service);
manager.refreshServices();
BOOST_CHECK_EQUAL(manager.repoSize(), (unsigned) 6); //-1 from new repoindex


Modified: trunk/libzypp/zypp/RepoManager.cc
URL:
http://svn.opensuse.org/viewcvs/zypp/trunk/libzypp/zypp/RepoManager.cc?rev=10663&r1=10662&r2=10663&view=diff
==============================================================================
--- trunk/libzypp/zypp/RepoManager.cc (original)
+++ trunk/libzypp/zypp/RepoManager.cc Fri Jul 25 18:12:14 2008
@@ -264,16 +264,19 @@
void saveService( const Service& service ) const;

Pathname generateNonExistingName( const Pathname &dir,
- const std::string &basefilename )
const;
+ const std::string &basefilename ) const;

std::string generateFilename( const RepoInfo &info ) const;
std::string generateFilename( const Service &info ) const;

- struct ServiceCollector {
- ServiceCollector(ServiceSet& services_) : services(services_) {}
+ struct ServiceCollector
+ {
+ ServiceCollector(ServiceSet & services_) : services(services_) {}
+
bool collect(Service service) { services.insert(service); return true; }
- private:
- ServiceSet& services;
+
+ private:
+ ServiceSet & services;
};

void knownServices();
@@ -1016,12 +1019,12 @@

std::string RepoManager::Impl::generateFilename( const Service &info ) const
{
- std::string filename = info.name();
+ std::string filename = info.alias();
// replace slashes with underscores
str::replaceAll( filename, "/", "_" );

filename = Pathname(filename).extend(".service").asString();
- MIL << "generating filename for service [" << info.name() << "] : '" <<
filename << "'" << endl;
+ MIL << "generating filename for service [" << info.alias() << "] : '" <<
filename << "'" << endl;
return filename;
}

@@ -1304,12 +1307,12 @@
ZYPP_THROW(RepoNotFoundException(info));
}

- void RepoManager::addService( const std::string& name, const Url& url )
+ void RepoManager::addService( const std::string & alias, const Url & url )
{
- addService( Service(name,url) );
+ addService( Service(alias, url) );
}

- void RepoManager::addService( const Service& service )
+ void RepoManager::addService( const Service & service )
{
//check if service isn't already exist
if( _pimpl->services.find(service)!= _pimpl->services.end() )
@@ -1321,11 +1324,11 @@
_pimpl->saveService( savedService );
}

- void RepoManager::removeService( const string& name)
+ void RepoManager::removeService( const string & alias)
{
- MIL << "Going to delete repo " << name << endl;
+ MIL << "Going to delete repo " << alias << endl;

- const Service& service = getService( name );
+ const Service& service = getService( alias );

Pathname location = service.location();
if( location.empty() )
@@ -1345,7 +1348,7 @@
{
ZYPP_THROW(RepoException("Can't delete " + location.asString()));
}
- MIL << name << " sucessfully deleted." << endl;
+ MIL << alias << " sucessfully deleted." << endl;
}
else
{
@@ -1357,20 +1360,21 @@

for_(it, tmpSet.begin(), tmpSet.end())
{
- if( it->name() != name )
+ if( it->alias() != alias )
it->dumpServiceOn(file);
}

- MIL << name << " sucessfully deleted from file " << location << endl;
+ MIL << alias << " sucessfully deleted from file " << location << endl;
}

//now remove all repositories added by this service
- getRepositoriesInService( name,
-
boost::make_function_output_iterator(bind(&RepoManager::removeRepository, this,
_1, ProgressData::ReceiverFnc()) ) );
+ getRepositoriesInService( alias,
+ boost::make_function_output_iterator(
+ bind(&RepoManager::removeRepository, this, _1,
ProgressData::ReceiverFnc()) ) );
}


- void RepoManager::Impl::saveService( const Service& service ) const
+ void RepoManager::Impl::saveService( const Service & service ) const
{
filesystem::assert_dir( options.knownServicesPath );

@@ -1390,9 +1394,9 @@
MIL << "done" << endl;
}

- Service RepoManager::getService( const std::string& name ) const
+ Service RepoManager::getService( const std::string & alias ) const
{
- ServiceConstIterator it = _pimpl->services.find(name);
+ ServiceConstIterator it = _pimpl->services.find(alias);
if ( it == serviceEnd() )
return Service::noService;
else
@@ -1425,16 +1429,20 @@
if ( !it->enabled() )
continue;

- MIL << "refresh: " << it->name() << " with url: "<< it->url().asString()
<< endl;
+ MIL << "refresh: " << it->alias() << " with url: "<<
it->url().asString() << endl;
refreshService(*it);
}
}

- void RepoManager::refreshService( const Service& service )
+ void RepoManager::refreshService( const Service & service )
{
- //download index file
+ //! \todo add callbacks for apps (start, end, repo removed, repo added,
repo changed)
+
+ // download the repo index file
media::MediaManager mediamanager;
- media::MediaAccessId mid = mediamanager.open( service.url() ); //FIXME
check if url is not empty
+ //if (service.url().empty())
+ // throw RepoNoUrlException();
+ media::MediaAccessId mid = mediamanager.open( service.url() );
mediamanager.attachDesiredMedia( mid );
mediamanager.provideFile( mid, "repo/repoindex.xml" );
Pathname path = mediamanager.localPath(mid, "repo/repoindex.xml" );
@@ -1449,19 +1457,20 @@
// set base url for all collected repositories
for_( it, collector.repos.begin(), collector.repos.end())
{
+ //repoUrl = it->baseUrlsBegin();
it->setBaseUrl( service.url() );
- it->setService(service.name());
+ it->setService( service.alias() );
}

- //compare old and new repositories (hope not to much, if it change
+ // compare old and new repositories (hope not to much, if it change
// then construct set and use set operation on it)

std::list<RepoInfo> oldRepos;
- getRepositoriesInService(service.name(),
+ getRepositoriesInService(service.alias(),
insert_iterator<std::list<RepoInfo> >
(oldRepos,oldRepos.begin()));

- //find old to remove
+ // find old to remove
for_( it, oldRepos.begin(), oldRepos.end() )
{
bool found = false;
@@ -1492,19 +1501,19 @@
if (!found)
addRepository( *it );
}
-
}

- void RepoManager::modifyService(const std::string& oldName, const Service&
service)
+ void RepoManager::modifyService(const std::string & oldAlias, const Service
& service)
{
- MIL << "Going to modify service " << oldName << endl;
+ MIL << "Going to modify service " << oldAlias << endl;

- const Service& oldService = getService(oldName);
+ const Service& oldService = getService(oldAlias);

Pathname location = oldService.location();
if( location.empty() )
{
- ZYPP_THROW(RepoException("Can't figure where the service is stored"));
+ ZYPP_THROW(RepoException(
+ "Cannot figure out where the service file is stored."));
}

ServiceSet tmpSet;
@@ -1519,7 +1528,7 @@

for_(it, tmpSet.begin(), tmpSet.end())
{
- if( *it != oldName )
+ if( *it != oldAlias )
it->dumpServiceOn(file);
}

@@ -1527,21 +1536,29 @@

file.close();

- _pimpl->services.erase(oldName);
+ _pimpl->services.erase(oldAlias);
_pimpl->services.insert(service);

- if( oldName != service.name() ) //changed name, must change also repository
+ // changed name, must change also repositories
+ if( oldAlias != service.alias() )
{
std::vector<RepoInfo> toModify;
- getRepositoriesInService(oldName,
+ getRepositoriesInService(oldAlias,
insert_iterator<std::vector<RepoInfo> >( toModify, toModify.begin() ));
for_( it, toModify.begin(), toModify.end() )
{
- it->setService(service.name());
+ it->setService(service.alias());
modifyRepository(it->alias(), *it);
}
}

+ //! \todo changed enabled status
+ if ( oldService.enabled() != service.enabled())
+ {
+
+ }
+
+ //! \todo refresh the service automatically if url is changed?
}

void RepoManager::Impl::knownServices()

Modified: trunk/libzypp/zypp/RepoManager.h
URL:
http://svn.opensuse.org/viewcvs/zypp/trunk/libzypp/zypp/RepoManager.h?rev=10663&r1=10662&r2=10663&view=diff
==============================================================================
--- trunk/libzypp/zypp/RepoManager.h (original)
+++ trunk/libzypp/zypp/RepoManager.h Fri Jul 25 18:12:14 2008
@@ -361,8 +361,11 @@
*
* \throws repo::RepoAlreadyExistsException If the repo clash some
* unique attribute like alias
- * \throws RepoUnknownType If repository type can't be determined
- * \throws RepoException If the access to the url fails (while probing).
+ * \throws RepoUnknownType
+ * If RepoManagerOptions::probe is true
+ * and repository type can't be determined.
+ * \throws RepoException
+ * If RepoManagerOptions::probe is true and access to the url fails.
* \throws Exception On other errors.
*/
void addRepository( const RepoInfo &info,
@@ -373,9 +376,7 @@
* \param url Url of the repo file
*
* \throws repo::RepoAlreadyExistsException If the repo clash some
- * unique attribute like alias
- *
- * \throws RepoAlreadyExistsException
+ * unique attribute like alias
* \throws MediaException If the access to the url fails
* \throws ParseException If the file parsing fails
* \throws RepoUnknownType If repository type can't be determined
@@ -445,19 +446,19 @@
const ProgressData::ReceiverFnc & progressrcv
= ProgressData::ReceiverFnc() );

/**
- * Adds new service by it's name and url
+ * Adds new service by it's alias and url
*
- * \param name unique name of service
+ * \param alias unique identifier of the service
* \param url url to service
*
* \throws FIXME RepoAlreadyExistException and as reponame is service name
*/
- void addService( const std::string& name, const Url& url );
+ void addService( const std::string & alias, const Url& url );

/**
* Adds new service
*
- * \param name service info
+ * \param service service info
*
* \throws FIXME RepoAlreadyExistException and as reponame is service name
*/
@@ -466,12 +467,12 @@
/**
* Removes service specified by its name
*
- * \param name name of service to remove
+ * \param alias unique indientifier of the service to remove
*
* \throws RepoException if service is not found or file with Service
cannot be deleted
* \throws Exception if file contain more services and rewrite file failed
*/
- void removeService( const std::string& name );
+ void removeService( const std::string & alias );

/**
* Gets true if no service is in RepoManager (so no one in specified
location)
@@ -501,51 +502,60 @@
ServiceConstIterator serviceEnd() const;

/**
- * Finds Service by name or return noService
+ * Finds Service by alias or return noService
*
- * \param name unique name of service
+ * \param alias unique identifier of service
* \return information about Service
*/
- Service getService( const std::string& name ) const;
+ Service getService( const std::string & alias ) const;

/**
- * Refreshs all services
- * \see refreshService
+ * Refreshes all enabled services.
+ *
+ * \see refreshService(Service)
*/
void refreshServices();

/**
* Refresh specific service.
- * \throws Exception if cannot download file
+ *
* \param name service structure
+ * \throws MediaException If there's a problem downloading the repo index
file.
*/
- void refreshService( const Service& name );
+ void refreshService( const Service & service );

/**
- * modify service, rewrite Service to filesystem.
- * If change Service name, then can escalate to rewrite all repositories
which it contain.
+ * Modifies service file (rewrites it with new values) and underlying
+ * repositories if needed.
+ *
+ * Modifications of a service can lead to rewrite of all .repo files of
+ * contained repositories. Particularily, disabling a service (changing
+ * Service::enabled() from true to false) will disable all contained
+ * repositories. Renaming of a service will modify the "service" key
+ * of all contained repositories.
*
- * \param oldName oldName of service
- * \param service Structure containing new datas
+ * \param oldAlias Old alias of the service
+ * \param service Service object containing new data
*
- * \throws RepoException if sservice with oldName is not known
+ * \throws RepoException if sservice with oldAlias is not known
* \throws Exception if have problems with files
*/
- void modifyService(const std::string& oldName, const Service& service);
+ void modifyService(const std::string & oldAlias, const Service & service);

- private:
+ private:
/**
* Functor thats filter RepoInfo by service which belongs to.
*/
- struct MatchServiceName {
+ struct MatchServiceAlias
+ {
private:
- std::string name;
+ std::string alias;
public:
- MatchServiceName( const std::string& name_ ) : name(name_) {}
- bool match( const RepoInfo& info ) { return info.service()==name; }
+ MatchServiceAlias( const std::string & alias_ ) : alias(alias_) {}
+ bool match( const RepoInfo & info ) { return info.service() == alias; }
};

- public:
+ public:
/**
* fill to output iterator repositories in service name. This output
iterator can perform
* any action on with Repo or service Container, because it is sets and it
isn't dynamic recreate.
@@ -570,13 +580,14 @@
*/

template<typename OutputIterator>
- void getRepositoriesInService( const std::string& name, OutputIterator out
) const
+ void getRepositoriesInService( const std::string & alias,
+ OutputIterator out ) const
{
- MatchServiceName filter(name);
+ MatchServiceAlias filter(alias);

- std::copy(boost::make_filter_iterator(bind(&MatchServiceName::match,
+ std::copy(boost::make_filter_iterator(bind(&MatchServiceAlias::match,
filter, _1),repoBegin(),repoEnd()), boost::make_filter_iterator(
- bind(&MatchServiceName::match, filter, _1),repoEnd(),repoEnd()),
+ bind(&MatchServiceAlias::match, filter, _1), repoEnd(), repoEnd()),
out );
}


Modified: trunk/libzypp/zypp/Service.cc
URL:
http://svn.opensuse.org/viewcvs/zypp/trunk/libzypp/zypp/Service.cc?rev=10663&r1=10662&r2=10663&view=diff
==============================================================================
--- trunk/libzypp/zypp/Service.cc (original)
+++ trunk/libzypp/zypp/Service.cc Fri Jul 25 18:12:14 2008
@@ -40,14 +40,15 @@
class Service::Impl
{
public:
+ string alias;
string name;
Url url;
DefaultIntegral<bool,false> enabled;
Pathname loc;

- Impl() : name("") {};
- Impl(const string& name_) : name(name_) {};
- Impl(const string& name_, const Url& url_) : name(name_), url(url_) {};
+ Impl() {}
+ Impl(const string & alias_) : alias(alias_) {}
+ Impl(const string & alias_, const Url& url_) : alias(alias_), url(url_) {}

private:
friend Impl * rwcowClone<Impl>( const Impl * rhs );
@@ -60,11 +61,15 @@

const Service Service::noService;

- Service::Service() : _pimpl( new Impl() ) {};
+ Service::Service() : _pimpl( new Impl() ) {}

- Service::Service(const string& name) : _pimpl( new Impl(name) ) {};
- Service::Service(const string& name, const Url& url)
- : _pimpl( new Impl(name,url) ) {};
+ Service::Service(const string & alias) : _pimpl( new Impl(alias) ) {}
+ Service::Service(const string & alias, const Url & url)
+ : _pimpl( new Impl(alias, url) ) {}
+
+
+ string Service::alias() const { return _pimpl->alias; }
+ void Service::setAlias( const std::string & alias ) { _pimpl->alias = alias;
}

string Service::name() const { return _pimpl->name; }
void Service::setName( const std::string& name ) { _pimpl->name = name; }

Modified: trunk/libzypp/zypp/Service.h
URL:
http://svn.opensuse.org/viewcvs/zypp/trunk/libzypp/zypp/Service.h?rev=10663&r1=10662&r2=10663&view=diff
==============================================================================
--- trunk/libzypp/zypp/Service.h (original)
+++ trunk/libzypp/zypp/Service.h Fri Jul 25 18:12:14 2008
@@ -53,6 +53,13 @@
static const Service noService;

public:
+ /**
+ * Gets unique alias.
+ *
+ * \return alias as string
+ */
+ std::string alias() const;
+
/**
* Gets unique name
*
@@ -86,7 +93,14 @@
Pathname location() const;

public:
-
+
+ /**
+ * Sets alias for this service
+ *
+ * \param alias new alias of this service
+ */
+ void setAlias( const std::string & alias );
+
/**
* Sets file where this service is stored.
*

Modified: trunk/libzypp/zypp/parser/RepoindexFileReader.cc
URL:
http://svn.opensuse.org/viewcvs/zypp/trunk/libzypp/zypp/parser/RepoindexFileReader.cc?rev=10663&r1=10662&r2=10663&view=diff
==============================================================================
--- trunk/libzypp/zypp/parser/RepoindexFileReader.cc (original)
+++ trunk/libzypp/zypp/parser/RepoindexFileReader.cc Fri Jul 25 18:12:14 2008
@@ -95,6 +95,7 @@
if ( reader_r->name() == "repo" )
{
RepoInfo info;
+ //! \todo FIXME this hardcodes the "/repo/" fragment - should not be
if we want it to be usable by others!

info.setPath(Pathname(string("/repo/")+reader_r->getAttribute("path").asString()));
info.setAlias(reader_r->getAttribute("alias").asString());
info.setType(repo::RepoType::RPMMD_e); //TODO hardwired rpmmd???

Modified: trunk/libzypp/zypp/parser/ServiceFileReader.cc
URL:
http://svn.opensuse.org/viewcvs/zypp/trunk/libzypp/zypp/parser/ServiceFileReader.cc?rev=10663&r1=10662&r2=10663&view=diff
==============================================================================
--- trunk/libzypp/zypp/parser/ServiceFileReader.cc (original)
+++ trunk/libzypp/zypp/parser/ServiceFileReader.cc Fri Jul 25 18:12:14 2008
@@ -29,10 +29,11 @@
namespace parser
{ /////////////////////////////////////////////////////////////////

- class ServiceFileReader::Impl {
- public:
- static void parseServices( const Pathname &file,
- const ServiceFileReader::ProcessService& callback );
+ class ServiceFileReader::Impl
+ {
+ public:
+ static void parseServices( const Pathname & file,
+ const ServiceFileReader::ProcessService & callback );
};

void ServiceFileReader::Impl::parseServices( const Pathname &file,
@@ -58,16 +59,20 @@
it != dict.entriesEnd(*its);
++it )
{
- //MIL << (*it).first << endl;
- if ( it->first == "url" )
+ // MIL << (*it).first << endl;
+ if ( it->first == "name" )
+ service.setName( it->second );
+ else if ( it->first == "url" )
service.setUrl( Url (it->second) );
else if ( it->first == "enabled" )
service.setEnabled( str::strToTrue( it->second ) );
else
ERR << "Unknown attribute " << it->second << " ignored" << endl;
}
- MIL << "Linking repo info with file " << file << endl;
+
+ MIL << "Linking Service with file " << file << endl;
service.setLocation(file);
+
// add it to the list.
if ( !callback(service) )
ZYPP_THROW(AbortRequestException());

--
To unsubscribe, e-mail: zypp-commit+unsubscribe@xxxxxxxxxxxx
For additional commands, e-mail: zypp-commit+help@xxxxxxxxxxxx

< Previous Next >
This Thread
  • No further messages