From 70062c72cc7f0acef94a333247cc07df74cd3626 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Fri, 19 May 2017 11:41:16 +0200 Subject: Add file_empty(), extend path_entry() to return size --- libbutl/filesystem.ixx | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'libbutl/filesystem.ixx') 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) { -- cgit v1.1