(PUP-3604) Rework handling of :ensure with a version

There's an increasing amount of code in this method, could we extract a method to handle generating the full name?