#parse /etc/env.d and generate /etc/profile.env
-def env_update(makelinks=1):
- global root, mtimedb
- if not os.path.exists(root+"etc/env.d"):
- prevmask=os.umask(0)
- os.makedirs(root+"etc/env.d",0755)
- os.umask(prevmask)
- fns=listdir(root+"etc/env.d",EmptyOnError=1)
+def env_update(makelinks=1, target_root=None, prev_mtimes=None):
+ if target_root is None:
+ global root
+ target_root = root
+ if prev_mtimes is None:
+ global mtimedb
+ prev_mtimes = mtimedb["ldpath"]
+ envd_dir = os.path.join(target_root, "etc", "env.d")
+ portage_util.ensure_dirs(envd_dir, mode=0755)
+ fns = listdir(envd_dir, EmptyOnError=1)
fns.sort()
pos=0
while (pos<len(fns)):
# don't process backup files
if x[-1]=='~' or x[-4:]==".bak":
continue
- myconfig=getconfig(root+"etc/env.d/"+x)
+ file_path = os.path.join(envd_dir, x)
+ myconfig = getconfig(file_path)
if myconfig is None:
- writemsg("!!! Parsing error in "+str(root)+"etc/env.d/"+str(x)+"\n")
+ writemsg("!!! Parsing error in '%s'\n" % file_path)
#parse error
continue
# process PATH, CLASSPATH, LDPATH
for myenv in myconfig.keys():
env[myenv]=myconfig[myenv]
- if os.path.exists(root+"etc/ld.so.conf"):
- myld=open(root+"etc/ld.so.conf")
+ ldsoconf_path = os.path.join(target_root, "etc", "ld.so.conf")
+ try:
+ myld = open(ldsoconf_path)
myldlines=myld.readlines()
myld.close()
oldld=[]
if x[0]=="#":
continue
oldld.append(x[:-1])
- # os.rename(root+"etc/ld.so.conf",root+"etc/ld.so.conf.bak")
- # Where is the new ld.so.conf generated? (achim)
- else:
- oldld=None
+ except (IOError, OSError), e:
+ if e.errno != errno.ENOENT:
+ raise
+ oldld = None
ld_cache_update=False
newld=specials["LDPATH"]
if (oldld!=newld):
#ld.so.conf needs updating and ldconfig needs to be run
- myfd = atomic_ofstream(os.path.join(root, "etc", "ld.so.conf"))
+ myfd = atomic_ofstream(ldsoconf_path)
myfd.write("# ld.so.conf autogenerated by env-update; make all changes to\n")
myfd.write("# contents of /etc/env.d directory\n")
for x in specials["LDPATH"]:
# Update prelink.conf if we are prelink-enabled
if prelink_capable:
- newprelink = atomic_ofstream(os.path.join(root, "etc", "prelink.conf"))
+ newprelink = atomic_ofstream(
+ os.path.join(target_root, "etc", "prelink.conf"))
newprelink.write("# prelink.conf autogenerated by env-update; make all changes to\n")
newprelink.write("# contents of /etc/env.d directory\n")
newprelink.write("-b "+x+"\n")
newprelink.close()
- if not mtimedb.has_key("ldpath"):
- mtimedb["ldpath"]={}
-
for lib_dir in portage_util.unique_array(specials["LDPATH"]+['usr/lib','usr/lib64','usr/lib32','lib','lib64','lib32']):
- x = os.path.join(root, lib_dir.lstrip(os.sep))
+ x = os.path.join(target_root, lib_dir.lstrip(os.sep))
try:
newldpathtime = os.stat(x)[stat.ST_MTIME]
except OSError, oe:
if oe.errno == errno.ENOENT:
try:
- del mtimedb["ldpath"][x]
+ del prev_mtimes[x]
except KeyError:
pass
# ignore this path because it doesn't exist
continue
raise
mtime_changed = False
- if mtimedb["ldpath"].has_key(x):
- if mtimedb["ldpath"][x]==newldpathtime:
+ if x in prev_mtimes:
+ if prev_mtimes[x] == newldpathtime:
pass
else:
- mtimedb["ldpath"][x]=newldpathtime
+ prev_mtimes[x] = newldpathtime
mtime_changed = True
else:
- mtimedb["ldpath"][x]=newldpathtime
+ prev_mtimes[x] = newldpathtime
mtime_changed = True
if mtime_changed:
# an older package installed ON TOP of a newer version will cause ldconfig
# to overwrite the symlinks we just made. -X means no links. After 'clean'
# we can safely create links.
- writemsg(">>> Regenerating "+str(root)+"etc/ld.so.cache...\n")
+ writemsg(">>> Regenerating %setc/ld.so.cache...\n" % target_root)
if makelinks:
- commands.getstatusoutput("cd / ; /sbin/ldconfig -r "+root)
+ commands.getstatusoutput("cd / ; /sbin/ldconfig -r '%s'" % target_root)
else:
- commands.getstatusoutput("cd / ; /sbin/ldconfig -X -r "+root)
+ commands.getstatusoutput("cd / ; /sbin/ldconfig -X -r '%s'" % target_root)
elif ostype in ("FreeBSD","DragonFly"):
- writemsg(">>> Regenerating "+str(root)+"var/run/ld-elf.so.hints...\n")
- commands.getstatusoutput("cd / ; /sbin/ldconfig -elf -i -f "+str(root)+"var/run/ld-elf.so.hints "+str(root)+"etc/ld.so.conf")
+ writemsg(">>> Regenerating %svar/run/ld-elf.so.hints...\n" % target_root)
+ commands.getstatusoutput(
+ "cd / ; /sbin/ldconfig -elf -i -f '%svar/run/ld-elf.so.hints' '%setc/ld.so.conf'" % \
+ (target_root, target_root))
del specials["LDPATH"]
cenvnotice += "# GO INTO /etc/csh.cshrc NOT /etc/csh.env\n\n"
#create /etc/profile.env for bash support
- outfile = atomic_ofstream(os.path.join(root, "etc", "profile.env"))
+ outfile = atomic_ofstream(os.path.join(target_root, "etc", "profile.env"))
outfile.write(penvnotice)
for path in specials.keys():
outfile.close()
#create /etc/csh.env for (t)csh support
- outfile = atomic_ofstream(os.path.join(root, "etc", "csh.env"))
+ outfile = atomic_ofstream(os.path.join(target_root, "etc", "csh.env"))
outfile.write(cenvnotice)
for path in specials.keys():
if "cur" in d:
del d["cur"]
- d.setdefault("updates", {})
+ for k in ("ldpath", "updates"):
+ d.setdefault(k, {})
mtimedbkeys = set(("info", "ldpath", "resume", "resume_backup",
"starttime", "updates", "version"))
f.close()
del f
except (IOError, OSError):
- mtimedb = {"updates":{}, "version":"", "starttime":0}
+ mtimedb = {"updates":{}, "ldpath":{}, "version":"", "starttime":0}
# ============================================================================
# COMPATIBILITY