The initial patch misses an edge case where a non-file buffer has the same name as a directory. I'll send a new patch with a more robust solution in the next couple of days.