This whole method was copied from rubygems verbatim, except for the YAML changes at the top. It's awful code, but I don't want to mess with the rubygems gods.