That's the code as it was pre-#1522. This PR is a bit confusing because it includes a commit to revert #1522. Take a look at the last commit to see what I've actually changed.

That bit of code needs work generally, e.g. the isDirectory call doesn't seem to do anything useful. I'm going to make another issue to do some bigger refactoring after the RC is out.