diff --git a/include/ircd/fs/fs.h b/include/ircd/fs/fs.h index 12ea7df8d..cabc58429 100644 --- a/include/ircd/fs/fs.h +++ b/include/ircd/fs/fs.h @@ -68,21 +68,19 @@ namespace ircd::fs const char *get(index) noexcept; const char *name(index) noexcept; - std::string make_path(const std::initializer_list &); + std::string make_path(const std::initializer_list &); - bool exists(const std::string &path); - bool is_dir(const std::string &path); - bool is_reg(const std::string &path); - - size_t size(const std::string &path); + bool exists(const string_view &path); + bool is_dir(const string_view &path); + bool is_reg(const string_view &path); size_t size(const string_view &path); - std::vector ls(const std::string &path); - std::vector ls_recursive(const std::string &path); + std::vector ls(const string_view &path); + std::vector ls_recursive(const string_view &path); std::string cwd(); - void chdir(const std::string &path); - bool mkdir(const std::string &path); + void chdir(const string_view &path); + bool mkdir(const string_view &path); extern aio *aioctx; } diff --git a/ircd/fs.cc b/ircd/fs.cc index 1f497f737..8a6cfb5f1 100644 --- a/ircd/fs.cc +++ b/ircd/fs.cc @@ -15,13 +15,17 @@ #include "aio.h" #endif +namespace filesystem = boost::filesystem; + namespace ircd::fs { - using namespace boost::filesystem; - enum { NAME, PATH }; using ent = std::pair; extern const std::array()> paths; + + filesystem::path path(std::string); + filesystem::path path(const string_view &); + filesystem::path path(const std::initializer_list &); } /// Non-null when aio is available for use @@ -195,44 +199,63 @@ ircd::fs::write__std(const string_view &path, } void -ircd::fs::chdir(const std::string &path) +ircd::fs::chdir(const string_view &path) try { - fs::current_path(path); + filesystem::current_path(fs::path(path)); } -catch(const fs::filesystem_error &e) +catch(const filesystem::filesystem_error &e) { - throw filesystem_error("%s", e.what()); + throw filesystem_error + { + "%s", e.what() + }; } bool -ircd::fs::mkdir(const std::string &path) +ircd::fs::mkdir(const string_view &path) try { - return fs::create_directory(path); + return filesystem::create_directory(fs::path(path)); } -catch(const fs::filesystem_error &e) +catch(const filesystem::filesystem_error &e) { - throw filesystem_error("%s", e.what()); + throw filesystem_error + { + "%s", e.what() + }; } std::string ircd::fs::cwd() try { - return fs::current_path().string(); + return filesystem::current_path().string(); } -catch(const fs::filesystem_error &e) +catch(const filesystem::filesystem_error &e) { - throw filesystem_error("%s", e.what()); + throw filesystem_error + { + "%s", e.what() + }; +} +catch(const filesystem::filesystem_error &e) +{ + throw filesystem_error + { + "%s", e.what() + }; } std::vector -ircd::fs::ls_recursive(const std::string &path) +ircd::fs::ls_recursive(const string_view &path) try { - const fs::recursive_directory_iterator end; - fs::recursive_directory_iterator it(path); + const filesystem::recursive_directory_iterator end; + filesystem::recursive_directory_iterator it + { + fs::path(path) + }; std::vector ret; std::transform(it, end, std::back_inserter(ret), [] @@ -243,17 +266,23 @@ try return ret; } -catch(const fs::filesystem_error &e) +catch(const filesystem::filesystem_error &e) { - throw filesystem_error("%s", e.what()); + throw filesystem_error + { + "%s", e.what() + }; } std::vector -ircd::fs::ls(const std::string &path) +ircd::fs::ls(const string_view &path) try { - static const fs::directory_iterator end; - fs::directory_iterator it(path); + static const filesystem::directory_iterator end; + filesystem::directory_iterator it + { + fs::path(path) + }; std::vector ret; std::transform(it, end, std::back_inserter(ret), [] @@ -264,66 +293,94 @@ try return ret; } -catch(const fs::filesystem_error &e) +catch(const filesystem::filesystem_error &e) { - throw filesystem_error("%s", e.what()); + throw filesystem_error + { + "%s", e.what() + }; } size_t ircd::fs::size(const string_view &path) { - return ircd::fs::size(std::string{path}); -} - -size_t -ircd::fs::size(const std::string &path) -{ - return fs::file_size(path); + return filesystem::file_size(fs::path(path)); } bool -ircd::fs::is_reg(const std::string &path) +ircd::fs::is_reg(const string_view &path) try { - return fs::is_regular_file(path); + return filesystem::is_regular_file(fs::path(path)); } -catch(const fs::filesystem_error &e) +catch(const filesystem::filesystem_error &e) { - throw filesystem_error("%s", e.what()); + throw filesystem_error + { + "%s", e.what() + }; } bool -ircd::fs::is_dir(const std::string &path) +ircd::fs::is_dir(const string_view &path) try { - return fs::is_directory(path); + return filesystem::is_directory(fs::path(path)); } -catch(const fs::filesystem_error &e) +catch(const filesystem::filesystem_error &e) { - throw filesystem_error("%s", e.what()); + throw filesystem_error + { + "%s", e.what() + }; } bool -ircd::fs::exists(const std::string &path) +ircd::fs::exists(const string_view &path) try { - return boost::filesystem::exists(path); + return filesystem::exists(fs::path(path)); } -catch(const fs::filesystem_error &e) +catch(const filesystem::filesystem_error &e) { - throw filesystem_error("%s", e.what()); + throw filesystem_error + { + "%s", e.what() + }; } std::string -ircd::fs::make_path(const std::initializer_list &list) +ircd::fs::make_path(const std::initializer_list &list) { - fs::path ret; + filesystem::path ret; for(const auto &s : list) - ret /= fs::path(s); + ret /= path(s); return ret.string(); } +filesystem::path +ircd::fs::path(const std::initializer_list &list) +{ + filesystem::path ret; + for(const auto &s : list) + ret /= path(s); + + return ret.string(); +} + +filesystem::path +ircd::fs::path(const string_view &s) +{ + return path(std::string{s}); +} + +filesystem::path +ircd::fs::path(std::string s) +{ + return filesystem::path(std::move(s)); +} + const char * ircd::fs::get(index index) noexcept try