2016-07-25 10:57:54 +02:00
|
|
|
/*
|
|
|
|
* charybdis: A slightly useful ircd.
|
|
|
|
* ircd.c: Starts up and runs the ircd.
|
|
|
|
*
|
|
|
|
* Copyright (C) 1990 Jarkko Oikarinen and University of Oulu, Co Center
|
|
|
|
* Copyright (C) 1996-2002 Hybrid Development Team
|
|
|
|
* Copyright (C) 2002-2008 ircd-ratbox development team
|
|
|
|
* Copyright (C) 2005-2013 charybdis development team
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
|
|
|
|
* USA
|
|
|
|
*/
|
|
|
|
|
2016-08-31 10:03:44 +02:00
|
|
|
#include <boost/filesystem.hpp>
|
|
|
|
|
|
|
|
namespace fs = boost::filesystem;
|
|
|
|
|
2016-08-31 08:25:25 +02:00
|
|
|
namespace ircd {
|
|
|
|
namespace path {
|
2016-07-25 10:57:54 +02:00
|
|
|
|
2016-08-31 08:25:25 +02:00
|
|
|
enum
|
2016-08-14 05:35:06 +02:00
|
|
|
{
|
2016-08-31 08:25:25 +02:00
|
|
|
NAME = 0,
|
|
|
|
PATH = 1,
|
|
|
|
};
|
2016-08-14 05:35:06 +02:00
|
|
|
|
2016-08-31 08:25:25 +02:00
|
|
|
using ent = std::pair<std::string, std::string>;
|
2016-08-14 05:35:06 +02:00
|
|
|
|
2016-08-31 08:25:25 +02:00
|
|
|
std::array<ent, num_of<index>()> paths
|
|
|
|
{{
|
|
|
|
{ "prefix", DPATH },
|
|
|
|
{ "binary dir", BINPATH },
|
|
|
|
{ "config", ETCPATH },
|
|
|
|
{ "log", LOGPATH },
|
|
|
|
{ "libexec dir", PKGLIBEXECDIR },
|
|
|
|
{ "modules", MODPATH },
|
|
|
|
{ "user help", UHPATH },
|
|
|
|
{ "oper help", HPATH },
|
|
|
|
{ "ircd.conf", CPATH },
|
|
|
|
{ "ircd binary", SPATH },
|
|
|
|
{ "ircd.motd", MPATH },
|
|
|
|
{ "ircd.log", LPATH },
|
|
|
|
{ "oper motd", OPATH },
|
2016-09-24 03:21:08 +02:00
|
|
|
{ "bandb", BDBPATH },
|
|
|
|
{ "db", DBPATH },
|
2016-08-31 08:25:25 +02:00
|
|
|
}};
|
2016-08-14 05:35:06 +02:00
|
|
|
|
2016-08-31 10:03:44 +02:00
|
|
|
} // namespace path
|
|
|
|
} // namespace ircd
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
ircd::path::chdir(const std::string &path)
|
|
|
|
try
|
|
|
|
{
|
|
|
|
fs::current_path(path);
|
|
|
|
}
|
|
|
|
catch(const fs::filesystem_error &e)
|
|
|
|
{
|
|
|
|
throw filesystem_error("%s", e.what());
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string
|
|
|
|
ircd::path::cwd()
|
|
|
|
try
|
|
|
|
{
|
|
|
|
return fs::current_path().string();
|
|
|
|
}
|
|
|
|
catch(const fs::filesystem_error &e)
|
|
|
|
{
|
|
|
|
throw filesystem_error("%s", e.what());
|
|
|
|
}
|
|
|
|
|
|
|
|
std::vector<std::string>
|
|
|
|
ircd::path::ls_recursive(const std::string &path)
|
|
|
|
try
|
|
|
|
{
|
|
|
|
fs::recursive_directory_iterator it(path);
|
|
|
|
const fs::recursive_directory_iterator end;
|
|
|
|
std::vector<std::string> ret(std::distance(it, end));
|
|
|
|
std::transform(it, end, begin(ret), []
|
|
|
|
(const auto &ent)
|
|
|
|
{
|
|
|
|
return ent.path().string();
|
|
|
|
});
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
catch(const fs::filesystem_error &e)
|
|
|
|
{
|
|
|
|
throw filesystem_error("%s", e.what());
|
|
|
|
}
|
|
|
|
|
|
|
|
std::vector<std::string>
|
|
|
|
ircd::path::ls(const std::string &path)
|
|
|
|
try
|
|
|
|
{
|
|
|
|
fs::directory_iterator it(path);
|
|
|
|
const fs::directory_iterator end;
|
|
|
|
std::vector<std::string> ret(std::distance(it, end));
|
|
|
|
std::transform(it, end, begin(ret), []
|
|
|
|
(const auto &ent)
|
|
|
|
{
|
|
|
|
return ent.path().string();
|
|
|
|
});
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
catch(const fs::filesystem_error &e)
|
|
|
|
{
|
|
|
|
throw filesystem_error("%s", e.what());
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
ircd::path::is_reg(const std::string &path)
|
|
|
|
try
|
|
|
|
{
|
|
|
|
return fs::is_regular_file(path);
|
|
|
|
}
|
|
|
|
catch(const fs::filesystem_error &e)
|
|
|
|
{
|
|
|
|
throw filesystem_error("%s", e.what());
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
ircd::path::is_dir(const std::string &path)
|
|
|
|
try
|
|
|
|
{
|
|
|
|
return fs::is_directory(path);
|
|
|
|
}
|
|
|
|
catch(const fs::filesystem_error &e)
|
|
|
|
{
|
|
|
|
throw filesystem_error("%s", e.what());
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
ircd::path::exists(const std::string &path)
|
|
|
|
try
|
|
|
|
{
|
|
|
|
return fs::exists(path);
|
|
|
|
}
|
|
|
|
catch(const fs::filesystem_error &e)
|
|
|
|
{
|
|
|
|
throw filesystem_error("%s", e.what());
|
|
|
|
}
|
|
|
|
|
2016-09-24 03:44:30 +02:00
|
|
|
std::string
|
|
|
|
ircd::path::build(const std::initializer_list<std::string> &list)
|
|
|
|
{
|
|
|
|
fs::path ret;
|
|
|
|
for(const auto &s : list)
|
|
|
|
ret /= fs::path(s);
|
|
|
|
|
|
|
|
return ret.string();
|
|
|
|
}
|
|
|
|
|
2016-08-14 05:35:06 +02:00
|
|
|
const char *
|
2016-08-31 10:03:44 +02:00
|
|
|
ircd::path::get(index index)
|
2016-08-14 05:35:06 +02:00
|
|
|
noexcept try
|
|
|
|
{
|
2016-08-31 08:25:25 +02:00
|
|
|
return std::get<PATH>(paths.at(index)).c_str();
|
2016-08-14 05:35:06 +02:00
|
|
|
}
|
|
|
|
catch(const std::out_of_range &e)
|
2016-07-25 10:57:54 +02:00
|
|
|
{
|
2016-08-14 05:35:06 +02:00
|
|
|
return nullptr;
|
|
|
|
}
|
2016-07-25 10:57:54 +02:00
|
|
|
|
2016-08-14 05:35:06 +02:00
|
|
|
const char *
|
2016-08-31 10:03:44 +02:00
|
|
|
ircd::path::name(index index)
|
2016-08-14 05:35:06 +02:00
|
|
|
noexcept try
|
|
|
|
{
|
2016-08-31 08:25:25 +02:00
|
|
|
return std::get<NAME>(paths.at(index)).c_str();
|
2016-08-14 05:35:06 +02:00
|
|
|
}
|
|
|
|
catch(const std::out_of_range &e)
|
|
|
|
{
|
|
|
|
return nullptr;
|
|
|
|
}
|