Rewrite flatpak_dir_list_unused_refs_with_options()

This simplifies the implementation and makes it more effective in
avoiding to re-scan the same things several times.
This commit is contained in:
Internal Server Error - Gitea: Git with a cup of tea
500 Internal Server Error

Gitea Version: 1.28.0+dev-477-g8b6ad49a5f