[llvm] [llvm][Support][Windows] Avoid crash calling remove_directories() (PR #118677)

Dmitry Vasilyev via llvm-commits llvm-commits at lists.llvm.org
Sun Dec 8 03:10:34 PST 2024


slydiman wrote:

> but invoking COM objects just for deleting a set of files/directories does also feel a bit like overkill.

Please note my second commit is the result of disassembling SHFileOperationW(). I have figured out the parameters for   CoInitializeEx() and used ILCreateFromPathW() and SHCreateItemFromIDList() instead of SHCreateItemFromParsingName().
So SHFileOperationW() does it anyway.

> So if possible, using common code shared with Unix, for traversing the file tree and recursively deleting files/directories, sounds like my preferred way forward as well

Note executeBuiltinRm() in llvm/utils/lit/lit/TestRunner.py uses SHFileOperationW() on Windows and just shutil.rmtree() for other OS. Why don't we use shutil.rmtree() for Windows too? I know that shutil.rmtree() cannot delete files marked RO and it is possible to fix it using a custom error handler. But I don't see such handler around shutil.rmtree() in executeBuiltinRm() for non-Windows OS.

> so we should be careful to not re-invent the removal logic if not absolutely necessary. 

For now I will prepare PR to replace SHFileOperationW() with std::filesystem::remove_all() in path.inc for Windows only to minimize possible side effects.

https://github.com/llvm/llvm-project/pull/118677


More information about the llvm-commits mailing list