libzypp 17.38.3
RepoInfoBase.cc
Go to the documentation of this file.
1/*---------------------------------------------------------------------\
2| ____ _ __ __ ___ |
3| |__ / \ / / . \ . \ |
4| / / \ V /| _/ _/ |
5| / /__ | | | | | | |
6| /_____||_| |_| |_| |
7| |
8\---------------------------------------------------------------------*/
12#include <iostream>
13#include <optional>
14
15#include <zypp/ZConfig.h>
17
19#include <zypp-core/Pathname.h>
20
21using std::endl;
22
24namespace zypp
25{
27 namespace repo
28 {
29
35 {
37 {}
38
39 Impl( const std::string & alias_r )
40 { setAlias( alias_r ); }
41
42 public:
43 bool _enabled = true;
44 bool _autorefresh = false;
45 std::string _alias;
46 std::optional<std::string> _escaped_alias;
49
50 public:
51
52 void setAlias( const std::string & alias_r )
53 {
54 _alias = alias_r;
55 if ( _alias.find( "/" ) != std::string::npos ) {
56 // replace slashes with underscores
58 str::replaceAll( *_escaped_alias, "/", "_" );
59 } else {
60 _escaped_alias.reset();
61 }
62 }
63
64 private:
65 friend Impl * rwcowClone<Impl>( const Impl * rhs );
67 Impl * clone() const
68 { return new Impl( *this ); }
69 };
70
71
73 //
74 // CLASS NAME : RepoInfoBase
75 //
77
79 : _pimpl( new Impl() )
80 {}
81
82 RepoInfoBase::RepoInfoBase(const std::string & alias)
83 : _pimpl( new Impl(alias) )
84 {}
85
88
90 { _pimpl->_enabled = enabled; }
91
93 { _pimpl->_autorefresh = autorefresh; }
94
95 void RepoInfoBase::setAlias( const std::string &alias )
96 { _pimpl->setAlias(alias); }
97
98 void RepoInfoBase::setName( const std::string &name )
99 { _pimpl->_name.raw() = name; }
100
102 { _pimpl->_filepath = filepath; }
103
105 { return _pimpl->_enabled; }
106
108 { return _pimpl->_autorefresh; }
109
110 std::string RepoInfoBase::alias() const
111 { return _pimpl->_alias; }
112
113 std::string RepoInfoBase::escaped_alias() const
114 { return _pimpl->_escaped_alias ? *_pimpl->_escaped_alias : _pimpl->_alias; }
115
116 std::string RepoInfoBase::name() const
117 {
118 if ( rawName().empty() )
119 return alias();
121 }
122
123 std::string RepoInfoBase::rawName() const
124 { return _pimpl->_name.raw(); }
125
126 std::string RepoInfoBase::label() const
127 {
128 if ( ZConfig::instance().repoLabelIsAlias() )
129 return alias();
130 return name();
131 }
132
134 { return _pimpl->_filepath; }
135
136
137 std::ostream & RepoInfoBase::dumpOn( std::ostream & str ) const
138 {
139 str << "--------------------------------------" << std::endl;
140 str << "- alias : " << alias() << std::endl;
141 if ( ! rawName().empty() )
142 str << "- name : " << rawName() << std::endl;
143 str << "- enabled : " << enabled() << std::endl;
144 str << "- autorefresh : " << autorefresh() << std::endl;
145
146 return str;
147 }
148
149 std::ostream & RepoInfoBase::dumpAsIniOn( std::ostream & str ) const
150 {
151 // we save the original data without variable replacement
152 str << "[" << alias() << "]" << endl;
153 if ( ! rawName().empty() )
154 str << "name=" << rawName() << endl;
155 str << "enabled=" << (enabled() ? "1" : "0") << endl;
156 str << "autorefresh=" << (autorefresh() ? "1" : "0") << endl;
157
158 return str;
159 }
160
161 std::ostream & RepoInfoBase::dumpAsXmlOn( std::ostream & str, const std::string & content ) const
162 {
163 return str << "<!-- there's no XML representation of RepoInfoBase -->" << endl;
164 }
165
166 std::ostream & operator<<( std::ostream & str, const RepoInfoBase & obj )
167 {
168 return obj.dumpOn(str);
169 }
170
171 } // namespace repo
173} // namespace zypp
base::ValueTransform< std::string, repo::RepoVariablesStringReplacer > RepoVariablesReplacedString
Helper managing repo variables replaced strings.
static ZConfig & instance()
Singleton ctor.
Definition ZConfig.cc:971
virtual std::ostream & dumpOn(std::ostream &str) const
Write a human-readable representation of this RepoInfoBase object into the str stream.
std::string label() const
Label for use in messages for the user interface.
void setAutorefresh(bool autorefresh)
enable or disable autorefresh
std::string escaped_alias() const
Same as alias(), just escaped in a way to be a valid file name.
virtual std::ostream & dumpAsIniOn(std::ostream &str) const
Write this RepoInfoBase object into str in a .repo (ini) file format.
void setFilepath(const Pathname &filename)
set the path to the .repo file
void setAlias(const std::string &alias)
set the repository alias
Pathname filepath() const
File where this repo was read from.
void setName(const std::string &name)
set the repository name
bool autorefresh() const
If true, the repostory must be refreshed before creating resolvables from it.
std::string name() const
Repository name.
std::string rawName() const
The raw metadata name (no default, no variables replaced).
virtual std::ostream & dumpAsXmlOn(std::ostream &str, const std::string &content="") const
Write an XML representation of this object with content (if available).
bool enabled() const
If enabled is false, then this repository must be ignored as if does not exists, except when checking...
void setEnabled(bool enabled)
enable or disable the repository
RWCOW_pointer< Impl > _pimpl
Pointer to implementation.
std::string alias() const
unique identifier for this source.
String related utilities and Regular expression matching.
std::ostream & operator<<(std::ostream &str, const DeltaCandidates &obj)
std::string & replaceAll(std::string &str_r, const std::string &from_r, const std::string &to_r)
Replace all occurrences of from_r with to_r in str_r (inplace).
Definition String.cc:333
Easy-to use interface to the ZYPP dependency resolver.
void setAlias(const std::string &alias_r)
std::optional< std::string > _escaped_alias
Impl(const std::string &alias_r)
friend Impl * rwcowClone(const Impl *rhs)
RepoVariablesReplacedString _name
Impl * clone() const
clone for RWCOW_pointer
Functor replacing repository variables.