'Add an install record for this spec to the database.
Assumes spec is installed in ``layout.path_for_spec(spec)``.
Also ensures dependencies are present and updated in the DB as
either intsalled or missing.'

def _add(self, spec, directory_layout=None, explicit=False):

    if (not spec.concrete):
        raise NonConcreteSpecAddError('Specs    added    to    DB    must    be    concrete.')
    for dep in spec.dependencies(_tracked_deps):
        dkey = dep.dag_hash()
        if (dkey not in self._data):
            self._add(dep, directory_layout, explicit=False)
    key = spec.dag_hash()
    if (key not in self._data):
        installed = bool(spec.external)
        path = None
        if ((not spec.external) and directory_layout):
            path = directory_layout.path_for_spec(spec)
            try:
                directory_layout.check_installed(spec)
                installed = True
            except DirectoryLayoutError as e:
                tty.warn('Dependency    missing    due    to    corrupt    install    directory:', path, str(e))
        new_spec = spec.copy(deps=False)
        self._data[key] = InstallRecord(new_spec, path, installed, ref_count=0, explicit=explicit)
        for (name, dep) in iteritems(spec.dependencies_dict(_tracked_deps)):
            dkey = dep.spec.dag_hash()
            new_spec._add_dependency(self._data[dkey].spec, dep.deptypes)
            self._data[dkey].ref_count += 1
        new_spec._mark_concrete()
        new_spec._hash = key
    else:
        self._data[key].installed = True
    self._data[key].explicit = explicit
