diff options
author | Boris Kolpackov <boris@codesynthesis.com> | 2017-05-19 11:41:16 +0200 |
---|---|---|
committer | Boris Kolpackov <boris@codesynthesis.com> | 2017-05-19 11:41:16 +0200 |
commit | 70062c72cc7f0acef94a333247cc07df74cd3626 (patch) | |
tree | 1b66af2ee26e0bf2e3232fe389a0a22520dbd936 /libbutl/filesystem.ixx | |
parent | cf9d0332f6b4dcd7dc388133ffd8fd6edd07e1c1 (diff) |
Add file_empty(), extend path_entry() to return size
Diffstat (limited to 'libbutl/filesystem.ixx')
-rw-r--r-- | libbutl/filesystem.ixx | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/libbutl/filesystem.ixx b/libbutl/filesystem.ixx index eb9984b..a6fae64 100644 --- a/libbutl/filesystem.ixx +++ b/libbutl/filesystem.ixx @@ -7,9 +7,25 @@ namespace butl inline bool dir_empty (const dir_path& d) { + // @@ Could 0 size be a valid and faster way? + // return dir_iterator (d) == dir_iterator (); } + inline bool + file_empty (const path& f) + { + auto p (path_entry (f)); + + if (p.first && p.second.type == entry_type::regular) + return p.second.size == 0; + + throw_generic_error ( + p.first + ? (p.second.type == entry_type::directory ? EISDIR : EINVAL) + : ENOENT); + } + inline rmdir_status try_rmdir_r (const dir_path& p, bool ignore_error) { |