From 33545ea18e8816addb3c54bb26a0cc788b8512e6 Mon Sep 17 00:00:00 2001
From: Krzysztof Pawlik <nelchael@gentoo.org>
Date: Fri, 4 May 2012 23:47:27 -0700
Subject: [PATCH] Support COLLISION_IGNORE_UNOWNED="*.pyc *.pyo"

This will fix bug #410691.
---
 cnf/make.globals                                       | 5 +++++
 man/make.conf.5                                        | 7 +++++++
 pym/portage/dbapi/vartree.py                           | 8 ++++++++
 pym/portage/package/ebuild/_config/special_env_vars.py | 5 +++--
 4 files changed, 23 insertions(+), 2 deletions(-)

diff --git a/cnf/make.globals b/cnf/make.globals
index 0f6f54165..5f536c33a 100644
--- a/cnf/make.globals
+++ b/cnf/make.globals
@@ -61,6 +61,11 @@ FEATURES="assume-digests binpkg-logs distlocks ebuild-locks
 # FEATURES=protect-owned to operate smoothly in all cases.
 COLLISION_IGNORE="/lib/modules"
 
+# Ignore file collisions for unowned *.pyo and *.pyc files, this helps during
+# transition from compiling python modules in live file system to compiling
+# them in src_install() function.
+COLLISION_IGNORE_UNOWNED="*.pyc *.pyo"
+
 # Enable preserve-libs for testing with portage versions that support it.
 # This setting is commented out for portage versions that don't support it.
 FEATURES="${FEATURES} preserve-libs"
diff --git a/man/make.conf.5 b/man/make.conf.5
index e8777c840..7b1d4c046 100644
--- a/man/make.conf.5
+++ b/man/make.conf.5
@@ -134,6 +134,13 @@ This variable allows the user to disable \fIcollision\-protect\fR and
 .br
 Defaults to /lib/modules.
 .TP
+\fBCOLLISION_IGNORE_UNOWNED\fR = \fI[space delimited list of shell patterns]\fR
+This variable allows the user to disable \fIcollision\-protect\fR and
+\fIprotect\-owned\fR for specific shell patterns for files that are
+not owned by any packages.
+.br
+Defaults to *.pyc and *.pyo patterns.
+.TP
 \fBCONFIG_PROTECT\fR = \fI[space delimited list of files and/or directories]\fR
 All files and/or directories that are defined here will have "config file protection"
 enabled for them. See the \fBCONFIGURATION FILES\fR section
diff --git a/pym/portage/dbapi/vartree.py b/pym/portage/dbapi/vartree.py
index ec9f87c35..71b5d80e7 100644
--- a/pym/portage/dbapi/vartree.py
+++ b/pym/portage/dbapi/vartree.py
@@ -63,6 +63,7 @@ from _emerge.PollScheduler import PollScheduler
 from _emerge.MiscFunctionsProcess import MiscFunctionsProcess
 
 import errno
+import fnmatch
 import gc
 import grp
 import io
@@ -3080,6 +3081,9 @@ class dblink(object):
 				portage.util.shlex_split(
 				self.settings.get("COLLISION_IGNORE", ""))])
 
+			unowned_ignore_patterns = self.settings.get(
+				"COLLISION_IGNORE_UNOWNED", "").split()
+
 			# For collisions with preserved libraries, the current package
 			# will assume ownership and the libraries will be unregistered.
 			if self.vartree.dbapi._plib_registry is None:
@@ -3188,6 +3192,10 @@ class dblink(object):
 								if f.startswith(myignore + os.path.sep):
 									stopmerge = False
 									break
+					for pattern in unowned_ignore_patterns:
+						if fnmatch.fnmatch(f, pattern):
+							stopmerge = False
+							break
 					if stopmerge:
 						collisions.append(f)
 			return collisions, symlink_collisions, plib_collisions
diff --git a/pym/portage/package/ebuild/_config/special_env_vars.py b/pym/portage/package/ebuild/_config/special_env_vars.py
index 132f8ebd8..8eac38034 100644
--- a/pym/portage/package/ebuild/_config/special_env_vars.py
+++ b/pym/portage/package/ebuild/_config/special_env_vars.py
@@ -134,8 +134,9 @@ environ_filter += [
 # portage config variables and variables set directly by portage
 environ_filter += [
 	"ACCEPT_CHOSTS", "ACCEPT_KEYWORDS", "ACCEPT_PROPERTIES", "AUTOCLEAN",
-	"CLEAN_DELAY", "COLLISION_IGNORE", "CONFIG_PROTECT",
-	"CONFIG_PROTECT_MASK", "EGENCACHE_DEFAULT_OPTS", "EMERGE_DEFAULT_OPTS",
+	"CLEAN_DELAY", "COLLISION_IGNORE", "COLLISION_IGNORE_UNOWNED",
+	"CONFIG_PROTECT", "CONFIG_PROTECT_MASK",
+	"EGENCACHE_DEFAULT_OPTS", "EMERGE_DEFAULT_OPTS",
 	"EMERGE_LOG_DIR",
 	"EMERGE_WARNING_DELAY",
 	"FETCHCOMMAND", "FETCHCOMMAND_FTP",
-- 
2.26.2