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;
}