From 5b78d4c4971ea4462e4e017ac3a27a930f8a633e Mon Sep 17 00:00:00 2001 From: John Maddock Date: Tue, 30 Mar 2004 15:19:58 +0000 Subject: [PATCH] filesystem::exists, must check to see why a filesystem stat failed, before assuming that the file does not exist. [SVN r22564] --- src/operations_posix_windows.cpp | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/src/operations_posix_windows.cpp b/src/operations_posix_windows.cpp index d3f1924..15cb3be 100644 --- a/src/operations_posix_windows.cpp +++ b/src/operations_posix_windows.cpp @@ -310,9 +310,23 @@ namespace boost { # ifdef BOOST_POSIX struct stat path_stat; - return ::stat( ph.string().c_str(), &path_stat ) == 0; + if(::stat( ph.string().c_str(), &path_stat ) != 0) + { + if((errno == ENOENT) || (errno == ENOTDIR)) + return false; // stat failed because the path does not exist + // for any other error we assume the file does exist and fall through, + // this may not be the best policy though... (JM 20040330) + } + return true; # else - return ::GetFileAttributesA( ph.string().c_str() ) != 0xFFFFFFFF; + if(::GetFileAttributesA( ph.string().c_str() ) == 0xFFFFFFFF) + { + if((::GetLastError() == ERROR_FILE_NOT_FOUND) || (::GetLastError() == ERROR_PATH_NOT_FOUND)) + return false; // GetFileAttributes failed because the path does not exist + // for any other error we assume the file does exist and fall through, + // this may not be the best policy though... (JM 20040330) + } + return true; # endif }