Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Merge pull request #1 from mer-packages/systemcheckd
Support for /etc/zypp/systemCheck.d/ config directory
  • Loading branch information
iamer committed Dec 30, 2013
2 parents b45c1c6 + e8f3ef0 commit 8f14a3a
Show file tree
Hide file tree
Showing 6 changed files with 79 additions and 13 deletions.
10 changes: 10 additions & 0 deletions libzypp/zypp.conf
Expand Up @@ -314,6 +314,16 @@
##
# solver.checkSystemFile = /etc/zypp/systemCheck

##
## This directory can contain files that contain requirements/conflicts
## which fulfill the needs of a running system (see checkSystemFile).
##
## Files are read in alphabetical order.
##
## Default value: {configdir}/systemCheck.d
##
# solver.checkSystemFileDir = /etc/zypp/systemCheck.d

##
## When committing a dist upgrade (e.g. 'zypper dup') a solver testcase
## is written to /var/log/updateTestcase-<date>. It is needed in bugreports.
Expand Down
9 changes: 9 additions & 0 deletions libzypp/zypp/ZConfig.cc
Expand Up @@ -453,6 +453,10 @@ namespace zypp
{
solver_checkSystemFile = Pathname(value);
}
else if ( entry == "solver.checkSystemFileDir" )
{
solver_checkSystemFileDir = Pathname(value);
}
else if ( entry == "multiversion" )
{
str::split( value, inserter( _multiversion, _multiversion.end() ), ", \t" );
Expand Down Expand Up @@ -572,6 +576,7 @@ namespace zypp
DefaultOption<bool> solverUpgradeRemoveDroppedPackages;

Pathname solver_checkSystemFile;
Pathname solver_checkSystemFileDir;

std::set<std::string> & multiversion() { return getMultiversion(); }
const std::set<std::string> & multiversion() const { return getMultiversion(); }
Expand Down Expand Up @@ -829,6 +834,10 @@ namespace zypp
{ return ( _pimpl->solver_checkSystemFile.empty()
? (configPath()/"systemCheck") : _pimpl->solver_checkSystemFile ); }

Pathname ZConfig::solver_checkSystemFileDir() const
{ return ( _pimpl->solver_checkSystemFileDir.empty()
? (configPath()/"systemCheck.d") : _pimpl->solver_checkSystemFileDir ); }

unsigned ZConfig::solver_upgradeTestcasesToKeep() const
{ return _pimpl->solver_upgradeTestcasesToKeep; }

Expand Down
7 changes: 7 additions & 0 deletions libzypp/zypp/ZConfig.h
Expand Up @@ -256,6 +256,13 @@ namespace zypp
*/
Pathname solver_checkSystemFile() const;

/**
* Directory, which may or may not contain files in which
* dependencies described which has to be fulfilled for a
* running system.
*/
Pathname solver_checkSystemFileDir() const;

/**
* Whether vendor check is by default enabled.
*/
Expand Down
51 changes: 41 additions & 10 deletions libzypp/zypp/solver/detail/SystemCheck.cc
Expand Up @@ -30,6 +30,7 @@ namespace zypp
{ /////////////////////////////////////////////////////////////////

Pathname _file = "";
Pathname _dir = "";
CapabilitySet _require;
CapabilitySet _conflict;

Expand All @@ -42,24 +43,40 @@ namespace zypp
}


SystemCheck::SystemCheck() {
SystemCheck::SystemCheck() {
if (_file.empty()) {
_file = ZConfig::instance().solver_checkSystemFile();
loadFile();
loadFile(_file);
}
if (_dir.empty()) {
_dir = ZConfig::instance().solver_checkSystemFileDir();
loadFiles();
}
}

bool SystemCheck::setFile(const Pathname & file) const{
MIL << "Setting checkFile to : " << file << endl;
_file = file;
loadFile();
loadFile(_file);
return true;
}

bool SystemCheck::setDir(const Pathname & dir) const {
MIL << "Setting checkFile directory to : " << dir << endl;
loadFile(_file);
_dir = dir;
loadFiles();
return true;
}

const Pathname & SystemCheck::file() {
return _file;
}

const Pathname & SystemCheck::dir() {
return _dir;
}

const CapabilitySet & SystemCheck::requiredSystemCap() const{
return _require;
}
Expand All @@ -68,21 +85,23 @@ namespace zypp
return _conflict;
}

bool SystemCheck::loadFile() const{
bool SystemCheck::loadFile(Pathname & file, bool reset_caps) const{
Target_Ptr trg( getZYpp()->getTarget() );
if ( trg )
_file = trg->assertRootPrefix( _file );
file = trg->assertRootPrefix( file );

PathInfo pi( _file );
PathInfo pi( file );
if ( ! pi.isFile() ) {
WAR << "Can't read " << _file << " " << pi << endl;
WAR << "Can't read " << file << " " << pi << endl;
return false;
}

_require.clear();
_conflict.clear();
if (reset_caps) {
_require.clear();
_conflict.clear();
}

std::ifstream infile( _file.c_str() );
std::ifstream infile( file.c_str() );
for( iostr::EachLine in( infile ); in; in.next() ) {
std::string l( str::trim(*in) );
if ( ! l.empty() && l[0] != '#' )
Expand All @@ -107,6 +126,18 @@ namespace zypp
return true;
}

bool SystemCheck::loadFiles() const {

filesystem::dirForEach(_dir,
[this](const Pathname & dir_r, const char *const & name_r)->bool
{
Pathname pth = dir_r/name_r;
MIL << "Reading " << pth << endl;
return loadFile(pth, false /* do not reset caps */);
});
return true;
}


/******************************************************************
**
Expand Down
13 changes: 11 additions & 2 deletions libzypp/zypp/solver/detail/SystemCheck.h
Expand Up @@ -38,11 +38,20 @@ namespace zypp
/** Return the file path. */
const Pathname & file();

/** Return the directory path. */
const Pathname & dir();

/** Set configuration file of system requirements
* Should be used for testcase only
*/
bool setFile(const Pathname & file) const;

/** Set configuration directory for files of system
* requirements.
* Should be used for testcase only
*/
bool setDir(const Pathname & dir) const;

/** Returns a list of required system capabilities.
*/
const CapabilitySet & requiredSystemCap() const;
Expand All @@ -54,8 +63,8 @@ namespace zypp
private:
/** Ctor taking the file to read. */
SystemCheck();
bool loadFile() const;

bool loadFile(Pathname &file, bool reset_caps = true) const;
bool loadFiles() const;
};
///////////////////////////////////////////////////////////////////

Expand Down
2 changes: 1 addition & 1 deletion rpm/libzypp.spec
Expand Up @@ -75,7 +75,7 @@ Authors:
%setup -q -n %{name}-%{version}/%{name}

%build
mkdir build
mkdir -p build
cd build

# There is gcc bug that prevents using gdwarf-4 atm.
Expand Down

0 comments on commit 8f14a3a

Please sign in to comment.