odb_pack: handle duplicate objects from different packs

This is based on 24634c6fd02b2240e4a93fad70a08220f8fb793a.

This also corrects an issue with error codes being mixed up with the
number of found objects.