Mercurial > irccd
changeset 477:bf201d09ee6a
Irccd: use boost::filesystem (fs::exists), #594
author | David Demelier <markand@malikania.fr> |
---|---|
date | Tue, 14 Feb 2017 13:05:42 +0100 |
parents | a2c61f1e548a |
children | 585427943384 |
files | irccdctl/main.cpp libcommon/CMakeLists.txt libcommon/irccd/fs.cpp libcommon/irccd/fs.hpp libcommon/irccd/path.cpp libirccd-js/irccd/mod-file.cpp libirccd-js/irccd/plugin-js.cpp |
diffstat | 7 files changed, 23 insertions(+), 30 deletions(-) [+] |
line wrap: on
line diff
--- a/irccdctl/main.cpp Tue Nov 06 11:09:42 2018 +0100 +++ b/irccdctl/main.cpp Tue Feb 14 13:05:42 2017 +0100 @@ -18,6 +18,8 @@ #include <unordered_map> +#include <boost/filesystem.hpp> + #include <format.h> #include "alias.hpp" @@ -559,9 +561,10 @@ read(it->second); else { for (const std::string &dir : path::list(path::PathConfig)) { + boost::system::error_code ec; std::string path = dir + "irccdctl.conf"; - if (fs::exists(path)) { + if (boost::filesystem::exists(path, ec) && !ec) { read(path); break; }
--- a/libcommon/CMakeLists.txt Tue Nov 06 11:09:42 2018 +0100 +++ b/libcommon/CMakeLists.txt Tue Feb 14 13:05:42 2017 +0100 @@ -18,6 +18,8 @@ project(libcommon) +find_package(Boost 1.60 REQUIRED COMPONENTS filesystem system) + set( HEADERS ${libcommon_SOURCE_DIR}/irccd/elapsed-timer.hpp @@ -59,11 +61,13 @@ LIBRARIES extern-fmt extern-json + ${Boost_LIBRARIES} $<$<BOOL:${WIN32}>:shlwapi> $<$<BOOL:${WIN32}>:ws2_32> $<$<BOOL:${WITH_SSL}>:OpenSSL::SSL> $<$<BOOL:${WITH_SSL}>:OpenSSL::Crypto> PUBLIC_INCLUDES + ${Boost_INCLUDE_DIRS} $<BUILD_INTERFACE:${IRCCD_FAKEROOTDIR}/include/irccd> $<BUILD_INTERFACE:${IRCCD_FAKEROOTDIR}/include> $<BUILD_INTERFACE:${libcommon_SOURCE_DIR}/irccd>
--- a/libcommon/irccd/fs.cpp Tue Nov 06 11:09:42 2018 +0100 +++ b/libcommon/irccd/fs.cpp Tue Feb 14 13:05:42 2017 +0100 @@ -320,21 +320,6 @@ #endif /* - * exists. - * ------------------------------------------------------------------ - */ -bool exists(const std::string &path) noexcept -{ -#if defined(FS_HAVE_STAT) - struct stat st; - - return ::stat(path.c_str(), &st) == 0; -#else - return hasAccess(path, "r"); -#endif -} - -/* * readdir. * ------------------------------------------------------------------ */
--- a/libcommon/irccd/fs.hpp Tue Nov 06 11:09:42 2018 +0100 +++ b/libcommon/irccd/fs.hpp Tue Feb 14 13:05:42 2017 +0100 @@ -169,17 +169,6 @@ #endif // !HAVE_STAT /** - * Check if a file exists. - * - * If HAVE_ACCESS is defined, the function access is used, otherwise stat is - * used. - * - * \param path the path to check - * \return true if the path exists - */ -IRCCD_EXPORT bool exists(const std::string &path) noexcept; - -/** * Check if the path is absolute. * * \param path the path
--- a/libcommon/irccd/path.cpp Tue Nov 06 11:09:42 2018 +0100 +++ b/libcommon/irccd/path.cpp Tue Feb 14 13:05:42 2017 +0100 @@ -21,6 +21,8 @@ #include <sstream> #include <stdexcept> +#include <boost/filesystem.hpp> + #include "sysconfig.hpp" #if defined(IRCCD_SYSTEM_WINDOWS) @@ -398,9 +400,10 @@ std::string name = fs::baseName(argv0); for (const auto &dir : util::split(sys::env("PATH"), std::string(1, Separator))) { + boost::system::error_code ec; std::string path = dir + fs::separator() + name; - if (fs::exists(path)) { + if (boost::filesystem::exists(path, ec) && !ec) { base = path; break; }
--- a/libirccd-js/irccd/mod-file.cpp Tue Nov 06 11:09:42 2018 +0100 +++ b/libirccd-js/irccd/mod-file.cpp Tue Feb 14 13:05:42 2017 +0100 @@ -22,6 +22,8 @@ #include <iterator> #include <vector> +#include <boost/filesystem.hpp> + #include "sysconfig.hpp" #if defined(HAVE_STAT) @@ -554,7 +556,11 @@ */ duk_ret_t functionExists(duk_context *ctx) { - duk_push_boolean(ctx, fs::exists(duk_require_string(ctx, 0))); + try { + duk_push_boolean(ctx, boost::filesystem::exists(duk_require_string(ctx, 0))); + } catch (...) { + duk_push_boolean(ctx, false); + } return 1; }
--- a/libirccd-js/irccd/plugin-js.cpp Tue Nov 06 11:09:42 2018 +0100 +++ b/libirccd-js/irccd/plugin-js.cpp Tue Feb 14 13:05:42 2017 +0100 @@ -16,6 +16,8 @@ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ +#include <boost/filesystem.hpp> + #include "sysconfig.hpp" #if defined(HAVE_STAT) @@ -105,9 +107,10 @@ // Use the first existing directory available. for (const auto &p : path::list(type)) { + boost::system::error_code ec; foundpath = path::clean(p + append); - if (fs::exists(foundpath)) { + if (boost::filesystem::exists(foundpath, ec) && !ec) { found = true; break; }