libzypp  12.16.5
SystemCheck.cc
Go to the documentation of this file.
1 /*---------------------------------------------------------------------\
2 | ____ _ __ __ ___ |
3 | |__ / \ / / . \ . \ |
4 | / / \ V /| _/ _/ |
5 | / /__ | | | | | | |
6 | /_____||_| |_| |_| |
7 | |
8 \---------------------------------------------------------------------*/
12 #include <iostream>
13 #include <fstream>
14 #include <vector>
15 
16 #include "zypp/base/LogTools.h"
17 #include "zypp/base/IOStream.h"
18 #include "zypp/base/String.h"
19 
20 #include "zypp/ZYppFactory.h"
21 #include "zypp/ZConfig.h"
22 #include "zypp/Pathname.h"
23 #include "zypp/PathInfo.h"
25 
26 using namespace std;
27 
29 namespace zypp
30 {
31 
32  Pathname _file = "";
35 
36  typedef vector<string> CapList;
37 
38  const SystemCheck & SystemCheck::instance()
39  {
40  static SystemCheck _val;
41  return _val;
42  }
43 
44 
45  SystemCheck::SystemCheck() {
46  if (_file.empty()) {
47  _file = ZConfig::instance().solver_checkSystemFile();
48  loadFile();
49  }
50  }
51 
52  bool SystemCheck::setFile(const Pathname & file) const{
53  MIL << "Setting checkFile to : " << file << endl;
54  _file = file;
55  loadFile();
56  return true;
57  }
58 
59  const Pathname & SystemCheck::file() {
60  return _file;
61  }
62 
63  const CapabilitySet & SystemCheck::requiredSystemCap() const{
64  return _require;
65  }
66 
67  const CapabilitySet & SystemCheck::conflictSystemCap() const{
68  return _conflict;
69  }
70 
71  bool SystemCheck::loadFile() const{
72  Target_Ptr trg( getZYpp()->getTarget() );
73  if ( trg )
74  _file = trg->assertRootPrefix( _file );
75 
76  PathInfo pi( _file );
77  if ( ! pi.isFile() ) {
78  WAR << "Can't read " << _file << " " << pi << endl;
79  return false;
80  }
81 
82  _require.clear();
83  _conflict.clear();
84 
85  std::ifstream infile( _file.c_str() );
86  for( iostr::EachLine in( infile ); in; in.next() ) {
87  std::string l( str::trim(*in) );
88  if ( ! l.empty() && l[0] != '#' )
89  {
90  CapList capList;
91  str::split( l, back_inserter(capList), ":" );
92  if (capList.size() == 2 ) {
93  CapList::iterator it = capList.begin();
94  if (*it == "requires") {
95  _require.insert(Capability(*(it+1)));
96  } else if (*it == "conflicts") {
97  _conflict.insert(Capability(*(it+1)));
98  } else {
99  ERR << "Wrong parameter: " << l << endl;
100  }
101  } else {
102  ERR << "Wrong line: " << l << endl;
103  }
104  }
105  }
106  MIL << "Read " << pi << endl;
107  return true;
108  }
109 
110 
111  /******************************************************************
112  **
113  ** FUNCTION NAME : operator<<
114  ** FUNCTION TYPE : std::ostream &
115  */
116  std::ostream & operator<<( std::ostream & str, const SystemCheck & obj )
117  {
118  str << _file << endl;
119  str << "requires" << endl;
120  for (CapabilitySet::const_iterator it = _require.begin(); it != _require.end(); ++it)
121  str << " " << *it << endl;
122 
123  str << "conflicts" << endl;
124  for (CapabilitySet::const_iterator it = _conflict.begin(); it != _conflict.end(); ++it)
125  str << " " << *it << endl;
126 
127  return str;
128  }
129 
131 } // namespace zypp