Skip to content

Commit 3fa9272

Browse files
committed
Updated with the behavior of SHFileOperationW().
1 parent bc5973d commit 3fa9272

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

llvm/lib/Support/Windows/Path.inc

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1387,29 +1387,31 @@ std::error_code remove_directories(const Twine &path, bool IgnoreErrors) {
13871387
Path16.push_back(0);
13881388
Path16.push_back(0);
13891389

1390-
HRESULT HR = CoInitializeEx(NULL, COINIT_MULTITHREADED);
1390+
HRESULT HR =
1391+
CoInitializeEx(NULL, COINIT_APARTMENTTHREADED | COINIT_DISABLE_OLE1DDE);
13911392
if (SUCCEEDED(HR)) {
1392-
IFileOperation *FileOp;
1393+
IFileOperation *FileOp = NULL;
13931394
HR = CoCreateInstance(CLSID_FileOperation, NULL, CLSCTX_ALL,
13941395
IID_PPV_ARGS(&FileOp));
13951396
if (SUCCEEDED(HR)) {
13961397
HR = FileOp->SetOperationFlags(FOF_NO_UI | FOFX_NOCOPYHOOKS);
13971398
if (SUCCEEDED(HR)) {
1399+
PIDLIST_ABSOLUTE PIDL = ILCreateFromPathW(Path16.data());
13981400
IShellItem *ShItem = NULL;
1399-
HR = SHCreateItemFromParsingName(Path16.data(), NULL,
1400-
IID_PPV_ARGS(&ShItem));
1401+
HR = SHCreateItemFromIDList(PIDL, IID_PPV_ARGS(&ShItem));
14011402
if (SUCCEEDED(HR)) {
14021403
HR = FileOp->DeleteItem(ShItem, NULL);
1404+
if (SUCCEEDED(HR)) {
1405+
HR = FileOp->PerformOperations();
1406+
}
14031407
ShItem->Release();
14041408
}
1405-
if (SUCCEEDED(HR)) {
1406-
HR = FileOp->PerformOperations();
1407-
}
1409+
ILFree(PIDL);
14081410
}
14091411
FileOp->Release();
14101412
}
1413+
CoUninitialize();
14111414
}
1412-
CoUninitialize();
14131415

14141416
int result = FAILED(HR) ? HRESULT_CODE(HR) : 0;
14151417
if (result != 0 && !IgnoreErrors)

0 commit comments

Comments
 (0)