Ticket/20308 file serving recursion

Fixes the issue in #20308 where some files didn't appear when serving a directory recursively. Cleans up the code significantly.