From abce07328c246136f6220fde07192dc739319c43 Mon Sep 17 00:00:00 2001 From: "Michael J. Spencer" Date: Wed, 5 Jan 2011 16:39:22 +0000 Subject: [PATCH] Support/Windows/PathV2: Fix remove to handle both files and directories. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@122882 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Support/Windows/PathV2.inc | 28 +++++++++++++++++++++------- 1 file changed, 21 insertions(+), 7 deletions(-) diff --git a/lib/Support/Windows/PathV2.inc b/lib/Support/Windows/PathV2.inc index c0c70e04726..f3d625797dd 100644 --- a/lib/Support/Windows/PathV2.inc +++ b/lib/Support/Windows/PathV2.inc @@ -268,17 +268,31 @@ error_code remove(const Twine &path, bool &existed) { SmallString<128> path_storage; SmallVector path_utf16; + file_status st; + if (error_code ec = status(path, st)) + return ec; + if (error_code ec = UTF8ToUTF16(path.toStringRef(path_storage), path_utf16)) return ec; - if (!::DeleteFileW(path_utf16.begin())) { - error_code ec = windows_error(::GetLastError()); - if (ec != windows_error::file_not_found) - return ec; - existed = false; - } else - existed = true; + if (st.type() == file_type::directory_file) { + if (!::RemoveDirectoryW(c_str(path_utf16))) { + error_code ec = windows_error(::GetLastError()); + if (ec != windows_error::file_not_found) + return ec; + existed = false; + } else + existed = true; + } else { + if (!::DeleteFileW(c_str(path_utf16))) { + error_code ec = windows_error(::GetLastError()); + if (ec != windows_error::file_not_found) + return ec; + existed = false; + } else + existed = true; + } return success; }