18#include <zypp-core/base/Logger.h>
19#include <zypp-core/base/String.h>
20#include <zypp-core/base/Regex.h>
21#include <zypp-core/base/IOStream.h>
22#include <zypp-core/base/InputStream>
23#include <zypp-core/Pathname.h>
24#include <zypp-core/fs/PathInfo.h>
25#include <zypp-core/fs/TmpPath.h>
36 DBG <<
"Load '" <<
_path <<
"'" << endl;
37 std::map<std::string,std::string>
ret;
42 WAR <<
"Unable to load '" <<
_path <<
"'" << endl;
46 while( getline(
in,
line ) ) {
47 if ( *
line.begin() !=
'#' ) {
49 std::string::size_type
pos =
line.find(
'=', 0 );
51 if (
pos != std::string::npos ) {
56 if ( value.length() >= 2
57 && *(value.begin()) ==
'"'
58 && *(value.rbegin()) ==
'"' )
60 value = value.substr( 1, value.length() - 2 );
62 if ( value.length() >= 2
63 && *(value.begin()) ==
'\''
64 && *(value.rbegin()) ==
'\'' )
66 value = value.substr( 1, value.length() - 2 );
68 XXX <<
"KEY: '" << key <<
"' VALUE: '" << value <<
"'" << endl;
76 MIL <<
"done reading '" <<
_path <<
"'" << endl;
84 WAR <<
"Empty key in write " <<
path_r << endl;
91 if ( !
pi.userMayRW() )
98 std::ofstream
o(
tmpf.path().c_str() );
104 o << key_r <<
'=' << val_r << endl;
106 MIL << path_r <<
": " << key_r <<
'=' << val_r <<
" changed on line " << num_r << endl;
116 WAR <<
path_r <<
": " <<
key_r <<
'=' <<
val_r <<
" can not be added (no comment provided)." << endl;
120 std::vector<std::string>
lines;
125 if (
line[0] !=
'#' )
Reference counted access to a Tp object calling a custom Dispose function when the last AutoDispose h...
Convenience errno wrapper.
Base class for Exception.
Wrapper class for stat/lstat.
const std::string & asString() const
String representation.
Provide a new empty temporary file and delete it when no longer needed.
static TmpFile makeSibling(const Pathname &sibling_r)
Provide a new empty temporary directory as sibling.
bool matches(const char *s, str::smatch &matches, int flags=none) const
std::map< std::string, std::string > read(const Pathname &_path)
Read sysconfig file path_r and return (key,valye) pairs.
bool write(const Pathname &path_r, const std::string &key_r, const std::string &val_r, const std::string &newcomment_r)
Add or change a value in sysconfig file path_r.
bool writeStringVal(const Pathname &path_r, const std::string &key_r, const std::string &val_r, const std::string &newcomment_r)
Convenience to add or change a string-value in sysconfig file path_r.
int forEachLine(std::istream &str_r, const function< bool(int, std::string)> &consume_r)
Simple lineparser: Call functor consume_r for each line.
std::string escape(const C_Str &str_r, const char sep_r)
Escape desired character c using a backslash.
unsigned split(const C_Str &line_r, TOutputIterator result_r, const C_Str &sepchars_r=" \t", const Trim trim_r=NO_TRIM)
Split line_r into words.
std::string trim(const std::string &s, const Trim trim_r)
Easy-to use interface to the ZYPP dependency resolver.
Convenient building of std::string via std::ostringstream Basically a std::ostringstream autoconverti...
#define ZYPP_THROW(EXCPT)
Drops a logline and throws the Exception.