aboutsummaryrefslogtreecommitdiff
path: root/butl
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2016-08-19 18:10:12 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2016-08-19 18:10:12 +0200
commit6aada88dc77a95a7b2726c39e008d4ddcd38d58c (patch)
tree12206f32a4f650860bfccc596c1607e5fb19e0c2 /butl
parent2676fc8d88af82dff1033869823b435d9b91c9b8 (diff)
Add dir_empty() test
Diffstat (limited to 'butl')
-rw-r--r--butl/filesystem12
-rw-r--r--butl/filesystem.cxx8
-rw-r--r--butl/filesystem.ixx6
3 files changed, 19 insertions, 7 deletions
diff --git a/butl/filesystem b/butl/filesystem
index 118fa01..41b9266 100644
--- a/butl/filesystem
+++ b/butl/filesystem
@@ -32,17 +32,23 @@
namespace butl
{
+ // Return true if the path is to an existing regular file. Note that
+ // this function resolves symlinks.
+ //
+ LIBBUTL_EXPORT bool
+ file_exists (const path&);
+
// Return true if the path is to an existing directory. Note that
// this function resolves symlinks.
//
LIBBUTL_EXPORT bool
dir_exists (const path&);
- // Return true if the path is to an existing regular file. Note that
- // this function resolves symlinks.
+ // Return true if the directory is empty. Note that the path must exist
+ // and be a directory.
//
LIBBUTL_EXPORT bool
- file_exists (const path&);
+ dir_empty (const dir_path&);
// Try to create a directory unless it already exists. If you expect
// the directory to exist and performance is important, then you
diff --git a/butl/filesystem.cxx b/butl/filesystem.cxx
index e5819e2..a807f4c 100644
--- a/butl/filesystem.cxx
+++ b/butl/filesystem.cxx
@@ -35,7 +35,7 @@ using namespace std;
namespace butl
{
bool
- dir_exists (const path& p)
+ file_exists (const path& p)
{
#ifndef _WIN32
struct stat s;
@@ -51,11 +51,11 @@ namespace butl
throw system_error (errno, system_category ());
}
- return S_ISDIR (s.st_mode);
+ return S_ISREG (s.st_mode);
}
bool
- file_exists (const path& p)
+ dir_exists (const path& p)
{
#ifndef _WIN32
struct stat s;
@@ -71,7 +71,7 @@ namespace butl
throw system_error (errno, system_category ());
}
- return S_ISREG (s.st_mode);
+ return S_ISDIR (s.st_mode);
}
mkdir_status
diff --git a/butl/filesystem.ixx b/butl/filesystem.ixx
index af1125e..6062c38 100644
--- a/butl/filesystem.ixx
+++ b/butl/filesystem.ixx
@@ -4,6 +4,12 @@
namespace butl
{
+ inline bool
+ dir_empty (const dir_path& d)
+ {
+ return dir_iterator (d) == dir_iterator ();
+ }
+
inline rmdir_status
try_rmdir_r (const dir_path& p, bool ignore_error)
{