Minor fix for ancestor traversal: just match the leaf directory, not the full path