Only remove packages if installs occur

This code change means package cleanup will only be run if packages
are installed or upgraded - the most likely reason for those files
to be out of date.

I've tested with no change and with a package install - both seemed
 to work correctly but its not a very comprehensive test.