changeset 482:541de6e61ac3

Irccd: use boost::filesystem (fs::isDirectory), #594
author David Demelier <markand@malikania.fr>
date Thu, 16 Feb 2017 13:04:58 +0100
parents fe39fc9700d0
children b6bc4ddf791c
files libcommon/irccd/fs.hpp libirccd-js/irccd/mod-directory.cpp
diffstat 2 files changed, 5 insertions(+), 13 deletions(-) [+]
line wrap: on
line diff
--- a/libcommon/irccd/fs.hpp	Thu Feb 16 13:00:54 2017 +0100
+++ b/libcommon/irccd/fs.hpp	Thu Feb 16 13:04:58 2017 +0100
@@ -194,15 +194,6 @@
 IRCCD_EXPORT bool isFile(const std::string &path);
 
 /**
- * Check if the file is a directory.
- *
- * \param path the path
- * \return true if it is a directory and false if not or not readable
- * \throw std::runtime_error if the operation is not supported
- */
-IRCCD_EXPORT bool isDirectory(const std::string &path);
-
-/**
  * Read a directory and return a list of entries (not recursive).
  *
  * \param path the directory path
--- a/libirccd-js/irccd/mod-directory.cpp	Thu Feb 16 13:00:54 2017 +0100
+++ b/libirccd-js/irccd/mod-directory.cpp	Thu Feb 16 13:04:58 2017 +0100
@@ -171,10 +171,11 @@
  */
 duk_ret_t remove(duk_context *ctx, const std::string &path, bool recursive)
 {
-    if (!fs::isDirectory(path))
+    boost::system::error_code ec;
+
+    if (!boost::filesystem::is_directory(path, ec) || ec) {
         dukx_throw(ctx, SystemError(EINVAL, "not a directory"));
-
-    boost::system::error_code ec;
+    }
 
     if (!recursive) {
         boost::filesystem::remove(path, ec);
@@ -254,7 +255,7 @@
         std::string path = duk_require_string(ctx, 0);
         std::int8_t flags = duk_get_uint(ctx, 1);
 
-        if (!fs::isDirectory(path))
+        if (!boost::filesystem::is_directory(path))
             dukx_throw(ctx, SystemError(EINVAL, "not a directory"));
 
         std::vector<fs::Entry> list = fs::readdir(path, flags);