copied some fixes from pacman-4.1