Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[zypp] Support for *.check files in the systemCheck.d directory
Reads files from under /etc/zypp/systemCheck.d (default) and adds the
listed requires and conflicts rules to the system requirements.

Files are read in alphabetical order.

This list of requires/conflicts is updated only when libzypp is loaded
(e.g. in case of PackageKit, when packagekitd is reloaded).
  • Loading branch information
kaltsi authored and thp committed May 19, 2015
1 parent 5a8a52a commit 5c0a630
Show file tree
Hide file tree
Showing 5 changed files with 85 additions and 12 deletions.
10 changes: 10 additions & 0 deletions libzypp/zypp.conf
Expand Up @@ -326,6 +326,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 @@ -472,6 +472,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 @@ -592,6 +596,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 @@ -879,6 +884,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 @@ -279,6 +279,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
58 changes: 48 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,25 @@ namespace zypp
return true;
}

bool SystemCheck::loadFiles() const {

filesystem::dirForEach(_dir,
[this](const Pathname & dir_r, const char *const & name_r)->bool
{
const std::string wanted = ".check";
Pathname pth = dir_r/name_r;
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 */);
}
});
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

0 comments on commit 5c0a630

Please sign in to comment.