Commit 5c0a6301 by Juha Kallioinen Committed by Thomas Perl

[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).
parent 5a8a52a1
...@@ -327,6 +327,16 @@ ...@@ -327,6 +327,16 @@
# solver.checkSystemFile = /etc/zypp/systemCheck # 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 ## When committing a dist upgrade (e.g. 'zypper dup') a solver testcase
## is written to /var/log/updateTestcase-<date>. It is needed in bugreports. ## is written to /var/log/updateTestcase-<date>. It is needed in bugreports.
## This option returns the number of testcases to keep on the system. Old ## This option returns the number of testcases to keep on the system. Old
......
...@@ -472,6 +472,10 @@ namespace zypp ...@@ -472,6 +472,10 @@ namespace zypp
{ {
solver_checkSystemFile = Pathname(value); solver_checkSystemFile = Pathname(value);
} }
else if ( entry == "solver.checkSystemFileDir" )
{
solver_checkSystemFileDir = Pathname(value);
}
else if ( entry == "multiversion" ) else if ( entry == "multiversion" )
{ {
str::split( value, inserter( _multiversion, _multiversion.end() ), ", \t" ); str::split( value, inserter( _multiversion, _multiversion.end() ), ", \t" );
...@@ -592,6 +596,7 @@ namespace zypp ...@@ -592,6 +596,7 @@ namespace zypp
DefaultOption<bool> solverUpgradeRemoveDroppedPackages; DefaultOption<bool> solverUpgradeRemoveDroppedPackages;
Pathname solver_checkSystemFile; Pathname solver_checkSystemFile;
Pathname solver_checkSystemFileDir;
std::set<std::string> & multiversion() { return getMultiversion(); } std::set<std::string> & multiversion() { return getMultiversion(); }
const std::set<std::string> & multiversion() const { return getMultiversion(); } const std::set<std::string> & multiversion() const { return getMultiversion(); }
...@@ -879,6 +884,10 @@ namespace zypp ...@@ -879,6 +884,10 @@ namespace zypp
{ return ( _pimpl->solver_checkSystemFile.empty() { return ( _pimpl->solver_checkSystemFile.empty()
? (configPath()/"systemCheck") : _pimpl->solver_checkSystemFile ); } ? (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 unsigned ZConfig::solver_upgradeTestcasesToKeep() const
{ return _pimpl->solver_upgradeTestcasesToKeep; } { return _pimpl->solver_upgradeTestcasesToKeep; }
......
...@@ -280,6 +280,13 @@ namespace zypp ...@@ -280,6 +280,13 @@ namespace zypp
Pathname solver_checkSystemFile() const; 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. * Whether vendor check is by default enabled.
*/ */
bool solver_allowVendorChange() const; bool solver_allowVendorChange() const;
......
...@@ -30,6 +30,7 @@ namespace zypp ...@@ -30,6 +30,7 @@ namespace zypp
{ ///////////////////////////////////////////////////////////////// { /////////////////////////////////////////////////////////////////
Pathname _file = ""; Pathname _file = "";
Pathname _dir = "";
CapabilitySet _require; CapabilitySet _require;
CapabilitySet _conflict; CapabilitySet _conflict;
...@@ -42,24 +43,40 @@ namespace zypp ...@@ -42,24 +43,40 @@ namespace zypp
} }
SystemCheck::SystemCheck() { SystemCheck::SystemCheck() {
if (_file.empty()) { if (_file.empty()) {
_file = ZConfig::instance().solver_checkSystemFile(); _file = ZConfig::instance().solver_checkSystemFile();
loadFile(); loadFile(_file);
} }
if (_dir.empty()) {
_dir = ZConfig::instance().solver_checkSystemFileDir();
loadFiles();
}
} }
bool SystemCheck::setFile(const Pathname & file) const{ bool SystemCheck::setFile(const Pathname & file) const{
MIL << "Setting checkFile to : " << file << endl; MIL << "Setting checkFile to : " << file << endl;
_file = file; _file = file;
loadFile(); loadFile(_file);
return true; 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() { const Pathname & SystemCheck::file() {
return _file; return _file;
} }
const Pathname & SystemCheck::dir() {
return _dir;
}
const CapabilitySet & SystemCheck::requiredSystemCap() const{ const CapabilitySet & SystemCheck::requiredSystemCap() const{
return _require; return _require;
} }
...@@ -68,21 +85,23 @@ namespace zypp ...@@ -68,21 +85,23 @@ namespace zypp
return _conflict; return _conflict;
} }
bool SystemCheck::loadFile() const{ bool SystemCheck::loadFile(Pathname & file, bool reset_caps) const{
Target_Ptr trg( getZYpp()->getTarget() ); Target_Ptr trg( getZYpp()->getTarget() );
if ( trg ) if ( trg )
_file = trg->assertRootPrefix( _file ); file = trg->assertRootPrefix( file );
PathInfo pi( _file ); PathInfo pi( file );
if ( ! pi.isFile() ) { if ( ! pi.isFile() ) {
WAR << "Can't read " << _file << " " << pi << endl; WAR << "Can't read " << file << " " << pi << endl;
return false; return false;
} }
_require.clear(); if (reset_caps) {
_conflict.clear(); _require.clear();
_conflict.clear();
}
std::ifstream infile( _file.c_str() ); std::ifstream infile( file.c_str() );
for( iostr::EachLine in( infile ); in; in.next() ) { for( iostr::EachLine in( infile ); in; in.next() ) {
std::string l( str::trim(*in) ); std::string l( str::trim(*in) );
if ( ! l.empty() && l[0] != '#' ) if ( ! l.empty() && l[0] != '#' )
...@@ -107,6 +126,25 @@ namespace zypp ...@@ -107,6 +126,25 @@ namespace zypp
return true; 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 ...@@ -38,11 +38,20 @@ namespace zypp
/** Return the file path. */ /** Return the file path. */
const Pathname & file(); const Pathname & file();
/** Return the directory path. */
const Pathname & dir();
/** Set configuration file of system requirements /** Set configuration file of system requirements
* Should be used for testcase only * Should be used for testcase only
*/ */
bool setFile(const Pathname & file) const; 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. /** Returns a list of required system capabilities.
*/ */
const CapabilitySet & requiredSystemCap() const; const CapabilitySet & requiredSystemCap() const;
...@@ -54,8 +63,8 @@ namespace zypp ...@@ -54,8 +63,8 @@ namespace zypp
private: private:
/** Ctor taking the file to read. */ /** Ctor taking the file to read. */
SystemCheck(); SystemCheck();
bool loadFile() const; bool loadFile(Pathname &file, bool reset_caps = true) const;
bool loadFiles() const;
}; };
/////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment