예제 #1
0
status_t
Volume::_AddPackageDomain(PackageDomain* domain, bool notify)
{
	// create a directory listener
	DomainDirectoryListener* listener = new(std::nothrow)
		DomainDirectoryListener(this, domain);
	if (listener == NULL)
		RETURN_ERROR(B_NO_MEMORY);

	// prepare the package domain
	status_t error = domain->Prepare(listener);
	if (error != B_OK) {
		ERROR("Failed to prepare package domain \"%s\": %s\n",
			domain->Path(), strerror(errno));
		RETURN_ERROR(errno);
	}

	// iterate through the dir and create packages
	DIR* dir = opendir(domain->Path());
	if (dir == NULL) {
		ERROR("Failed to open package domain directory \"%s\": %s\n",
			domain->Path(), strerror(errno));
		RETURN_ERROR(errno);
	}
	CObjectDeleter<DIR, int> dirCloser(dir, closedir);

	while (dirent* entry = readdir(dir)) {
		// skip "." and ".."
		if (strcmp(entry->d_name, ".") == 0 || strcmp(entry->d_name, "..") == 0)
			continue;

		_DomainEntryCreated(domain, domain->DeviceID(), domain->NodeID(),
			-1, entry->d_name, false, notify);
// TODO: -1 node ID?
	}

	// add the packages to the node tree
	VolumeWriteLocker systemVolumeLocker(_SystemVolumeIfNotSelf());
	VolumeWriteLocker volumeLocker(this);
	for (PackageFileNameHashTable::Iterator it
			= domain->Packages().GetIterator(); Package* package = it.Next();) {
		error = _AddPackageContent(package, notify);
		if (error != B_OK) {
			for (it.Rewind(); Package* activePackage = it.Next();) {
				if (activePackage == package)
					break;
				_RemovePackageContent(activePackage, NULL, notify);
			}
			RETURN_ERROR(error);
		}
	}

	fPackageDomains.Add(domain);
	domain->AcquireReference();

	return B_OK;
}
예제 #2
0
void
Volume::_RemovePackageDomain(PackageDomain* domain)
{
	// remove the domain's packages from the node tree
	VolumeWriteLocker systemVolumeLocker(_SystemVolumeIfNotSelf());
	VolumeWriteLocker volumeLocker(this);
	for (PackageFileNameHashTable::Iterator it
			= domain->Packages().GetIterator(); Package* package = it.Next();) {
		_RemovePackageContent(package, NULL, false);
	}

	// remove the domain
	fPackageDomains.Remove(domain);
	domain->ReleaseReference();
}
예제 #3
0
void
PackageManager::InitInstalledRepository(InstalledRepository& repository)
{
	const char* name = repository.InitialName();
	BRepositoryBuilder repositoryBuilder(repository, name);

	if (Volume* volume = fRoot->GetVolume(repository.Location())) {
		for (PackageFileNameHashTable::Iterator it
				= volume->PackagesByFileNameIterator(); it.HasNext();) {
			Package* package = it.Next();
			if (package->IsActive()) {
				BSolverPackage* solverPackage;
				repositoryBuilder.AddPackage(package->Info(), NULL,
					&solverPackage);
				fSolverPackages[package] = solverPackage;
			}
		}
	}
}