Skip to content
Permalink
Browse files
[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 5c0a63010331c35df5755ef022a1509687f2f731
Show file tree
Hide file tree
Showing 5 changed files with 85 additions and 12 deletions.
@@ -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.
@@ -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" );
@@ -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(); }
@@ -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; }

@@ -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.
*/
@@ -30,6 +30,7 @@ namespace zypp
{ /////////////////////////////////////////////////////////////////

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

@@ -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;
}
@@ -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] != '#' )
@@ -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;
}


/******************************************************************
**
@@ -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;
@@ -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;
};
///////////////////////////////////////////////////////////////////

0 comments on commit 5c0a630

Please sign in to comment.