From 1f8e2fe1729c68bbe7b173378ce7c9d7bb14f582 Mon Sep 17 00:00:00 2001 From: Zac Medico Date: Wed, 23 May 2007 04:47:36 +0000 Subject: Pass a temporary file name to the package phase in the environment variable PORTAGE_BINPKG_TMPFILE and move the temporary file into place inside binarytree.inject(). This allows binarytree.inject() to perform the move while holding a lock. svn path=/main/trunk/; revision=6591 --- pym/emerge/__init__.py | 7 ++++++- pym/portage/dbapi/bintree.py | 27 ++++++++++++++++++++++++--- 2 files changed, 30 insertions(+), 4 deletions(-) (limited to 'pym') diff --git a/pym/emerge/__init__.py b/pym/emerge/__init__.py index 8a8bbfbe8..2cff1ed41 100644 --- a/pym/emerge/__init__.py +++ b/pym/emerge/__init__.py @@ -3157,13 +3157,18 @@ class MergeTask(object): (mergecount, len(mymergelist), pkg_key) emergelog(xterm_titles, msg, short_msg=short_msg) self.trees[myroot]["bintree"].prevent_collision(pkg_key) + binpkg_tmpfile = os.path.join(pkgsettings["PKGDIR"], + pkg_key + ".tbz2." + str(os.getpid())) + pkgsettings["PORTAGE_BINPKG_TMPFILE"] = binpkg_tmpfile + pkgsettings.backup_changes("PORTAGE_BINPKG_TMPFILE") retval = portage.doebuild(y, "package", myroot, pkgsettings, self.edebug, mydbapi=portdb, tree="porttree") + del pkgsettings["PORTAGE_BINPKG_TMPFILE"] if retval != os.EX_OK: return retval bintree = self.trees[myroot]["bintree"] - bintree.inject(pkg_key) + bintree.inject(pkg_key, filename=binpkg_tmpfile) if "--buildpkgonly" not in self.myopts: msg = " === (%s of %s) Merging (%s::%s)" % \ (mergecount, len(mymergelist), pkg_key, y) diff --git a/pym/portage/dbapi/bintree.py b/pym/portage/dbapi/bintree.py index dda35ce65..fcceb5e0d 100644 --- a/pym/portage/dbapi/bintree.py +++ b/pym/portage/dbapi/bintree.py @@ -557,16 +557,32 @@ class binarytree(object): continue self.populated=1 - def inject(self, cpv): + def inject(self, cpv, filename=None): """Add a freshly built package to the database. This updates - $PKGDIR/Packages with the new package metadata (including MD5).""" + $PKGDIR/Packages with the new package metadata (including MD5). + @param cpv: The cpv of the new package to inject + @type cpv: string + @param filename: File path of the package to inject, or None if it's + already in the location returned by getname() + @type filename: string + @rtype: None + """ + mycat, mypkg = catsplit(cpv) if not self.populated and self._all_directory: + if filename is not None: + # In order to avoid population, don't call getname() here. + os.rename(filename, os.path.join( + self.pkgdir, "All", mypkg + ".tbz2")) + self._create_symlink(cpv) # There's nothing to update in this case, since the Packages # index is not created when $PKGDIR/All/ exists. return if not self.populated: self.populate() - full_path = self.getname(cpv) + if filename is None: + full_path = self.getname(cpv) + else: + full_path = filename try: s = os.stat(full_path) except OSError, e: @@ -589,6 +605,9 @@ class binarytree(object): self.dbapi._aux_cache.pop(cpv, None) if self._all_directory: + if filename is not None: + os.rename(filename, self.getname(cpv)) + self._create_symlink(cpv) return # Reread the Packages index (in case it's been changed by another @@ -598,6 +617,8 @@ class binarytree(object): try: pkgindex_lock = lockfile(self._pkgindex_file, wantnewlockfile=1) + if filename is not None: + os.rename(filename, self.getname(cpv)) pkgindex = portage.getbinpkg.PackageIndex() try: f = open(self._pkgindex_file) -- cgit v1.2.3-1-g7c22