10 #include "pol_global_config.h" 12 #include "../clib/cfgelem.h" 13 #include "../clib/cfgfile.h" 14 #include "../clib/clib.h" 15 #include "../clib/dirlist.h" 16 #include "../clib/fileutil.h" 17 #include "../clib/logfacility.h" 18 #include "../clib/passert.h" 19 #include "../clib/stlutil.h" 20 #include "../clib/strutil.h" 21 #include "../plib/systemstate.h" 38 return ( *itr ).second;
49 std::bind2nd( std::equal_to<Package*>(), pkg ) );
61 if ( ( *tempitr ).second == pkg )
66 void compare_versions(
const std::string& verleft,
const std::string& verright,
bool& isgreater,
69 isgreater = isequal =
false;
71 const char* vneed = verright.c_str();
72 const char* vhave = verleft.c_str();
74 while ( ( vneed != NULL && vneed[0] !=
'\0' ) || ( vhave != NULL && vhave[0] !=
'\0' ) )
76 char* new_vneed = NULL;
77 char* new_vhave = NULL;
78 unsigned int vneedpart, vhavepart;
79 vneedpart = ( vneed != NULL ) ? strtoul( vneed, &new_vneed, 0 ) : 0;
80 vhavepart = ( vhave != NULL ) ? strtoul( vhave, &new_vhave, 0 ) : 0;
82 if ( vhavepart > vneedpart )
87 else if ( vhavepart < vneedpart )
94 if ( vneed && *vneed )
97 if ( vhave && *vhave )
104 bool check_version2(
const std::string& version_have,
const std::string& version_need )
109 return ( isequal || isgreater );
136 if ( !( is >> _elem.
version ) )
139 elems.push_back( _elem );
146 for (
const auto& elem : elems )
147 size += elem.pkgname.capacity() + elem.version.capacity();
153 name_( elem.remove_string(
"Name" ) ),
154 version_( elem.remove_string(
"Version",
"0" ) ),
164 std::string tmp = elem.
read_string(
"CoreRequired",
"0" );
165 if ( isdigit( tmp[0] ) )
178 return name() +
" (" +
dir() +
")";
206 <<
" Core version " <<
core_required_ <<
" is required, but version " 207 << POL_VERSION <<
" is running.\n";
208 throw std::runtime_error(
"Package requires a newer core version" );
218 <<
" is required, but version " << POL_VERSION_ID <<
" is running.\n";
219 throw std::runtime_error(
"Package requires a newer core version" );
228 <<
" Package '" << elem.pkgname <<
"' is required, but is not installed.\n";
229 throw std::runtime_error(
"Package dependency error" );
236 <<
" Package '" << elem.pkgname <<
"' version " << elem.version
237 <<
" is required, but version " << found->
version_ <<
" was found\n";
238 throw std::runtime_error(
"Package dependency error" );
252 <<
" Package conflicts with package " << found->
desc() <<
"\n";
253 throw std::runtime_error(
"Package dependency error" );
261 sizeof(
unsigned short )
271 std::unique_ptr<Package> pkg(
new Package( pkg_dir, elem ) );
274 if ( existing_pkg != NULL )
276 bool isgreater, isequal;
282 INFO_PRINT <<
"Replacing package " << existing_pkg->
desc() <<
" version " 283 << existing_pkg->
version() <<
" with version " << pkg->version() <<
" found in " 284 << pkg->dir() <<
"\n";
291 ERROR_PRINT <<
"Error in package " << pkg->desc() <<
":\n" 292 <<
" Package by same name already found in " << existing_pkg->
desc() <<
"\n";
293 throw std::runtime_error(
"Duplicate package found" );
299 INFO_PRINT <<
"Skipping package " << pkg->desc() <<
" version " << pkg->version()
300 <<
" because version " << existing_pkg->
version() <<
" was already found in " 301 << existing_pkg->
dir() <<
"\n";
316 std::string dirname = dl.name();
317 if ( dirname[0] ==
'.' )
319 if ( dirname ==
"template" )
322 std::string pkg_dir = basedir + dirname +
"/";
323 std::string pkg_cfg = pkg_dir +
"pkg.cfg";
331 std::string enabled_pkg = pkg_dir +
"enabled.pkg";
332 std::string disabled_pkg = pkg_dir +
"disabled.pkg";
334 if ( ( elem.remove_bool(
"Enabled" ) ==
true ||
Clib::FileExists( enabled_pkg.c_str() ) ) &&
338 INFO_PRINT <<
"Loading package in " << pkg_dir <<
"\n";
366 bool change = pkg->check_replacements();
393 while ( cf.
read( elem ) )
399 INFO_PRINT <<
"Searching for packages under " << dir <<
"\n";
413 if ( spec[0] ==
':' )
415 if ( spec[1] ==
':' )
418 *path = spec.substr( 2, std::string::npos );
422 std::string::size_type second_colon = spec.find(
':', 2 );
423 if ( second_colon != std::string::npos )
425 std::string pkgname = spec.substr( 1, second_colon - 1 );
426 std::string pkgfile = spec.substr( second_colon + 1, std::string::npos );
428 if ( dstpkg != NULL )
435 ERROR_PRINT <<
"Unable to find package '" << pkgname <<
"'\n";
441 ERROR_PRINT <<
"Poorly formed packagefile descriptor: '" << spec <<
"'\n";
465 while ( cf.read( elem ) )
467 loadentry( pkg, elem );
476 std::string filename = std::string(
"config/" ) + cfgname;
482 while ( cf.read( elem ) )
484 loadentry( NULL, elem );
493 std::string filepath;
496 filepath =
"config/" + filename;
501 filepath = pkg->
dir() +
"config/" + filename;
505 filepath = pkg->
dir() + filename;
std::string core_versionstring_required_
bool provides_system_home_page_
bool check_version2(const std::string &version_have, const std::string &version_need)
std::string remove_string(const char *propname)
void load_packaged_cfgs(const char *cfgname, const char *taglist, void(*loadentry)(const Package *, Clib::ConfigElem &))
void check_package_deps()
bool provides_system_home_page() const
PackageList(Clib::ConfigElem &elem, const char *tag)
unsigned short core_required_
const std::string & name() const
void check_dependencies() const
Package * find_package(const std::string &pkgname)
bool pkgdef_split(const std::string &spec, const Package *inpkg, const Package **outpkg, std::string *path)
size_t sizeEstimate() const
std::string read_string(const char *propname) const
void check_deps_for_package(const Package *pkg)
void load_all_cfgs(const char *cfgname, const char *taglist, void(*loadentry)(const Package *, Clib::ConfigElem &))
bool check_replacements() const
bool remove_prop(const char *propname, std::string *value)
void compare_versions(const std::string &verleft, const std::string &verright, bool &isgreater, bool &isequal)
Package(const std::string &pkg_dir, Clib::ConfigElem &elem)
std::vector< Elem > elems
unsigned short remove_ushort(const char *propname)
std::string GetPackageCfgPath(const Package *pkg, const std::string &filename)
void check_conflicts() const
size_t estimateSize() const
void mklower(std::string &str)
std::string normalized_dir_form(const std::string &istr)
bool FileExists(const char *filename)
bool read(ConfigElem &elem)
const std::string & version() const
void load_package(const std::string &pkg_dir, Clib::ConfigElem &elem, bool quiet)
PackagesByName packages_byname
void test_check_version()
const std::string & dir() const
void remove_package(Package *pkg)
void load_packages(const std::string &basedir, bool quiet)