diff options
author | Michael J. Spencer <bigcheesegs@gmail.com> | 2011-01-05 16:39:22 +0000 |
---|---|---|
committer | Michael J. Spencer <bigcheesegs@gmail.com> | 2011-01-05 16:39:22 +0000 |
commit | 153749b30b983d6b6a7a62868857d848e227a40e (patch) | |
tree | 9c94ee92a3da15b1dfa35af1ed518a855bf541d0 /llvm | |
parent | f8dc1868e294649ff1f2c7cf562b31b18c54e65c (diff) | |
download | bcm5719-llvm-153749b30b983d6b6a7a62868857d848e227a40e.tar.gz bcm5719-llvm-153749b30b983d6b6a7a62868857d848e227a40e.zip |
Support/Windows/PathV2: Fix remove to handle both files and directories.
llvm-svn: 122882
Diffstat (limited to 'llvm')
-rw-r--r-- | llvm/lib/Support/Windows/PathV2.inc | 28 |
1 files changed, 21 insertions, 7 deletions
diff --git a/llvm/lib/Support/Windows/PathV2.inc b/llvm/lib/Support/Windows/PathV2.inc index c0c70e04726..f3d625797dd 100644 --- a/llvm/lib/Support/Windows/PathV2.inc +++ b/llvm/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; } |