From 2429c833ff9bb47c98804111acb9b18bb7aed792 Mon Sep 17 00:00:00 2001 From: Fabian Groffen Date: Wed, 21 May 2008 17:37:05 +0000 Subject: [PATCH] Merged from trunk 10359:10377 | 10360 | Tweak vardbapi.aux_get() cache logic a bit. | | zmedico | | | 10361 | In unmerge(), flush the vardbapi aux_get() cache to disk | | zmedico | before releasing the vardb lock. | | 10364 | Exclude "env" from use in variable substitution since we | | zmedico | want to avoid any interaction with the calling environment | | | that might lead to unexpected results. | | 10367 | Fix vardbapi.aux_get() logic so that it will correctly pull | | zmedico | the metadata value corresponding to an unrecognized metadata | | | key. | | 10369 | Validate and normalize target_root earlier in the config | | zmedico | constructor. | | 10372 | Adjust code order to organize it a bit. (branches/2.1.2 | | zmedico | r10371) | | 10373 | Inside vardbapi.aux_get(), do more validation on the cache | | zmedico | data to ensure it contains the expected data types. | | 10375 | In vardbapi.aux_get(), don't mark cacheed metadata invalid | | zmedico | just because some of the values are missing. | | 10377 | Simplify cache code in vardbapi.aux_get(). | | zmedico | | svn path=/main/branches/prefix/; revision=10385 --- pym/_emerge/__init__.py | 1 + pym/portage/__init__.py | 30 ++++++++++++++++-------------- pym/portage/dbapi/vartree.py | 27 +++++++++++++++------------ 3 files changed, 32 insertions(+), 26 deletions(-) diff --git a/pym/_emerge/__init__.py b/pym/_emerge/__init__.py index 7f2950179..118d12ff8 100644 --- a/pym/_emerge/__init__.py +++ b/pym/_emerge/__init__.py @@ -6361,6 +6361,7 @@ def unmerge(root_config, myopts, unmerge_action, return 0 finally: if vdb_lock: + vartree.dbapi.flush_cache() portage.locks.unlockdir(vdb_lock) from portage.sets.base import EditablePackageSet diff --git a/pym/portage/__init__.py b/pym/portage/__init__.py index 610d2a7ed..10dd13270 100644 --- a/pym/portage/__init__.py +++ b/pym/portage/__init__.py @@ -1285,18 +1285,27 @@ class config(object): if target_root is None: target_root = "/" + target_root = normalize_path(os.path.abspath( + target_root)).rstrip(os.path.sep) + os.path.sep + + portage.util.ensure_dirs(target_root + EPREFIX_LSTRIP) + check_var_directory("ROOT", target_root + EPREFIX_LSTRIP) + # The expand_map is used for variable substitution # in getconfig() calls, and the getconfig() calls # update expand_map with the value of each variable # assignment that occurs. Variable substitution occurs - # in the following order: + # in the following order, which corresponds to the + # order of appearance in self.lookuplist: # # * env.d - # * env # * make.globals # * make.defaults # * make.conf # + # Notably absent is "env", since we want to avoid any + # interaction with the calling environment that might + # lead to unexpected results. expand_map = {} env_d = getconfig(os.path.join(target_root + EPREFIX_LSTRIP, "etc", "profile.env"), @@ -1308,12 +1317,6 @@ class config(object): # backupenv is used for calculating incremental variables. self.backupenv = os.environ.copy() - expand_map.update(self.backupenv) - - # make.globals should not be relative to config_root - # because it only contains constants. - self.mygcfg = getconfig(os.path.join(BPREFIX, "etc", "make.globals"), - expand=expand_map) if env_d: # Remove duplicate values so they don't override updated @@ -1329,6 +1332,11 @@ class config(object): self.configdict["env"] = self.backupenv.copy() + # make.globals should not be relative to config_root + # because it only contains constants. + self.mygcfg = getconfig(os.path.join(BPREFIX, "etc", "make.globals"), + expand=expand_map) + if self.mygcfg is None: self.mygcfg = {} @@ -1396,12 +1404,6 @@ class config(object): cfg.pop(blacklisted, None) del blacklisted, cfg - target_root = normalize_path(os.path.abspath( - target_root)).rstrip(os.path.sep) + os.path.sep - - portage.util.ensure_dirs(target_root + EPREFIX_LSTRIP) - check_var_directory("ROOT", target_root + EPREFIX_LSTRIP) - self["PORTAGE_CONFIGROOT"] = config_root self.backup_changes("PORTAGE_CONFIGROOT") self["ROOT"] = target_root diff --git a/pym/portage/dbapi/vartree.py b/pym/portage/dbapi/vartree.py index 5f4e947a2..dc6de78cd 100644 --- a/pym/portage/dbapi/vartree.py +++ b/pym/portage/dbapi/vartree.py @@ -715,33 +715,36 @@ class vardbapi(dbapi): raise KeyError(mycpv) mydir_mtime = long(mydir_stat.st_mtime) pkg_data = self._aux_cache["packages"].get(mycpv) + pull_me = cache_these.union(wants) mydata = {} cache_valid = False cache_incomplete = False + cache_mtime = None + metadata = None + if pkg_data is not None: + if not isinstance(pkg_data, tuple) or len(pkg_data) != 2: + pkg_data = None + else: + cache_mtime, metadata = pkg_data + if not isinstance(cache_mtime, (long, int)) or \ + not isinstance(metadata, dict): + pkg_data = None + if pkg_data: cache_mtime, metadata = pkg_data cache_valid = cache_mtime == mydir_mtime if cache_valid: - cache_incomplete = cache_these.difference(metadata) - if cache_incomplete: - # Allow self._aux_cache_keys to change without a cache version - # bump and efficiently recycle partial cache whenever possible. - cache_valid = False - pull_me = cache_incomplete.union(wants) - else: - pull_me = set(wants).difference(cache_these) mydata.update(metadata) - else: - pull_me = cache_these + pull_me.difference_update(metadata) if pull_me: # pull any needed data and cache it aux_keys = list(pull_me) for k, v in izip(aux_keys, self._aux_get(mycpv, aux_keys)): mydata[k] = v - if not cache_valid or cache_incomplete: + if not cache_valid or cache_these.difference(metadata): cache_data = {} - if cache_incomplete: + if cache_valid and metadata: cache_data.update(metadata) for aux_key in cache_these: cache_data[aux_key] = mydata[aux_key] -- 2.26.2