aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/Support/Windows/PathV2.inc28
1 files changed, 21 insertions, 7 deletions
diff --git a/lib/Support/Windows/PathV2.inc b/lib/Support/Windows/PathV2.inc
index c0c70e0472..f3d625797d 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<wchar_t, 128> 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;
}