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; }
status_t RemoveRepositoryJob::Execute() { BPackageRoster roster; BRepositoryConfig repoConfig; status_t result = roster.GetRepositoryConfig(fRepositoryName, &repoConfig); if (result != B_OK) { if (result == B_ENTRY_NOT_FOUND) { BString error = BString("repository '") << fRepositoryName << "' not found!"; SetErrorString(error); } return result; } BString question = BString("Really remove the repository '") << fRepositoryName << "'?"; bool yes = fContext.DecisionProvider().YesNoDecisionNeeded("", question, "yes", "no", "no"); if (!yes) return B_CANCELED; BEntry repoConfigEntry = repoConfig.Entry(); if ((result = repoConfigEntry.Remove()) != B_OK) return result; BRepositoryCache repoCache; if (roster.GetRepositoryCache(fRepositoryName, &repoCache) == B_OK) { BEntry repoCacheEntry = repoCache.Entry(); if ((result = repoCacheEntry.Remove()) != B_OK) return result; } return B_OK; }
status_t BRefreshRepositoryRequest::CreateInitialJobs() { status_t result = InitCheck(); if (result != B_OK) return B_NO_INIT; if ((result = fRepoConfig.InitCheck()) != B_OK) return result; // fetch the current checksum and compare with our cache's checksum, // if they differ, fetch the updated cache result = fContext.GetNewTempfile("repochecksum-", &fFetchedChecksumFile); if (result != B_OK) return result; BString repoChecksumURL = BString(fRepoConfig.BaseURL()) << "/" << "repo.sha256"; FetchFileJob* fetchChecksumJob = new (std::nothrow) FetchFileJob( fContext, BString("Fetching repository checksum from ") << fRepoConfig.BaseURL(), repoChecksumURL, fFetchedChecksumFile); if (fetchChecksumJob == NULL) return B_NO_MEMORY; if ((result = QueueJob(fetchChecksumJob)) != B_OK) { delete fetchChecksumJob; return result; } BRepositoryCache repoCache; BPackageRoster roster; roster.GetRepositoryCache(fRepoConfig.Name(), &repoCache); ValidateChecksumJob* validateChecksumJob = new (std::nothrow) ValidateChecksumJob(fContext, BString("Validating checksum for ") << fRepoConfig.Name(), new (std::nothrow) ChecksumFileChecksumAccessor( fFetchedChecksumFile), new (std::nothrow) GeneralFileChecksumAccessor(repoCache.Entry(), true), false); if (validateChecksumJob == NULL) return B_NO_MEMORY; validateChecksumJob->AddDependency(fetchChecksumJob); if ((result = QueueJob(validateChecksumJob)) != B_OK) { delete validateChecksumJob; return result; } fValidateChecksumJob = validateChecksumJob; return B_OK; }
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; }
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; }
int ListReposCommand::Execute(int argc, const char* const* argv) { bool verbose = false; while (true) { static struct option sLongOptions[] = { { "help", no_argument, 0, 'h' }, { "verbose", no_argument, 0, 'v' }, { 0, 0, 0, 0 } }; opterr = 0; // don't print errors int c = getopt_long(argc, (char**)argv, "hv", sLongOptions, NULL); if (c == -1) break; switch (c) { case 'h': PrintUsageAndExit(false); break; case 'v': verbose = true; break; default: PrintUsageAndExit(true); break; } } // No remaining arguments. if (argc != optind) PrintUsageAndExit(true); BStringList repositoryNames(20); BPackageRoster roster; status_t result = roster.GetRepositoryNames(repositoryNames); if (result != B_OK) DIE(result, "can't collect repository names"); for (int i = 0; i < repositoryNames.CountStrings(); ++i) { const BString& repoName = repositoryNames.StringAt(i); BRepositoryConfig repoConfig; result = roster.GetRepositoryConfig(repoName, &repoConfig); if (result != B_OK) { BPath path; repoConfig.Entry().GetPath(&path); WARN(result, "skipping repository-config '%s'", path.Path()); continue; } if (verbose && i > 0) printf("\n"); printf(" %s %s\n", repoConfig.IsUserSpecific() ? "[User]" : " ", repoConfig.Name().String()); printf("\t\tbase-url: %s\n", repoConfig.BaseURL().String()); printf("\t\tpriority: %u\n", repoConfig.Priority()); if (verbose) { BRepositoryCache repoCache; result = roster.GetRepositoryCache(repoName, &repoCache); if (result == B_OK) { printf("\t\tvendor: %s\n", repoCache.Info().Vendor().String()); printf("\t\tsummary: %s\n", repoCache.Info().Summary().String()); printf("\t\tarch: %s\n", BPackageInfo::kArchitectureNames[ repoCache.Info().Architecture()]); printf("\t\tpkg-count: %" B_PRIu32 "\n", repoCache.CountPackages()); printf("\t\torig-url: %s\n", repoCache.Info().OriginalBaseURL().String()); printf("\t\torig-prio: %u\n", repoCache.Info().Priority()); } else printf("\t\t<no repository cache found>\n"); } } return 0; }