1 /*---------------------------------------------------------------------\
3 | |__ / \ / / . \ . \ |
8 \---------------------------------------------------------------------*/
9 /** \file zypp/solver/detail/SystemCheck.cc
16 #define ZYPP_USE_RESOLVER_INTERNALS
18 #include "zypp/base/LogTools.h"
19 #include "zypp/base/IOStream.h"
20 #include "zypp/base/String.h"
22 #include "zypp/ZYppFactory.h"
23 #include "zypp/ZConfig.h"
24 #include "zypp/Pathname.h"
25 #include "zypp/PathInfo.h"
26 #include "zypp/solver/detail/SystemCheck.h"
30 ///////////////////////////////////////////////////////////////////
32 { /////////////////////////////////////////////////////////////////
36 CapabilitySet _require;
37 CapabilitySet _conflict;
39 typedef vector<string> CapList;
41 const SystemCheck & SystemCheck::instance()
43 static SystemCheck _val;
48 SystemCheck::SystemCheck() {
50 _file = ZConfig::instance().solver_checkSystemFile();
54 _dir = ZConfig::instance().solver_checkSystemFileDir();
59 bool SystemCheck::setFile(const Pathname & file) const{
60 MIL << "Setting checkFile to : " << file << endl;
66 bool SystemCheck::setDir(const Pathname & dir) const {
67 MIL << "Setting checkFile directory to : " << dir << endl;
74 const Pathname & SystemCheck::file() {
78 const Pathname & SystemCheck::dir() {
82 const CapabilitySet & SystemCheck::requiredSystemCap() const{
86 const CapabilitySet & SystemCheck::conflictSystemCap() const{
90 bool SystemCheck::loadFile(Pathname & file, bool reset_caps) const{
91 Target_Ptr trg( getZYpp()->getTarget() );
93 file = trg->assertRootPrefix( file );
96 if ( ! pi.isFile() ) {
97 WAR << "Can't read " << file << " " << pi << endl;
106 std::ifstream infile( file.c_str() );
107 for( iostr::EachLine in( infile ); in; in.next() ) {
108 std::string l( str::trim(*in) );
109 if ( ! l.empty() && l[0] != '#' )
112 str::split( l, back_inserter(capList), ":" );
113 if (capList.size() == 2 ) {
114 CapList::iterator it = capList.begin();
115 if (*it == "requires") {
116 _require.insert(Capability(*(it+1)));
117 } else if (*it == "conflicts") {
118 _conflict.insert(Capability(*(it+1)));
120 ERR << "Wrong parameter: " << l << endl;
123 ERR << "Wrong line: " << l << endl;
127 MIL << "Read " << pi << endl;
131 bool SystemCheck::loadFiles() const {
133 filesystem::dirForEach(_dir,
134 [this](const Pathname & dir_r, const char *const & name_r)->bool
136 const std::string wanted = ".check";
137 Pathname pth = dir_r/name_r;
138 if (pth.extension() != wanted) {
139 MIL << "Skipping " << pth << " (not a *.check file)" << endl;
143 MIL << "Reading " << pth << endl;
144 return loadFile(pth, false /* do not reset caps */);
151 /******************************************************************
153 ** FUNCTION NAME : operator<<
154 ** FUNCTION TYPE : std::ostream &
156 std::ostream & operator<<( std::ostream & str, const SystemCheck & obj )
158 str << _file << endl;
159 str << "requires" << endl;
160 for (CapabilitySet::const_iterator it = _require.begin(); it != _require.end(); ++it)
161 str << " " << *it << endl;
163 str << "conflicts" << endl;
164 for (CapabilitySet::const_iterator it = _conflict.begin(); it != _conflict.end(); ++it)
165 str << " " << *it << endl;
170 /////////////////////////////////////////////////////////////////
172 ///////////////////////////////////////////////////////////////////