libzypp: zypp/repo/RepoInfoBase.cc Source File

libzypp 17.38.9

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>
16#include <zypp/repo/RepoVariables.h>
17
18#include <zypp/repo/RepoInfoBase.h>
19#include <zypp-core/Pathname.h>
20
21using std::endl;
22
24namespace zypp
25{
27 namespace repo
28 {
29
34 struct RepoInfoBase::Impl
35 {
36 Impl()
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;
47 RepoVariablesReplacedString _name;
48 Pathname _filepath;
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
57 _escaped_alias = _alias;
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
78 RepoInfoBase::RepoInfoBase()
79 : _pimpl( new Impl() )
80 {}
81
82 RepoInfoBase::RepoInfoBase(const std::string & alias)
83 : _pimpl( new Impl(alias) )
84 {}
85
86 RepoInfoBase::~RepoInfoBase()
87 {}
88
89 void RepoInfoBase::setEnabled( bool enabled )
90 { _pimpl->_enabled = enabled; }
91
92 void RepoInfoBase::setAutorefresh( bool autorefresh )
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
101 void RepoInfoBase::setFilepath( const Pathname &filepath )
102 { _pimpl->_filepath = filepath; }
103
104 bool RepoInfoBase::enabled() const
105 { return _pimpl->_enabled; }
106
107 bool RepoInfoBase::autorefresh() const
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();
120 return repo::RepoVariablesStringReplacer()( rawName() );
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
133 Pathname RepoInfoBase::filepath() const
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
Pathname.h
RepoInfoBase.h
RepoVariables.h
ZConfig.h
zypp::ZConfig::instance
static ZConfig & instance()
Singleton ctor.
Definition ZConfig.cc:756
zypp::filesystem::Pathname
Pathname.
Definition Pathname.h:48
zypp::repo::RepoInfoBase::dumpOn
virtual std::ostream & dumpOn(std::ostream &str) const
Write a human-readable representation of this RepoInfoBase object into the str stream.
Definition RepoInfoBase.cc:137
zypp::repo::RepoInfoBase::label
std::string label() const
Label for use in messages for the user interface.
Definition RepoInfoBase.cc:126
zypp::repo::RepoInfoBase::setAutorefresh
void setAutorefresh(bool autorefresh)
enable or disable autorefresh
Definition RepoInfoBase.cc:92
zypp::repo::RepoInfoBase::escaped_alias
std::string escaped_alias() const
Same as alias(), just escaped in a way to be a valid file name.
Definition RepoInfoBase.cc:113
zypp::repo::RepoInfoBase::dumpAsIniOn
virtual std::ostream & dumpAsIniOn(std::ostream &str) const
Write this RepoInfoBase object into str in a .repo (ini) file format.
Definition RepoInfoBase.cc:149
zypp::repo::RepoInfoBase::setFilepath
void setFilepath(const Pathname &filename)
set the path to the .repo file
Definition RepoInfoBase.cc:101
zypp::repo::RepoInfoBase::setAlias
void setAlias(const std::string &alias)
set the repository alias
Definition RepoInfoBase.cc:95
zypp::repo::RepoInfoBase::RepoInfoBase
RepoInfoBase()
Definition RepoInfoBase.cc:78
zypp::repo::RepoInfoBase::filepath
Pathname filepath() const
File where this repo was read from.
Definition RepoInfoBase.cc:133
zypp::repo::RepoInfoBase::setName
void setName(const std::string &name)
set the repository name
Definition RepoInfoBase.cc:98
zypp::repo::RepoInfoBase::autorefresh
bool autorefresh() const
If true, the repostory must be refreshed before creating resolvables from it.
Definition RepoInfoBase.cc:107
zypp::repo::RepoInfoBase::name
std::string name() const
Repository name.
Definition RepoInfoBase.cc:116
zypp::repo::RepoInfoBase::rawName
std::string rawName() const
The raw metadata name (no default, no variables replaced).
Definition RepoInfoBase.cc:123
zypp::repo::RepoInfoBase::~RepoInfoBase
virtual ~RepoInfoBase()
Definition RepoInfoBase.cc:86
zypp::repo::RepoInfoBase::dumpAsXmlOn
virtual std::ostream & dumpAsXmlOn(std::ostream &str, const std::string &content="") const
Write an XML representation of this object with content (if available).
Definition RepoInfoBase.cc:161
zypp::repo::RepoInfoBase::enabled
bool enabled() const
If enabled is false, then this repository must be ignored as if does not exists, except when checking...
Definition RepoInfoBase.cc:104
zypp::repo::RepoInfoBase::setEnabled
void setEnabled(bool enabled)
enable or disable the repository
Definition RepoInfoBase.cc:89
zypp::repo::RepoInfoBase::_pimpl
RWCOW_pointer< Impl > _pimpl
Pointer to implementation.
Definition RepoInfoBase.h:168
zypp::repo::RepoInfoBase::alias
std::string alias() const
unique identifier for this source.
Definition RepoInfoBase.cc:110
str
String related utilities and Regular expression matching.
zypp::repo
Definition DeltaCandidates.cc:30
zypp::repo::operator<<
std::ostream & operator<<(std::ostream &str, const DeltaCandidates::Impl &obj)
relates: DeltaCandidates::Impl Stream output
Definition DeltaCandidates.cc:55
zypp::str::replaceAll
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
zypp
Easy-to use interface to the ZYPP dependency resolver.
Definition CodePitfalls.doc:2
zypp::RepoVariablesReplacedString
base::ValueTransform< std::string, repo::RepoVariablesStringReplacer > RepoVariablesReplacedString
relates: RepoVariablesStringReplacer Helper managing repo variables replaced strings
Definition RepoVariables.h:127
zypp::repo::RepoInfoBase::Impl
RepoInfoBase data.
Definition RepoInfoBase.cc:35
zypp::repo::RepoInfoBase::Impl::setAlias
void setAlias(const std::string &alias_r)
Definition RepoInfoBase.cc:52
zypp::repo::RepoInfoBase::Impl::_escaped_alias
std::optional< std::string > _escaped_alias
Definition RepoInfoBase.cc:46
zypp::repo::RepoInfoBase::Impl::Impl
Impl()
Definition RepoInfoBase.cc:36
zypp::repo::RepoInfoBase::Impl::Impl
Impl(const std::string &alias_r)
Definition RepoInfoBase.cc:39
zypp::repo::RepoInfoBase::Impl::_enabled
bool _enabled
Definition RepoInfoBase.cc:43
zypp::repo::RepoInfoBase::Impl::rwcowClone
friend Impl * rwcowClone(const Impl *rhs)
zypp::repo::RepoInfoBase::Impl::_alias
std::string _alias
Definition RepoInfoBase.cc:45
zypp::repo::RepoInfoBase::Impl::_name
RepoVariablesReplacedString _name
Definition RepoInfoBase.cc:47
zypp::repo::RepoInfoBase::Impl::_filepath
Pathname _filepath
Definition RepoInfoBase.cc:48
zypp::repo::RepoInfoBase::Impl::clone
Impl * clone() const
clone for RWCOW_pointer
Definition RepoInfoBase.cc:67
zypp::repo::RepoInfoBase::Impl::_autorefresh
bool _autorefresh
Definition RepoInfoBase.cc:44
zypp::repo::RepoVariablesStringReplacer
Functor replacing repository variables.
Definition RepoVariables.h:106