コード例 #1
0
ファイル: file.cpp プロジェクト: cvalka4/cupt
	string perform(const shared_ptr< const Config >& /* config */, const download::Uri& uri,
			const string& targetPath, const std::function< void (const vector< string >&) >& callback)
	{
		auto sourcePath = uri.getOpaque();
		auto protocol = uri.getProtocol();

		// preparing source
		string openError;
		File sourceFile(sourcePath, "r", openError);
		if (!openError.empty())
		{
			return format2("unable to open the file '%s' for reading: %s", sourcePath, openError);
		}

		if (protocol == "copy")
		{
			return copyFile(sourcePath, sourceFile, targetPath, callback); // full copying
		}
		else if (protocol == "file")
		{
			// symlinking
			unlink(targetPath.c_str()); // yep, no error handling;
			if (symlink(sourcePath.c_str(), targetPath.c_str()) == -1)
			{
				return format2e("unable to create symbolic link '%s' -> '%s'", targetPath, sourcePath);
			}
			return string();
		}
		else
		{
			fatal2i("a wrong scheme '%s' for the 'file' download method", protocol);
			return string(); // unreachable
		}
	}
コード例 #2
0
ファイル: binaryversion.cpp プロジェクト: jamessan/cupt
bool BinaryVersion::areHashesEqual(const Version* other) const
{
	auto o = dynamic_cast< const BinaryVersion* >(other);
	if (!o)
	{
		fatal2i("areHashesEqual: non-binary version parameter");
	}
	return file.hashSums.match(o->file.hashSums);
}
コード例 #3
0
ファイル: score.cpp プロジェクト: jamessan/cupt
ScoreManager::ScoreManager(const Config& config, const shared_ptr< const Cache >& cache)
	: __cache(cache)
{
	__quality_adjustment = config.getInteger("cupt::resolver::score::quality-adjustment");
	__preferred_version_default_pin = config.getString("apt::default-release").empty() ?
			500 : 990;

	for (size_t i = 0; i < ScoreChange::SubScore::Count; ++i)
	{
		const auto type = ScoreChange::SubScore::Type(i);
		auto& multiplier = __subscore_multipliers[i];

		if (type == ScoreChange::SubScore::Version || type == ScoreChange::SubScore::UnsatisfiedCustomRequest)
		{
			multiplier = 1u;
			continue;
		}

		const char* leafOption;
		switch (type)
		{
			case ScoreChange::SubScore::New:
				leafOption = "new"; break;
			case ScoreChange::SubScore::Removal:
				leafOption = "removal"; break;
			case ScoreChange::SubScore::RemovalOfEssential:
				leafOption = "removal-of-essential"; break;
			case ScoreChange::SubScore::RemovalOfAuto:
				leafOption = "removal-of-autoinstalled"; break;
			case ScoreChange::SubScore::Upgrade:
				leafOption = "upgrade"; break;
			case ScoreChange::SubScore::Downgrade:
				leafOption = "downgrade"; break;
			case ScoreChange::SubScore::PositionPenalty:
				leafOption = "position-penalty"; break;
			case ScoreChange::SubScore::UnsatisfiedRecommends:
				leafOption = "unsatisfied-recommends"; break;
			case ScoreChange::SubScore::UnsatisfiedSuggests:
				leafOption = "unsatisfied-suggests"; break;
			case ScoreChange::SubScore::FailedSync:
				leafOption = "failed-synchronization"; break;
			case ScoreChange::SubScore::UnsatisfiedTry:
				leafOption = "unsatisfied-try"; break;
			case ScoreChange::SubScore::UnsatisfiedWish:
				leafOption = "unsatisfied-wish"; break;
			default:
				fatal2i("missing score multiplier for the score '%zu'", i);
		}

		multiplier = config.getInteger(
				string("cupt::resolver::score::") + leafOption);
	}
}
コード例 #4
0
static vector< const VersionType* > __convert_version_type(list< const Version* >&& source)
{
	vector< const VersionType* > result;
	for (const auto& oldVersion: source)
	{
		auto version = dynamic_cast< const VersionType* >(oldVersion);
		if (!version)
		{
			fatal2i("version has a wrong type");
		}
		result.push_back(version);
	}

	return result;
}
コード例 #5
0
ファイル: impl.cpp プロジェクト: jamessan/cupt
	FORIT(it, __initial_packages)
	{
		dg::InitialPackageEntry& initialPackageEntry = it->second;
		if (!initialPackageEntry.version)
		{
			continue;
		}

		const string& packageName = it->first;
		auto package = __cache->getBinaryPackage(packageName);

		// if there is original version, then the preferred version should exist
		auto supposedVersion = static_cast< const BinaryVersion* >
				(__cache->getPreferredVersion(package));
		if (!supposedVersion)
		{
			fatal2i("supposed version doesn't exist");
		}

		__prepare_version_no_stick(supposedVersion, initialPackageEntry);
	}
