Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 4 additions & 17 deletions llvm/lib/Support/Windows/Path.inc
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include "llvm/Support/ConvertUTF.h"
#include "llvm/Support/WindowsError.h"
#include <fcntl.h>
#include <filesystem>
#include <sys/stat.h>
#include <sys/types.h>

Expand Down Expand Up @@ -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<char> &Path) {
Expand Down
Loading