Fixing portage when it has wedged a package as '-MERGING-'
Portage rocks, but occasionally it pokes itself in the eye. Something I recently had the misfortune of witnessing was that it had somehow put a kink into a package in the local package database when attempting to emerge (in this case re-emerge) it.
The symptom was that it threw an exception that looked like the following:
portage.exception.InvalidAtom: dev-python/-MERGING-docutils:0
The key thing to note there is the '-MERGING-' prefix added to the package name, evidently something that occurs when the emerge is in flight, and which is removed when the emerge finishes/succeeds. Only for whatever reason, that didn't happen, and the package name became corrupted.
Not intuitively knowing how to fix this, I went to the gentoo forums and was rewarded with the suggestion to simply remove the corrupted entry in the pkg database, which is just a directory hierarchy located in /var/db/pkg.
Thus, in this case, I needed to do the following:
emerge -avt --unmerge dev-python/docutils rm -rf /var/db/pkg/dev-python/-MERGING-docutils-0.6 emerge -avt1 dev-python/docutils
The unmerge step was just for precautionary purposes, I'm not sure it's strictly required. As mentioned on that forum thread, care should be taken when doing anything manual in the /var/db/pkg area because that is literally portage's record of what's installed on the system.
At any rate, removal of the buggered directory allowed for successful re-emerging of the package, and I was off and running.