示例#1
0
status_t
BSolverRepository::SetTo(const BRepositoryConfig& config)
{
	Unset();

	if (config.InitCheck() != B_OK)
		return B_BAD_VALUE;

	fName = config.Name();
	fPriority = config.Priority();

	BPackageRoster roster;
	BRepositoryCache cache;
	status_t error = roster.GetRepositoryCache(config.Name(), &cache);
	if (error != B_OK) {
		Unset();
		return error;
	}

	BRepositoryCache::Iterator it = cache.GetIterator();
	while (const BPackageInfo* packageInfo = it.Next()) {
		error = AddPackage(*packageInfo);
		if (error != B_OK) {
			Unset();
			return error;
		}
	}

	return B_OK;
}
示例#2
0
static void add_installed_packages(Repo *repo, Repodata *repoData,
  BPackageInstallationLocation location)
{
  BPackageRoster roster;
  BPackageInfoSet packageInfos;
  if (roster.GetActivePackages(location, packageInfos) == B_OK)
    {
      BRepositoryCache::Iterator it = packageInfos.GetIterator();
      while (const BPackageInfo *packageInfo = it.Next())
        add_package_info_to_repo(repo, repoData, *packageInfo);
    }
}
示例#3
0
status_t
BSolverRepository::AddPackages(BPackageInstallationLocation location)
{
	BPackageRoster roster;
	BPackageInfoSet packageInfos;
	status_t error = roster.GetActivePackages(location, packageInfos);
	if (error != B_OK)
		return error;

	BRepositoryCache::Iterator it = packageInfos.GetIterator();
	while (const BPackageInfo* packageInfo = it.Next()) {
		error = AddPackage(*packageInfo);
		if (error != B_OK)
			return error;
	}

	return B_OK;
}
示例#4
0
int repo_add_haiku_packages(Repo *repo, const char *repoName, int flags)
{
  BPackageRoster roster;
  BRepositoryCache cache;
  if (roster.GetRepositoryCache(repoName, &cache) != B_OK)
    return 0;

  Repodata *repoData = repo_add_repodata(repo, flags);

  BRepositoryCache::Iterator it = cache.GetIterator();
  while (const BPackageInfo *packageInfo = it.Next())
    add_package_info_to_repo(repo, repoData, *packageInfo);

  if (!(flags & REPO_NO_INTERNALIZE))
    repodata_internalize(repoData);

  return 0;
}
示例#5
0
status_t
BSolverRepository::SetTo(const BRepositoryCache& cache)
{
	Unset();

	const BRepositoryInfo& info = cache.Info();
	if (info.InitCheck() != B_OK)
		return B_BAD_VALUE;

	fName = info.Name();
	fPriority = info.Priority();

	BRepositoryCache::Iterator it = cache.GetIterator();
	while (const BPackageInfo* packageInfo = it.Next()) {
		status_t error = AddPackage(*packageInfo);
		if (error != B_OK) {
			Unset();
			return error;
		}
	}

	return B_OK;
}
int
main(int argc, const char* const* argv)
{
	if (argc != 3)
		print_usage_and_exit(true);

	if (strcmp(argv[1], "-h") == 0 || strcmp(argv[1], "--help") == 0)
		print_usage_and_exit(false);

	const char* const packageInfoPath = argv[1];
	const char* const repositoryCachePath = argv[2];

	// read the repository cache
	BRepositoryCache repositoryCache;
	status_t error = repositoryCache.SetTo(repositoryCachePath);
	if (error != B_OK) {
		DIE(error, "failed to read repository cache file \"%s\"",
			repositoryCachePath);
	}

	// create a map for all provides (name -> resolvable list)
	typedef std::map<BString, ProvidesList> ProvidesMap;

	ProvidesMap providesMap;

	for (BRepositoryCache::Iterator it = repositoryCache.GetIterator();
		const BPackageInfo* info = it.Next();) {
		const BObjectList<BPackageResolvable>& provides = info->ProvidesList();
		int32 count = provides.CountItems();
		for (int32 i = 0; i < count; i++) {
			BPackageResolvable* resolvable = provides.ItemAt(i);
			ProvidesList& providesList = providesMap[resolvable->Name()];
			providesList.push_back(resolvable);
		}
	}

	// load the package info
	BPackageInfo packageInfo;
	error = packageInfo.ReadFromConfigFile(packageInfoPath);
	if (error != B_OK)
		DIE(error, "failed to read package info file \"%s\"", packageInfoPath);

	// clone the package info's requires list
	typedef std::list<BPackageResolvableExpression> RequiresList;
	RequiresList requiresList;
	int32 requiresCount = packageInfo.RequiresList().CountItems();
	for (int32 i = 0; i < requiresCount; i++)
		requiresList.push_back(*packageInfo.RequiresList().ItemAt(i));

	// rebuild the requires list with updated versions
	packageInfo.ClearRequiresList();
	for (RequiresList::iterator it = requiresList.begin();
		it != requiresList.end(); ++it) {
		BPackageResolvableExpression expression = *it;
		ProvidesMap::iterator foundIt = providesMap.find(expression.Name());
		if (foundIt != providesMap.end())
			update_requires_expression(expression, foundIt->second);

		error = packageInfo.AddRequires(expression);
		if (error != B_OK)
			DIE(error, "failed to add requires item to package info");
	}

	// write updated package info
	BString configString;
	error = packageInfo.GetConfigString(configString);
	if (error != B_OK)
		DIE(error, "failed to get updated package info string");

	FILE* file = fopen(packageInfoPath, "w");
	if (file == NULL) {
		DIE(errno, "failed to open package info file \"%s\" for writing",
			packageInfoPath);
	}

	if (fwrite(configString.String(), configString.Length(), 1, file) != 1) {
		DIE(errno, "failed to write updated package info file \"%s\"",
			packageInfoPath);
	}

	fclose(file);

	return 0;
}