vardbapi: acquire lock during counter_tick_core
authorZac Medico <zmedico@gentoo.org>
Sun, 8 May 2011 03:05:21 +0000 (20:05 -0700)
committerZac Medico <zmedico@gentoo.org>
Thu, 12 May 2011 05:17:11 +0000 (22:17 -0700)
pym/portage/dbapi/vartree.py

index 1b13e137135721082496cf7f586f279e66b5d041..1302556fc2ec9d413bf0147dafa52714e63d40e1 100644 (file)
@@ -776,17 +776,25 @@ class vardbapi(dbapi):
                to the global file.  Returns new counter value.
 
                @param myroot: ignored, self._eroot is used instead
+               @param mycpv: ignored
                """
                myroot = None
-               counter = self.get_counter_tick_core(mycpv=mycpv) - 1
-               if incrementing:
-                       #increment counter
-                       counter += 1
-                       # use same permissions as config._init_dirs()
-                       ensure_dirs(os.path.dirname(self._counter_path),
-                               gid=portage_gid, mode=0o2750, mask=0o2)
-                       # update new global counter file
-                       write_atomic(self._counter_path, str(counter))
+               mycpv = None
+
+               self.lock()
+               try:
+                       counter = self.get_counter_tick_core() - 1
+                       if incrementing:
+                               #increment counter
+                               counter += 1
+                               # use same permissions as config._init_dirs()
+                               ensure_dirs(os.path.dirname(self._counter_path),
+                                       gid=portage_gid, mode=0o2750, mask=0o2)
+                               # update new global counter file
+                               write_atomic(self._counter_path, str(counter))
+               finally:
+                       self.unlock()
+
                return counter
 
        def _dblink(self, cpv):