Commit 1d66bfef authored by Pavel Vainerman's avatar Pavel Vainerman Committed by Pavel Vainerman

[conf]: check directory exists

parent 603b7219
......@@ -323,6 +323,7 @@ namespace uniset
// Всякие helper-ы
bool file_exist( const std::string& filename );
bool directory_exist( const std::string& path );
// Проверка xml-узла на соответствие <...f_prop="f_val">,
// если не задано f_val, то проверяется, что просто f_prop!=""
......
......@@ -611,7 +611,7 @@ namespace uniset
{
repeatCount = it.getPIntProp("name", 1);
}
else if( name == "ImagesPath" )
else if( name == "ImagesPath" ) // DEPRECATED
{
imagesDir = dataDir + it.getProp("name") + "/"; // ????????
}
......@@ -633,6 +633,13 @@ namespace uniset
if( dataDir.empty() )
dataDir = getRootDir();
if( !directory_exist(dataDir) )
{
ostringstream err;
err << "Configuration: DataDir=" << dataDir << " NOT EXISTS";
throw uniset::SystemError(err.str());
}
}
else if( name == "BinDir" )
{
......@@ -640,6 +647,13 @@ namespace uniset
if( binDir.empty() )
binDir = getRootDir();
if( !directory_exist(binDir) )
{
ostringstream err;
err << "Configuration: BinDir=" << binDir << " NOT EXISTS";
throw uniset::SystemError(err.str());
}
}
else if( name == "LogDir" )
{
......@@ -647,6 +661,13 @@ namespace uniset
if( logDir.empty() )
logDir = getRootDir();
if( !directory_exist(logDir) )
{
ostringstream err;
err << "Configuration: LogDir=" << logDir << " NOT EXISTS";
throw uniset::SystemError(err.str());
}
}
else if( name == "LockDir" )
{
......@@ -654,6 +675,13 @@ namespace uniset
if( lockDir.empty() )
lockDir = getRootDir();
if( !directory_exist(lockDir) )
{
ostringstream err;
err << "Configuration: LockDir=" << lockDir << " NOT EXISTS";
throw uniset::SystemError(err.str());
}
}
else if( name == "ConfDir" )
{
......@@ -661,6 +689,13 @@ namespace uniset
if( confDir.empty() )
confDir = getRootDir();
if( !directory_exist(confDir) )
{
ostringstream err;
err << "Configuration: ConfDir=" << confDir << " NOT EXISTS";
throw uniset::SystemError(err.str());
}
}
}
......
......@@ -252,6 +252,12 @@ TEST_CASE("UniSetTypes: file_exist", "[utypes][file_exist]" )
CHECK( file_exist(conf->getConfFileName()) );
}
// -----------------------------------------------------------------------------
TEST_CASE("UniSetTypes: directory_exist", "[utypes][directory_exist]" )
{
CHECK_FALSE( directory_exist("uknown_dir") );
CHECK( directory_exist("/") ); // linux only
}
// -----------------------------------------------------------------------------
TEST_CASE("UniSetTypes: check_filter", "[utypes][check_filter]" )
{
// bool check_filter( UniXML::iterator& it, const std::string& f_prop, const std::string& f_val = "" ) noexcept;
......
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