autoremove: Exclude locked packages

This was resulting in errors when trying to remove
since they were locked.

This is based on e77874e002d18249a182d31bf08fd5c413a43f76 but
that had many conflicts for release-1.2 branch.

Issue #705