From 50bdae2c0547051228361e439a72f8be62c3e936 Mon Sep 17 00:00:00 2001 From: Karen Arutyunov Date: Wed, 4 Oct 2017 15:19:47 +0300 Subject: Add ignore_error parameter for path_entry() and *_exists() functions --- libbutl/filesystem.cxx | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) (limited to 'libbutl/filesystem.cxx') diff --git a/libbutl/filesystem.cxx b/libbutl/filesystem.cxx index 8c3abc4..da2f12c 100644 --- a/libbutl/filesystem.cxx +++ b/libbutl/filesystem.cxx @@ -75,34 +75,34 @@ using namespace std; namespace butl { bool - file_exists (const char* p, bool fl) + file_exists (const char* p, bool fl, bool ie) { - auto pe (path_entry (p, fl)); + auto pe (path_entry (p, fl, ie)); return pe.first && (pe.second.type == entry_type::regular || (!fl && pe.second.type == entry_type::symlink)); } bool - entry_exists (const char* p, bool fl) + entry_exists (const char* p, bool fl, bool ie) { - return path_entry (p, fl).first; + return path_entry (p, fl, ie).first; } bool - dir_exists (const char* p) + dir_exists (const char* p, bool ie) { - auto pe (path_entry (p, true)); + auto pe (path_entry (p, true, ie)); return pe.first && pe.second.type == entry_type::directory; } #ifndef _WIN32 pair - path_entry (const char* p, bool fl) + path_entry (const char* p, bool fl, bool ie) { struct stat s; if ((fl ? stat (p, &s) : lstat (p, &s)) != 0) { - if (errno == ENOENT || errno == ENOTDIR) + if (errno == ENOENT || errno == ENOTDIR || ie) return make_pair (false, entry_stat {entry_type::unknown, 0}); else throw_generic_error (errno); @@ -124,7 +124,7 @@ namespace butl } #else pair - path_entry (const char* p, bool) + path_entry (const char* p, bool, bool ie) { // A path like 'C:', while being a root path in our terminology, is not as // such for Windows, that maintains current directory for each drive, and @@ -157,7 +157,7 @@ namespace butl if (_stat64 (p, &s) != 0) { - if (errno == ENOENT || errno == ENOTDIR) + if (errno == ENOENT || errno == ENOTDIR || ie) return make_pair (false, entry_stat {entry_type::unknown, 0}); else throw_generic_error (errno); -- cgit v1.1