Refactor rewriting of primary/repomd