diff --git a/llvm/lib/Support/Windows/Path.inc b/llvm/lib/Support/Windows/Path.inc index c4bd5e2472351..f433b1824adb6 100644 --- a/llvm/lib/Support/Windows/Path.inc +++ b/llvm/lib/Support/Windows/Path.inc @@ -19,6 +19,7 @@ #include "llvm/Support/ConvertUTF.h" #include "llvm/Support/WindowsError.h" #include +#include #include #include @@ -1378,24 +1379,10 @@ std::error_code remove_directories(const Twine &path, bool IgnoreErrors) { std::error_code EC = widenPath(path, Path16); if (EC && !IgnoreErrors) return EC; - - // SHFileOperation() accepts a list of paths, and so must be double null- - // terminated to indicate the end of the list. The buffer is already null - // terminated, but since that null character is not considered part of the - // vector's size, pushing another one will just consume that byte. So we - // need to push 2 null terminators. - Path16.push_back(0); Path16.push_back(0); - - SHFILEOPSTRUCTW shfos = {}; - shfos.wFunc = FO_DELETE; - shfos.pFrom = Path16.data(); - shfos.fFlags = FOF_NO_UI; - - int result = ::SHFileOperationW(&shfos); - if (result != 0 && !IgnoreErrors) - return mapWindowsError(result); - return std::error_code(); + const std::filesystem::path Path(Path16.data()); + std::filesystem::remove_all(Path, EC); + return IgnoreErrors ? std::error_code() : EC; } static void expandTildeExpr(SmallVectorImpl &Path) {