+1 I’d like to get rid of all EnumerateXXX with callback functions and replace with iterator based equivalents.  Given that in this case the iterator version already exists, I definitely think we should try to use it instead <br><div class="gmail_quote"><div dir="ltr">On Wed, May 30, 2018 at 9:30 AM Pavel Labath via Phabricator <<a href="mailto:reviews@reviews.llvm.org">reviews@reviews.llvm.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">labath added a reviewer: zturner.<br>
labath added a comment.<br>
<br>
In <a href="https://reviews.llvm.org/D47535#1116392" rel="noreferrer" target="_blank">https://reviews.llvm.org/D47535#1116392</a>, @JDevlieghere wrote:<br>
<br>
> In <a href="https://reviews.llvm.org/D47535#1116364" rel="noreferrer" target="_blank">https://reviews.llvm.org/D47535#1116364</a>, @labath wrote:<br>
><br>
> > Actually, I wonder if we shouldn't just deprecate this function altogether. What was your motivation for this patch? It seems we already have `llvm::fs::(recursive_)directory_iterator` for this purpose. It would be great if we could use that for all new code. Have you looked at that?<br>
><br>
><br>
> My motivation is <a href="https://reviews.llvm.org/D47539" rel="noreferrer" target="_blank">https://reviews.llvm.org/D47539</a>. I could use the iterators directly but since the FileSpec one is based on them anyway (and adds some functionality that is actually useful) I figured I might as well use them for consistency. I'm not opposed to using the iterators directly, but won't that result in more code?<br>
<br>
<br>
Looking back at the last refactor of this function (<a href="https://reviews.llvm.org/D30807" rel="noreferrer" target="_blank">https://reviews.llvm.org/D30807</a>)  I think the intention even then was to deprecate/remove it altogether.<br>
<br>
Also, I don't think that this would increase the amount of code. Looking at your patch, it seems that it could be equivalently implemented using llvm iterators as:<br>
<br>
  std::error_code EC;<br>
  for(llvm::sys::fs::recursive_directory_iterator Iter(dir.GetStringRef(), EC), End; Iter != End && !EC ; Iter.incement(EC)) {<br>
    auto Status = Iter->status();<br>
    if (!Status)<br>
      break;<br>
    if (llvm::sys::fs::is_regular_file(*Status) && llvm::sys::fs::can_execute(Status->path())<br>
      executables.push_back(FileSpec(Status->path()));<br>
  }<br>
<br>
which is (a tiny bit) shorter. I also find code with no callbacks more readable.<br>
<br>
<br>
Repository:<br>
  rL LLVM<br>
<br>
<a href="https://reviews.llvm.org/D47535" rel="noreferrer" target="_blank">https://reviews.llvm.org/D47535</a><br>
<br>
<br>
<br>
</blockquote></div>