--- ufed-0.40.1/Portage.pm 2009-10-26 20:56:53.000000000 +0100 +++ ufed-0.40.1/Portage.pm 2012-09-20 19:15:15.292794714 +0200 @@ -4,10 +4,15 @@ # Distributed under the terms of the GNU General Public License v2 # $Header: /var/cvsroot/gentoo-src/ufed/Portage.pm,v 1.3 2005/11/13 00:28:17 truedfx Exp $ +use strict; +use warnings; +use File::Spec; ## provided by virtual/perl-File-Spec + my %environment; $environment{$_}={} for qw(USE); # INCREMENTALS, except we only need USE our %packages; +our @portagedirs; our @profiles; our %use_masked_flags; our %use_defaults_flags; @@ -16,6 +21,7 @@ our %make_conf_flags; our %archs; our %all_flags; +our $make_conf_path; sub have_package($); sub merge(\%%); @@ -42,6 +48,7 @@ read_archs; my $lastorder; + for(reverse split /:/, $environment{USE_ORDER} || "env:pkg:conf:auto:defaults") { if($_ eq 'defaults') { merge %default_flags, %make_defaults_flags; @@ -136,9 +143,34 @@ } sub read_make_conf() { - my %env = read_sh "/etc/make.conf"; - merge %make_conf_flags, %{$env{USE}} if exists $env{USE}; - @portagedirs = $environment{PORTDIR}; + my $mcFile = "/etc/make.conf"; + my $mcPath = ( -l $mcFile ) ? File::Spec->rel2abs( readlink($mcFile) ) : $mcFile; + my %env = (); + + # 1. There is no known valid path, yet + $make_conf_path = ""; + + # 2. Read the old path if it is not a symlink to the new path + if ( ( -e $mcPath ) && ("/etc/portage/make.conf" ne $mcPath) ) { + %env = read_sh $mcPath; + merge %make_conf_flags, %{$env{USE}} if exists $env{USE}; + %env = (); + ## Store this path as being valid for now + $make_conf_path = $mcPath; + } + + # 3. Now switch to the new location - it must not be a symlink to the old either + $mcFile = "/etc/portage/make.conf"; + $mcPath = ( -l $mcFile ) ? File::Spec->rel2abs( readlink($mcFile) ) : $mcFile; + if ( (-e $mcPath ) && ("/etc/make.conf" ne $mcPath) ) { + %env = read_sh $mcPath; + merge %make_conf_flags, %{$env{USE}} if exists $env{USE}; + + # Overwrite the old path, as the new location is the overriding one. + $make_conf_path = $mcPath; + } + + @portagedirs = $environment{PORTDIR} || ( "/usr/portage" ); ## PORTDIR is not necassarily set by make.conf push @portagedirs, split ' ', $environment{PORTDIR_OVERLAY} if defined $environment{PORTDIR_OVERLAY}; }