SPARK-1198 Directory Shuffle

This commit is contained in:
Eric Harding authored and Pedro Pinto committed 2018-06-04 17:10:36 -04:00
1 parent fdf727a52a
commit 4c7949ff8d
5 files changed
+27 -65

No files matched your search

+10 -17
View File
@@ -47,20 +47,21 @@ namespace http {
WsServer _server;
int _port;
std::string _www;
std::string _conf;
const api::ServiceContext& _ctx;
ServerState(const api::ServiceContext& ctx, int port, const char* web_root) :
ServerState(const api::ServiceContext& ctx, int port) :
_m(),
_dispatcher(utils::Dispatcher::get_named("Webserver")),
_session(),
_server(),
_port(port),
_www(web_root),
_www(),
_ctx(ctx)
{
if (_www.empty()) {
_www = std::string(getenv("HOME")) + "/www";
}
_www = os::sparkdata_path("www");
_conf = os::sparkdata_path("conf");
_server.init_asio(_dispatcher.io_service());
_server.set_open_handler(bind(&ServerState::on_open, this, ::_1));
_server.set_close_handler(bind(&ServerState::on_close, this, ::_1));
@@ -112,7 +113,7 @@ namespace http {
void return_dotall(connection_ptr& con) {
std::vector<boost::filesystem::path> files;
auto iter = boost::filesystem::directory_iterator(_www + "/config/");
auto iter = boost::filesystem::directory_iterator(_conf);
auto end = boost::filesystem::directory_iterator();
// Collect all .conf file
for (; iter != end; ++iter) {
@@ -183,21 +184,13 @@ namespace http {
boost::filesystem::path map_path_to_filesystem(const std::string& resource) {
std::string config = "/config";
std::string files = "/files";
std::string error_reports = "/error_reports";
if (resource.compare(0, config.size(), config) == 0) {
return _www + resource;
return _conf;
}
else if (resource.compare(0, files.size(), files) == 0) {
return _www + resource.substr(files.size());
}
#ifndef RELEASE
// To enable this in release it probably needs a password
else if (resource.compare(0, error_reports.size(), error_reports) == 0) {
auto errp = boost::filesystem::path(getenv("HOME")) / ".bts/data/error_reports" / resource.substr(error_reports.size());
if (boost::filesystem::exists(errp)) return errp;
}
#endif
return web_ui_path(os::get_install_path()) / resource;
}
@@ -254,8 +247,8 @@ namespace http {
SparkWebServer::SparkWebServer(const api::ServiceContext& ctx, int port, const char* web_root) :
_me(std::make_shared<ServerState>(ctx, port, web_root))
SparkWebServer::SparkWebServer(const api::ServiceContext& ctx, int port) :
_me(std::make_shared<ServerState>(ctx, port))
{
}