[PATCH] D30676: Add llvm::sys::fs::remove_directories()

Zachary Turner via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Mar 7 15:37:12 PST 2017


zturner updated this revision to Diff 90952.
zturner added a comment.

Updated to use a more robust method on Windows.  Also, on non-Windows platforms unfortunately `directory_iterator` will follow symlinks when statting, so directory symlinks will look like ordinary directories.  This is a serious problem for a recursive delete function, because we will walk into the child and delete everything in it.

To err on the side of caution, I've updated `directory_iterator` and `recursive_directory_iterator` to make following symlinks opt-out (this way all existing code is unchanged).  In the deletion function specifically, I use this opt-out flag so that we do not follow symlinks, and we just delete the link itself.

Although it's not explicitly documented what the behavior of `SHFileOperation` is with respect to this, and despite the fact that there is a mysterious flag called `SH_NORECURSEREPARSE` which it claims is "unsupported", I've confirmed that with the code as written, the API does *not* recurse into reparse points (either junctions or symlinks).


https://reviews.llvm.org/D30676

Files:
  llvm/include/llvm/Support/FileSystem.h
  llvm/lib/Support/Path.cpp
  llvm/lib/Support/Unix/Path.inc
  llvm/lib/Support/Windows/Path.inc
  llvm/unittests/Support/Path.cpp

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D30676.90952.patch
Type: text/x-patch
Size: 10522 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20170307/0c8cf365/attachment.bin>


More information about the llvm-commits mailing list