From: Jeff Cohen Date: Sat, 7 Apr 2007 20:47:27 +0000 (+0000) Subject: Unbreak VC++ build. X-Git-Url: http://plrg.eecs.uci.edu/git/?a=commitdiff_plain;h=31102896e5cecdc2b28edd52bb0599d3bc91d24e;p=oota-llvm.git Unbreak VC++ build. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@35751 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/System/Win32/Path.inc b/lib/System/Win32/Path.inc index 937bb51fa63..f28fe86b59b 100644 --- a/lib/System/Win32/Path.inc +++ b/lib/System/Win32/Path.inc @@ -368,11 +368,15 @@ bool Path::makeExecutableOnDisk(std::string* ErrMsg) { bool Path::getDirectoryContents(std::set& result, std::string* ErrMsg) const { - const FileStatus *Status = getFileStatus(false, ErrMsg); - if (!Status) + WIN32_FILE_ATTRIBUTE_DATA fi; + if (!GetFileAttributesEx(path.c_str(), GetFileExInfoStandard, &fi)) { + MakeErrMsg(ErrMsg, path + ": can't get status of file"); return true; - if (!Status->isDir) { - MakeErrMsg(ErrMsg, path + ": not a directory"); + } + + if (!(fi.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)) { + if (ErrMsg) + *ErrMsg = path + ": not a directory"; return true; } @@ -565,28 +569,11 @@ Path::createFileOnDisk(std::string* ErrMsg) { bool Path::eraseFromDisk(bool remove_contents, std::string *ErrStr) const { - const FileStatus *Status = getFileStatus(false, ErrStr); - if (!Status) - return false; + WIN32_FILE_ATTRIBUTE_DATA fi; + if (!GetFileAttributesEx(path.c_str(), GetFileExInfoStandard, &fi)) + return true; - if (Status->isFile) { - DWORD attr = GetFileAttributes(path.c_str()); - - // If it doesn't exist, we're done. - if (attr == INVALID_FILE_ATTRIBUTES) - return false; - - // Read-only files cannot be deleted on Windows. Must remove the read-only - // attribute first. - if (attr & FILE_ATTRIBUTE_READONLY) { - if (!SetFileAttributes(path.c_str(), attr & ~FILE_ATTRIBUTE_READONLY)) - return MakeErrMsg(ErrStr, path + ": Can't destroy file: "); - } - - if (!DeleteFile(path.c_str())) - return MakeErrMsg(ErrStr, path + ": Can't destroy file: "); - return false; - } else if (Status->isDir) { + if (fi.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) { // If it doesn't exist, we're done. if (!exists()) return false; @@ -645,9 +632,19 @@ Path::eraseFromDisk(bool remove_contents, std::string *ErrStr) const { return MakeErrMsg(ErrStr, std::string(pathname) + ": Can't destroy directory: "); return false; - } - // It appears the path doesn't exist. - return true; + } else { + // Read-only files cannot be deleted on Windows. Must remove the read-only + // attribute first. + if (fi.dwFileAttributes & FILE_ATTRIBUTE_READONLY) { + if (!SetFileAttributes(path.c_str(), + fi.dwFileAttributes & ~FILE_ATTRIBUTE_READONLY)) + return MakeErrMsg(ErrStr, path + ": Can't destroy file: "); + } + + if (!DeleteFile(path.c_str())) + return MakeErrMsg(ErrStr, path + ": Can't destroy file: "); + return false; + } } bool Path::getMagicNumber(std::string& Magic, unsigned len) const { diff --git a/lib/System/Win32/Signals.inc b/lib/System/Win32/Signals.inc index 8adf7674faf..7da0c751136 100644 --- a/lib/System/Win32/Signals.inc +++ b/lib/System/Win32/Signals.inc @@ -101,12 +101,15 @@ bool sys::RemoveFileOnSignal(const sys::Path &Filename, std::string* ErrMsg) { // RemoveDirectoryOnSignal - The public API bool sys::RemoveDirectoryOnSignal(const sys::Path& path, std::string* ErrMsg) { // Not a directory? - const sys::FileStatus *Status = path.getFileStatus(false, ErrMsg); - if (!Status) + WIN32_FILE_ATTRIBUTE_DATA fi; + if (!GetFileAttributesEx(path.c_str(), GetFileExInfoStandard, &fi)) { + MakeErrMsg(ErrMsg, path.toString() + ": can't get status of file"); return true; - if (!Status->isDir) { + } + + if (!(fi.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)) { if (ErrMsg) - *ErrMsg = path.toString() + " is not a directory"; + *ErrMsg = path.toString() + ": not a directory"; return true; }