0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2024-11-17 23:40:57 +01:00

ircd::fs: Fixes/renames to local filesystem support subsystem.

This commit is contained in:
Jason Volk 2017-03-30 15:46:01 -07:00
parent 33b2cd8f70
commit 2e7dd1e5ad
3 changed files with 24 additions and 23 deletions

View file

@ -20,7 +20,7 @@
*/ */
#pragma once #pragma once
#define HAVE_IRCD_PATH_H #define HAVE_IRCD_FS_H
/* /*
* Directory paths and filenames for UNIX systems. * Directory paths and filenames for UNIX systems.
@ -37,7 +37,7 @@
*/ */
namespace ircd { namespace ircd {
namespace path { namespace fs {
IRCD_EXCEPTION(ircd::error, error) IRCD_EXCEPTION(ircd::error, error)
IRCD_EXCEPTION(error, filesystem_error) IRCD_EXCEPTION(error, filesystem_error)
@ -54,7 +54,7 @@ constexpr auto CPATH = RB_ETC_DIR "/ircd.conf"; // ircd.conf file
constexpr auto MPATH = RB_ETC_DIR "/ircd.motd"; // MOTD file constexpr auto MPATH = RB_ETC_DIR "/ircd.motd"; // MOTD file
constexpr auto LPATH = RB_LOG_DIR "/ircd.log"; // ircd logfile constexpr auto LPATH = RB_LOG_DIR "/ircd.log"; // ircd logfile
constexpr auto OPATH = RB_ETC_DIR "/opers.motd"; // oper MOTD file constexpr auto OPATH = RB_ETC_DIR "/opers.motd"; // oper MOTD file
constexpr auto DBPATH = PKGLOCALSTATEDIR; // database prefix constexpr auto DBPATH = PKGLOCALSTATEDIR "/db"; // database prefix
constexpr auto BDBPATH = PKGLOCALSTATEDIR "/ban.db"; // bandb file constexpr auto BDBPATH = PKGLOCALSTATEDIR "/ban.db"; // bandb file
// Below are the elements for default paths. // Below are the elements for default paths.
@ -82,7 +82,7 @@ enum index
const char *get(index) noexcept; const char *get(index) noexcept;
const char *name(index) noexcept; const char *name(index) noexcept;
std::string build(const std::initializer_list<std::string> &); std::string make_path(const std::initializer_list<std::string> &);
bool exists(const std::string &path); bool exists(const std::string &path);
bool is_dir(const std::string &path); bool is_dir(const std::string &path);
@ -94,5 +94,5 @@ std::vector<std::string> ls_recursive(const std::string &path);
std::string cwd(); std::string cwd();
void chdir(const std::string &path); void chdir(const std::string &path);
} // namespace path } // namespace fs
} // namespace ircd } // namespace ircd

View file

@ -172,7 +172,7 @@ struct line {};
#include "json.h" #include "json.h"
#include "http.h" #include "http.h"
#include "fmt.h" #include "fmt.h"
#include "path.h" #include "fs.h"
#include "ctx.h" #include "ctx.h"
#include "conf.h" #include "conf.h"
#include "resource.h" #include "resource.h"

View file

@ -25,10 +25,10 @@
#include <boost/filesystem.hpp> #include <boost/filesystem.hpp>
namespace fs = boost::filesystem;
namespace ircd { namespace ircd {
namespace path { namespace fs {
using namespace boost::filesystem;
enum enum
{ {
@ -57,12 +57,12 @@ std::array<ent, num_of<index>()> paths
{ "db", DBPATH }, { "db", DBPATH },
}}; }};
} // namespace path } // namespace fs
} // namespace ircd } // namespace ircd
void void
ircd::path::chdir(const std::string &path) ircd::fs::chdir(const std::string &path)
try try
{ {
fs::current_path(path); fs::current_path(path);
@ -73,7 +73,7 @@ catch(const fs::filesystem_error &e)
} }
std::string std::string
ircd::path::cwd() ircd::fs::cwd()
try try
{ {
return fs::current_path().string(); return fs::current_path().string();
@ -84,7 +84,7 @@ catch(const fs::filesystem_error &e)
} }
std::vector<std::string> std::vector<std::string>
ircd::path::ls_recursive(const std::string &path) ircd::fs::ls_recursive(const std::string &path)
try try
{ {
fs::recursive_directory_iterator it(path); fs::recursive_directory_iterator it(path);
@ -104,13 +104,14 @@ catch(const fs::filesystem_error &e)
} }
std::vector<std::string> std::vector<std::string>
ircd::path::ls(const std::string &path) ircd::fs::ls(const std::string &path)
try try
{ {
static const fs::directory_iterator end;
std::vector<std::string> ret;
fs::directory_iterator it(path); fs::directory_iterator it(path);
const fs::directory_iterator end; std::transform(it, end, std::back_inserter(ret), []
std::vector<std::string> ret(std::distance(it, end));
std::transform(it, end, begin(ret), []
(const auto &ent) (const auto &ent)
{ {
return ent.path().string(); return ent.path().string();
@ -124,7 +125,7 @@ catch(const fs::filesystem_error &e)
} }
bool bool
ircd::path::is_reg(const std::string &path) ircd::fs::is_reg(const std::string &path)
try try
{ {
return fs::is_regular_file(path); return fs::is_regular_file(path);
@ -135,7 +136,7 @@ catch(const fs::filesystem_error &e)
} }
bool bool
ircd::path::is_dir(const std::string &path) ircd::fs::is_dir(const std::string &path)
try try
{ {
return fs::is_directory(path); return fs::is_directory(path);
@ -146,7 +147,7 @@ catch(const fs::filesystem_error &e)
} }
bool bool
ircd::path::exists(const std::string &path) ircd::fs::exists(const std::string &path)
try try
{ {
return fs::exists(path); return fs::exists(path);
@ -157,7 +158,7 @@ catch(const fs::filesystem_error &e)
} }
std::string std::string
ircd::path::build(const std::initializer_list<std::string> &list) ircd::fs::make_path(const std::initializer_list<std::string> &list)
{ {
fs::path ret; fs::path ret;
for(const auto &s : list) for(const auto &s : list)
@ -167,7 +168,7 @@ ircd::path::build(const std::initializer_list<std::string> &list)
} }
const char * const char *
ircd::path::get(index index) ircd::fs::get(index index)
noexcept try noexcept try
{ {
return std::get<PATH>(paths.at(index)).c_str(); return std::get<PATH>(paths.at(index)).c_str();
@ -178,7 +179,7 @@ catch(const std::out_of_range &e)
} }
const char * const char *
ircd::path::name(index index) ircd::fs::name(index index)
noexcept try noexcept try
{ {
return std::get<NAME>(paths.at(index)).c_str(); return std::get<NAME>(paths.at(index)).c_str();