From 4e2024e2e6b8309f2db6548e04e920f565a84b0b Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Thu, 18 Mar 2021 15:47:49 +0200 Subject: Add try_rmfile_ignore_error() --- libbutl/filesystem.mxx | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) (limited to 'libbutl/filesystem.mxx') diff --git a/libbutl/filesystem.mxx b/libbutl/filesystem.mxx index 935fc3f..7506439 100644 --- a/libbutl/filesystem.mxx +++ b/libbutl/filesystem.mxx @@ -42,12 +42,14 @@ import std.core; #endif import butl.path; +import butl.optional; import butl.timestamp; import butl.path_pattern; // path_match_flags import butl.utility; // operator<<(ostream,exception), throw_generic_error() #else #include +#include #include #include @@ -60,7 +62,8 @@ LIBBUTL_MODEXPORT namespace butl { // Return true if the path is to an existing regular file. Note that by // default this function follows symlinks. Underlying OS errors are reported - // by throwing std::system_error, unless ignore_error is true. + // by throwing std::system_error, unless ignore_error is true (in which case + // erroneous entries are treated as non-existent). // LIBBUTL_SYMEXPORT bool file_exists (const char*, @@ -73,7 +76,8 @@ LIBBUTL_MODEXPORT namespace butl // Return true if the path is to an existing directory. Note that this // function follows symlinks. Underlying OS errors are reported by throwing - // std::system_error, unless ignore_error is true. + // std::system_error, unless ignore_error is true (in which case erroneous + // entries are treated as non-existent). // LIBBUTL_SYMEXPORT bool dir_exists (const char*, bool ignore_error = false); @@ -84,7 +88,8 @@ LIBBUTL_MODEXPORT namespace butl // Return true if the path is to an existing file system entry. Note that by // default this function doesn't follow symlinks. Underlying OS errors are - // reported by throwing std::system_error, unless ignore_error is true. + // reported by throwing std::system_error, unless ignore_error is true (in + // which case erroneous entries are treated as non-existent). // LIBBUTL_SYMEXPORT bool entry_exists (const char*, @@ -117,7 +122,8 @@ LIBBUTL_MODEXPORT namespace butl // Return a flag indicating if the path is to an existing filesystem entry // and its info if so. Note that by default this function doesn't follow // symlinks. Underlying OS errors are reported by throwing - // std::system_error, unless ignore_error is true. + // std::system_error, unless ignore_error is true (in which case erroneous + // entries are treated as non-existent). // LIBBUTL_SYMEXPORT std::pair path_entry (const char*, @@ -206,9 +212,12 @@ LIBBUTL_MODEXPORT namespace butl // is not atomic. It is also not atomic for the directory-type reparse point // removal. // - LIBBUTL_SYMEXPORT rmfile_status + rmfile_status try_rmfile (const path&, bool ignore_error = false); + optional + try_rmfile_ignore_error (const path&); + // Automatically try to remove a non-empty path on destruction unless // cancelled. Since the non-cancelled destruction will normally happen as a // result of an exception, the failure to remove the path is silently -- cgit v1.1