コード例 #6
0
ファイル: solution.cpp プロジェクト: cvalka4/cupt
void SolutionStorage::setPackageEntry(Solution& solution,
		const dg::Element* elementPtr, PackageEntry&& packageEntry,
		const dg::Element* conflictingElementPtr, size_t priority)
{
	__dependency_graph.unfoldElement(elementPtr);
	__update_change_index(solution.id, elementPtr, packageEntry);

	auto it = solution.__added_entries->lower_bound(elementPtr);
	if (it == solution.__added_entries->end() || it->first != elementPtr)
	{
		// there is no modifiable element in this solution
		solution.__added_entries->insert(it,
				make_pair(elementPtr, std::make_shared< const PackageEntry >(std::move(packageEntry))));
	}
	else
	{
		if (conflictingElementPtr && it->second)
		{
			fatal2i("conflicting elements in __added_entries: solution '%u', in '%s', out '%s'",
					solution.id, elementPtr->toString(), conflictingElementPtr->toString());
		}
		it->second = std::make_shared< const PackageEntry >(std::move(packageEntry));
	}

	if (conflictingElementPtr)
	{
		auto forRemovalIt = solution.__added_entries->lower_bound(conflictingElementPtr);
		if (forRemovalIt != solution.__added_entries->end() && forRemovalIt->first == conflictingElementPtr)
		{
			forRemovalIt->second.reset();
		}
		else
		{
			solution.__added_entries->insert(forRemovalIt, { conflictingElementPtr, {} });
		}
	}

	__update_broken_successors(solution, conflictingElementPtr, elementPtr, priority);
}
コード例 #7
0
ファイル: base.cpp プロジェクト: jackyf/cupt
WorkerBase::WorkerBase()
{
	fatal2i("WorkerBase::WorkerBase shouldn't be ever called");
}
コード例 #8
0
ファイル: snapshots.cpp プロジェクト: jamessan/cupt
void SnapshotsImpl::setupResolverForSnapshotOnly(const string& snapshotName,
        const Cache& cache, system::Resolver& resolver)
{
    {
        auto snapshotNames = getSnapshotNames();
        if (std::find(snapshotNames.begin(), snapshotNames.end(), snapshotName)
                == snapshotNames.end())
        {
            fatal2(__("unable to find a snapshot named '%s'"), snapshotName);
        }
    }

    auto snapshotDirectory = getSnapshotDirectory(snapshotName);

    {   // checking snapshot format, current we support none and '1'
        auto formatPath = snapshotDirectory + "/format";
        if (fs::fileExists(formatPath))
        {
            RequiredFile file(formatPath, "r");
            string content;
            file.getFile(content);
            chomp(content);
            if (content != "1")
            {
                fatal2(__("unsupported snapshot format '%s'"), content);
            }
        }
    }

    std::set< string > toBeInstalledPackageNames;

    {
        auto snapshotPackagesPath = snapshotDirectory + '/' + system::Snapshots::installedPackageNamesFilename;
        RequiredFile file(snapshotPackagesPath, "r");

        string packageName;
        while (!file.getLine(packageName).eof())
        {
            auto package = cache.getBinaryPackage(packageName);
            if (!package)
            {
                fatal2i("the package '%s' doesn't exist", packageName);
            }

            toBeInstalledPackageNames.insert(packageName);

            for (auto version: *package)
            {
                for (const auto& source: version->sources)
                {
                    if (source.release->archive == "snapshot")
                    {
                        resolver.installVersion({ version });
                        goto next_file_line;
                    }
                }
            }

            // not found
            fatal2i("unable to find snapshot version for the package '%s'", packageName);

next_file_line:
            ;
        }
    }

    for (const auto& packageName: cache.getBinaryPackageNames())
    {
        if (!toBeInstalledPackageNames.count(packageName))
        {
            resolver.removeVersions(cache.getBinaryPackage(packageName)->getVersions());
        }
    }
}