bintree: always populate pkgindex REPO header
authorZac Medico <zmedico@gentoo.org>
Fri, 10 Jun 2011 12:04:17 +0000 (05:04 -0700)
committerZac Medico <zmedico@gentoo.org>
Fri, 10 Jun 2011 12:04:17 +0000 (05:04 -0700)
The previous code would only populate it when there was no existing
index file. Now, the default will be populated even if the file exists
already. If an existing pkgindex header already defines these keys,
then they will appropriately override our defaults.

pym/portage/dbapi/bintree.py

index ffa296c29723342debd77d012708ee2ee51a887e..756ea67117389a75973ff9dd31bb6e0deabccc46 100644 (file)
@@ -270,9 +270,23 @@ class binarytree(object):
                                "REQUIRED_USE" : ""
                        }
                        self._pkgindex_inherited_keys = ["CHOST", "repository"]
+
+                       # Populate the header with appropriate defaults.
                        self._pkgindex_default_header_data = {
-                               "repository":""
+                               "VERSION"      : str(self._pkgindex_version),
+                               "repository"   : "",
                        }
+
+                       # It is especially important to populate keys like
+                       # "repository" that save space when entries can
+                       # inherit them from the header. If an existing
+                       # pkgindex header already defines these keys, then
+                       # they will appropriately override our defaults.
+                       main_repo = self.settings.repositories.mainRepo()
+                       if main_repo is not None:
+                               self._pkgindex_default_header_data["repository"] = \
+                                       main_repo.name
+
                        self._pkgindex_translated_keys = (
                                ("DESCRIPTION"   ,   "DESC"),
                                ("repository"    ,   "REPO"),
@@ -284,7 +298,6 @@ class binarytree(object):
                                self._pkgindex_hashes,
                                self._pkgindex_default_pkg_data,
                                self._pkgindex_inherited_keys,
-                               self._pkgindex_default_header_data,
                                chain(*self._pkgindex_translated_keys)
                        ))
 
@@ -1280,14 +1293,7 @@ class binarytree(object):
                                mode='r', encoding=_encodings['repo.content'],
                                errors='replace')
                except EnvironmentError:
-                       # We're creating a new file, so populate the header
-                       # with appropriate defaults. This is especially
-                       # important for keys like REPO that save space when
-                       # entries can inherit them from the header.
-                       pkgindex.header["VERSION"] = str(self._pkgindex_version)
-                       main_repo = self.settings.repositories.mainRepo()
-                       if main_repo is not None:
-                               pkgindex.header["REPO"] = main_repo.name
+                       pass
                else:
                        try:
                                pkgindex.read(f)