From e297edc38785ae5931685f6b1d6efdef97fc5c10 Mon Sep 17 00:00:00 2001 From: Mikko Rasa Date: Mon, 9 Jul 2012 17:44:16 +0300 Subject: [PATCH] Return an empty Stat object for nonexistent files on Windows --- source/fs/stat.cpp | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/source/fs/stat.cpp b/source/fs/stat.cpp index f5e914e..d61081b 100644 --- a/source/fs/stat.cpp +++ b/source/fs/stat.cpp @@ -94,7 +94,13 @@ Stat Stat::stat(const Path &path) HANDLE handle; handle = CreateFile(path.str().c_str(), 0, FILE_SHARE_READ, 0, OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, 0); if(handle==INVALID_HANDLE_VALUE) - throw system_error("CreateFile"); + { + DWORD err = GetLastError(); + if(err==ERROR_FILE_NOT_FOUND) + return Stat(); + else + throw system_error("CreateFile", err); + } BY_HANDLE_FILE_INFORMATION info; if(!GetFileInformationByHandle(handle, &info)) -- 2.43.0