return spawn(EBUILD_SH_BINARY + " depend", mysettings)
+ # Validate dependency metadata here to ensure that ebuilds with invalid
+ # data are never installed (even via the ebuild command).
+ invalid_dep_exempt_phases = \
+ set(["clean", "cleanrm", "help", "prerm", "postrm"])
+ mycpv = mysettings["CATEGORY"] + "/" + mysettings["PF"]
+ dep_keys = ["DEPEND", "RDEPEND", "PDEPEND"]
+ metadata = dict(izip(dep_keys, mydbapi.aux_get(mycpv, dep_keys)))
+ class FakeTree(object):
+ def __init__(self, mydb):
+ self.dbapi = mydb
+ dep_check_trees = {myroot:{}}
+ dep_check_trees[myroot]["porttree"] = \
+ FakeTree(fakedbapi(settings=mysettings))
+ for dep_type in dep_keys:
+ mycheck = dep_check(metadata[dep_type], None, mysettings,
+ myuse="all", myroot=myroot, trees=dep_check_trees)
+ if not mycheck[0]:
+ writemsg("%s: %s\n%s\n" % (
+ dep_type, metadata[dep_type], mycheck[1]), noiselevel=-1)
+ if mydo not in invalid_dep_exempt_phases:
+ return 1
+ del dep_type, mycheck
+ del mycpv, dep_keys, metadata, FakeTree, dep_check_trees
+
if "PORTAGE_TMPDIR" not in mysettings or \
not os.path.isdir(mysettings["PORTAGE_TMPDIR"]):
writemsg("The directory specified in your " + \
# $Id: portage_locks.py 4449 2006-09-14 07:52:39Z zmedico $
-import errno
-import os
-import stat
-import time
-import types
-import portage_exception
-import portage_util
-import portage_data
+import errno, os, stat, time, types
+from portage_exception import InvalidData, DirectoryNotFound, FileNotFound
+from portage_data import portage_gid
+from portage_util import writemsg
from portage_localization import _
import portage_const
import fcntl
if not mypath:
- raise portage_exception.InvalidData, "Empty path given"
+ raise InvalidData, "Empty path given"
if type(mypath) == types.StringType and mypath[-1] == '/':
mypath = mypath[:-1]
if type(mypath) == types.StringType:
if not os.path.exists(os.path.dirname(mypath)):
- raise portage_exception.DirectoryNotFound, os.path.dirname(mypath)
+ raise DirectoryNotFound, os.path.dirname(mypath)
if not os.path.exists(lockfilename):
old_mask=os.umask(000)
myfd = os.open(lockfilename, os.O_CREAT|os.O_RDWR,0660)
try:
- if os.stat(lockfilename).st_gid != portage_data.portage_gid:
- os.chown(lockfilename,os.getuid(),portage_data.portage_gid)
+ if os.stat(lockfilename).st_gid != portage_gid:
+ os.chown(lockfilename,os.getuid(),portage_gid)
except OSError, e:
if e[0] == 2: # No such file or directory
return lockfile(mypath,wantnewlockfile,unlinkfile)
else:
- portage_util.writemsg("Cannot chown a lockfile. This could cause inconvenience later.\n");
+ writemsg("Cannot chown a lockfile. This could cause inconvenience later.\n");
os.umask(old_mask)
else:
myfd = os.open(lockfilename, os.O_CREAT|os.O_RDWR,0660)
myfd != HARDLINK_FD and os.fstat(myfd).st_nlink == 0:
# The file was deleted on us... Keep trying to make one...
os.close(myfd)
- portage_util.writemsg("lockfile recurse\n",1)
+ writemsg("lockfile recurse\n",1)
lockfilename,myfd,unlinkfile,locking_method = lockfile(mypath,wantnewlockfile,unlinkfile)
- portage_util.writemsg(str((lockfilename,myfd,unlinkfile))+"\n",1)
+ writemsg(str((lockfilename,myfd,unlinkfile))+"\n",1)
return (lockfilename,myfd,unlinkfile,locking_method)
def unlockfile(mytuple):
elif len(mytuple) == 4:
lockfilename,myfd,unlinkfile,locking_method = mytuple
else:
- raise
+ raise InvalidData
if(myfd == HARDLINK_FD):
unhardlink_lockfile(lockfilename)
# myfd may be None here due to myfd = mypath in lockfile()
if type(lockfilename) == types.StringType and not os.path.exists(lockfilename):
- portage_util.writemsg("lockfile does not exist '%s'\n" % lockfilename,1)
+ writemsg("lockfile does not exist '%s'\n" % lockfilename,1)
if myfd is not None:
os.close(myfd)
return False
locking_method(myfd,fcntl.LOCK_EX|fcntl.LOCK_NB)
# We won the lock, so there isn't competition for it.
# We can safely delete the file.
- portage_util.writemsg("Got the lockfile...\n",1)
+ writemsg("Got the lockfile...\n",1)
if os.fstat(myfd).st_nlink == 1:
os.unlink(lockfilename)
- portage_util.writemsg("Unlinked lockfile...\n",1)
+ writemsg("Unlinked lockfile...\n",1)
locking_method(myfd,fcntl.LOCK_UN)
else:
- portage_util.writemsg("lockfile does not exist '%s'\n" % lockfilename,1)
+ writemsg("lockfile does not exist '%s'\n" % lockfilename,1)
os.close(myfd)
return False
except Exception, e:
- portage_util.writemsg("Failed to get lock... someone took it.\n",1)
- portage_util.writemsg(str(e)+"\n",1)
+ writemsg("Failed to get lock... someone took it.\n",1)
+ writemsg(str(e)+"\n",1)
# why test lockfilename? because we may have been handed an
# fd originally, and the caller might not like having their
os.close(myfd)
if not os.path.exists(myhardlock):
- raise portage_exception.FileNotFound, _("Created lockfile is missing: %(filename)s") % {"filename":myhardlock}
+ raise FileNotFound, _("Created lockfile is missing: %(filename)s") % {"filename":myhardlock}
try:
res = os.link(myhardlock, lockfilename)
return True
if reported_waiting:
- portage_util.writemsg(".")
+ writemsg(".")
else:
reported_waiting = True
print