summaryrefslogtreecommitdiff
path: root/lib/Support/Windows/PathV2.inc
diff options
context:
space:
mode:
authorMichael J. Spencer <bigcheesegs@gmail.com>2011-01-05 16:39:22 +0000
committerMichael J. Spencer <bigcheesegs@gmail.com>2011-01-05 16:39:22 +0000
commitabce07328c246136f6220fde07192dc739319c43 (patch)
tree829981b25535b3afae70c08b2ac8432a808716a5 /lib/Support/Windows/PathV2.inc
parent5bcdc7f7c4f1b5aa053b07a4b2ea95b750ed1715 (diff)
downloadllvm-abce07328c246136f6220fde07192dc739319c43.tar.gz
llvm-abce07328c246136f6220fde07192dc739319c43.tar.bz2
llvm-abce07328c246136f6220fde07192dc739319c43.tar.xz
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
Diffstat (limited to 'lib/Support/Windows/PathV2.inc')
-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;
}