/
SystemCheck.cc
170 lines (144 loc) · 4.87 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
/*---------------------------------------------------------------------\
| ____ _ __ __ ___ |
| |__ / \ / / . \ . \ |
| / / \ V /| _/ _/ |
| / /__ | | | | | | |
| /_____||_| |_| |_| |
| |
\---------------------------------------------------------------------*/
/** \file zypp/solver/detail/SystemCheck.cc
*
*/
#include <iostream>
#include <fstream>
#include <vector>
#include "zypp/base/LogTools.h"
#include "zypp/base/IOStream.h"
#include "zypp/base/String.h"
#include "zypp/ZYppFactory.h"
#include "zypp/ZConfig.h"
#include "zypp/Pathname.h"
#include "zypp/PathInfo.h"
#include "zypp/solver/detail/SystemCheck.h"
using namespace std;
///////////////////////////////////////////////////////////////////
namespace zypp
{ /////////////////////////////////////////////////////////////////
Pathname _file = "";
33
Pathname _dir = "";
34
35
36
37
38
39
40
41
42
43
44
45
CapabilitySet _require;
CapabilitySet _conflict;
typedef vector<string> CapList;
const SystemCheck & SystemCheck::instance()
{
static SystemCheck _val;
return _val;
}
46
SystemCheck::SystemCheck() {
47
48
if (_file.empty()) {
_file = ZConfig::instance().solver_checkSystemFile();
49
loadFile(_file);
51
52
53
54
if (_dir.empty()) {
_dir = ZConfig::instance().solver_checkSystemFileDir();
loadFiles();
}
55
56
57
58
59
}
bool SystemCheck::setFile(const Pathname & file) const{
MIL << "Setting checkFile to : " << file << endl;
_file = file;
60
loadFile(_file);
61
62
63
return true;
}
64
65
66
67
68
69
70
71
bool SystemCheck::setDir(const Pathname & dir) const {
MIL << "Setting checkFile directory to : " << dir << endl;
loadFile(_file);
_dir = dir;
loadFiles();
return true;
}
72
73
74
75
const Pathname & SystemCheck::file() {
return _file;
}
76
77
78
79
const Pathname & SystemCheck::dir() {
return _dir;
}
80
81
82
83
84
85
86
87
const CapabilitySet & SystemCheck::requiredSystemCap() const{
return _require;
}
const CapabilitySet & SystemCheck::conflictSystemCap() const{
return _conflict;
}
88
bool SystemCheck::loadFile(Pathname & file, bool reset_caps) const{
89
90
Target_Ptr trg( getZYpp()->getTarget() );
if ( trg )
91
file = trg->assertRootPrefix( file );
93
PathInfo pi( file );
94
if ( ! pi.isFile() ) {
95
WAR << "Can't read " << file << " " << pi << endl;
96
97
98
return false;
}
99
100
101
102
if (reset_caps) {
_require.clear();
_conflict.clear();
}
104
std::ifstream infile( file.c_str() );
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
for( iostr::EachLine in( infile ); in; in.next() ) {
std::string l( str::trim(*in) );
if ( ! l.empty() && l[0] != '#' )
{
CapList capList;
str::split( l, back_inserter(capList), ":" );
if (capList.size() == 2 ) {
CapList::iterator it = capList.begin();
if (*it == "requires") {
_require.insert(Capability(*(it+1)));
} else if (*it == "conflicts") {
_conflict.insert(Capability(*(it+1)));
} else {
ERR << "Wrong parameter: " << l << endl;
}
} else {
ERR << "Wrong line: " << l << endl;
}
}
}
MIL << "Read " << pi << endl;
return true;
}
129
130
131
132
133
bool SystemCheck::loadFiles() const {
filesystem::dirForEach(_dir,
[this](const Pathname & dir_r, const char *const & name_r)->bool
{
134
const std::string wanted = ".check";
135
Pathname pth = dir_r/name_r;
136
137
138
139
140
141
142
143
if (pth.extension() != wanted) {
MIL << "Skipping " << pth << " (not a *.check file)" << endl;
return true;
}
else {
MIL << "Reading " << pth << endl;
return loadFile(pth, false /* do not reset caps */);
}
144
145
146
147
});
return true;
}
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
/******************************************************************
**
** FUNCTION NAME : operator<<
** FUNCTION TYPE : std::ostream &
*/
std::ostream & operator<<( std::ostream & str, const SystemCheck & obj )
{
str << _file << endl;
str << "requires" << endl;
for (CapabilitySet::const_iterator it = _require.begin(); it != _require.end(); ++it)
str << " " << *it << endl;
str << "conflicts" << endl;
for (CapabilitySet::const_iterator it = _conflict.begin(); it != _conflict.end(); ++it)
str << " " << *it << endl;
return str;
}
/////////////////////////////////////////////////////////////////
} // namespace zypp
///////////////////////////////////////////////////////////////////