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.hxx | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) (limited to 'libbutl/filesystem.hxx') diff --git a/libbutl/filesystem.hxx b/libbutl/filesystem.hxx index 4fa1021..a6d7a4a 100644 --- a/libbutl/filesystem.hxx +++ b/libbutl/filesystem.hxx @@ -21,7 +21,7 @@ #endif #include // ptrdiff_t -#include // uint16_t +#include // uint16_t, etc #include // move(), pair #include #include @@ -73,23 +73,37 @@ namespace butl other }; + // Filesystem entry info. The size is only meaningful for regular files. + // + struct entry_stat + { + entry_type type; + std::uint64_t size; + }; + // Return a flag indicating if the path is to an existing file system entry // and its type if so. Note that by default this function doesn't follow // symlinks. // - LIBBUTL_EXPORT std::pair + LIBBUTL_EXPORT std::pair path_entry (const char*, bool follow_symlinks = false); - inline std::pair + inline std::pair path_entry (const path& p, bool fs = false) { return path_entry (p.string ().c_str (), fs);} // Return true if the directory is empty. Note that the path must exist - // and be a directory. + // and be a directory. This function follows symlinks. // - LIBBUTL_EXPORT bool + bool dir_empty (const dir_path&); + // Return true if the file is empty. Note that the path must exist and be a + // regular file. This function follows symlinks. + // + bool + file_empty (const path&); + // Try to create a directory unless it already exists. If you expect // the directory to exist and performance is important, then you // should first call dir_exists() above since that's what this -- cgit v1.1