diff options
author | Zac Medico <zmedico@gentoo.org> | 2007-05-23 00:50:05 +0000 |
---|---|---|
committer | Zac Medico <zmedico@gentoo.org> | 2007-05-23 00:50:05 +0000 |
commit | bdcc125b3a103ce8a8b98099a14e218d79b4a0e0 (patch) | |
tree | 90a654fce4d1cf6d9faf1667f5904c1c9ef17092 /pym/portage | |
parent | e333806ae0a2b7099c3be6179c4ac65abe0e2896 (diff) | |
download | portage-bdcc125b3a103ce8a8b98099a14e218d79b4a0e0.tar.gz portage-bdcc125b3a103ce8a8b98099a14e218d79b4a0e0.tar.bz2 portage-bdcc125b3a103ce8a8b98099a14e218d79b4a0e0.zip |
Lock the Packages index while it's being updated with a packages that was just built.
svn path=/main/trunk/; revision=6589
Diffstat (limited to 'pym/portage')
-rw-r--r-- | pym/portage/dbapi/bintree.py | 48 |
1 files changed, 36 insertions, 12 deletions
diff --git a/pym/portage/dbapi/bintree.py b/pym/portage/dbapi/bintree.py index d74b4a8c5..83c9fecfd 100644 --- a/pym/portage/dbapi/bintree.py +++ b/pym/portage/dbapi/bintree.py @@ -588,20 +588,44 @@ class binarytree(object): md5 = perform_md5(full_path) self.dbapi.cpv_inject(cpv) self.dbapi._aux_cache.pop(cpv, None) - self._pkgindex.packages.pop(cpv, None) - d = {} - d["CPV"] = cpv - d["SLOT"] = slot - d["MTIME"] = str(long(s.st_mtime)) - d["SIZE"] = str(s.st_size) - d["MD5"] = str(md5) - self._pkgindex.packages[cpv] = d - from portage.util import atomic_ofstream - f = atomic_ofstream(os.path.join(self.pkgdir, "Packages")) + + if self._all_directory: + return + + # Reread the Packages index (in case it's been changed by another + # process) and then updated it, all while holding a lock. + from portage.locks import lockfile, unlockfile + pkgindex_lock = None try: - self._pkgindex.write(f) + pkgindex_lock = lockfile(self._pkgindex_file, + wantnewlockfile=1) + self._pkgindex = portage.getbinpkg.PackageIndex() + try: + f = open(self._pkgindex_file) + except EnvironmentError: + pass + else: + try: + self._pkgindex.read(f) + finally: + f.close() + del f + d = {} + d["CPV"] = cpv + d["SLOT"] = slot + d["MTIME"] = str(long(s.st_mtime)) + d["SIZE"] = str(s.st_size) + d["MD5"] = str(md5) + self._pkgindex.packages[cpv] = d + from portage.util import atomic_ofstream + f = atomic_ofstream(os.path.join(self.pkgdir, "Packages")) + try: + self._pkgindex.write(f) + finally: + f.close() finally: - f.close() + if pkgindex_lock: + unlockfile(pkgindex_lock) def exists_specific(self, cpv): if not self.populated: |