diff options
author | Zac Medico <zmedico@gentoo.org> | 2007-12-28 15:57:52 +0000 |
---|---|---|
committer | Zac Medico <zmedico@gentoo.org> | 2007-12-28 15:57:52 +0000 |
commit | ed22bd8e6d0f995dae84177c9ea1ab3e3cad304d (patch) | |
tree | a67e25cb1cff437de4f8d4dc4f6c9219dd1153f3 | |
parent | e9e6eb58af5ce0794325daba124285c2b00b6d8f (diff) | |
download | portage-ed22bd8e6d0f995dae84177c9ea1ab3e3cad304d.tar.gz portage-ed22bd8e6d0f995dae84177c9ea1ab3e3cad304d.tar.bz2 portage-ed22bd8e6d0f995dae84177c9ea1ab3e3cad304d.zip |
Bug #203090 - Do not trust the global counter
file that can lead to invalid COUNTER generation.
(trunk r9052)
svn path=/main/branches/2.1.2/; revision=9069
-rw-r--r-- | pym/portage.py | 50 |
1 files changed, 37 insertions, 13 deletions
diff --git a/pym/portage.py b/pym/portage.py index ddf0bff69..e8bd8027e 100644 --- a/pym/portage.py +++ b/pym/portage.py @@ -6485,8 +6485,29 @@ class vardbapi(dbapi): def counter_tick(self,myroot,mycpv=None): return self.counter_tick_core(myroot,incrementing=1,mycpv=mycpv) - def get_counter_tick_core(self,myroot,mycpv=None): - return self.counter_tick_core(myroot,incrementing=0,mycpv=mycpv)+1 + def get_counter_tick_core(self, myroot, mycpv=None): + """ + Use this method to retrieve the counter instead + of having to trust the value of a global counter + file that can lead to invalid COUNTER + generation. When cache is valid, the package COUNTER + files are not read and we rely on the timestamp of + the package directory to validate cache. The stat + calls should only take a short time, so performance + is sufficient without having to rely on a potentially + corrupt global counter file. + """ + cp_list = self.cp_list + max_counter = 0 + for cp in self.cp_all(): + for cpv in cp_list(cp): + try: + counter = int(self.aux_get(cpv, ["COUNTER"])[0]) + except (KeyError, OverflowError, ValueError): + continue + if counter > max_counter: + max_counter = counter + return max_counter + 1 def counter_tick_core(self, myroot, incrementing=1, mycpv=None): "This method will grab the next COUNTER value and record it back to the global file. Returns new counter value." @@ -6508,22 +6529,25 @@ class vardbapi(dbapi): writemsg("!!! COUNTER file is corrupt: '%s'\n" % cpath, noiselevel=-1) + real_counter = self.get_counter_tick_core(myroot, mycpv=mycpv) - 1 + if counter < 0: changed = True - max_counter = 0 - cp_list = self.cp_list - for cp in self.cp_all(): - for cpv in cp_list(cp): - try: - counter = int(self.aux_get(cpv, ["COUNTER"])[0]) - except (KeyError, OverflowError, ValueError): - continue - if counter > max_counter: - max_counter = counter - counter = max_counter writemsg("!!! Initializing COUNTER to " + \ "value of %d\n" % counter, noiselevel=-1) + if counter != real_counter: + changed = True + writemsg("!!! Initializing COUNTER to " + \ + "value of %d\n" % counter, noiselevel=-1) + + # Never trust the counter file, since having a + # corrupt value that is too low there can trigger + # incorrect AUTOCLEAN behavior due to newly installed + # packages having lower counters than the previous + # version in the same slot. + counter = real_counter + if incrementing or changed: #increment counter |