Id
ModulePackage::createPlatformSolvable(DnfSack * sack, DnfSack * moduleSack,
        const std::vector<std::string> & osReleasePaths, const std::string install_root,
        const char *  platformModule)
{
    std::pair<std::string, std::string> parsedPlatform;
    std::string name;
    std::string stream;
    if (platformModule) {
        parsedPlatform = parsePlatform(platformModule);
        if (!parsedPlatform.first.empty() && !parsedPlatform.second.empty()) {
            name = parsedPlatform.first;
            stream = parsedPlatform.second;
        } else {
            throw std::runtime_error(
                tfm::format(_("Invalid format of Platform module: %s"), platformModule));
        }
    } else if (sack) {
        Query baseQuery(sack);
        baseQuery.addFilter(HY_PKG_PROVIDES, HY_EQ, "system-release");
        baseQuery.addFilter(HY_PKG_LATEST, HY_EQ, 1);
        baseQuery.apply();
        Query availableQuery(baseQuery);
        availableQuery.addFilter(HY_PKG_REPONAME, HY_NEQ, HY_SYSTEM_REPO_NAME);
        auto platform = availableQuery.getStringsFromProvide("base-module");
        auto platformSize = platform.size();
        if (platformSize == 1) {
            parsedPlatform = parsePlatform(*platform.begin());
        } else if (platformSize > 1) {
            auto logger(Log::getLogger());
            logger->debug(_("Multiple module platforms provided by available packages\n"));
        }
        if (!parsedPlatform.first.empty() && !parsedPlatform.second.empty()) {
            name = parsedPlatform.first;
            stream = parsedPlatform.second;
        } else {
            baseQuery.addFilter(HY_PKG_REPONAME, HY_EQ, HY_SYSTEM_REPO_NAME);
            platform = baseQuery.getStringsFromProvide("base-module");
            platformSize = platform.size();
            if (platformSize == 1) {
                parsedPlatform = parsePlatform(*platform.begin());
            } else if (platformSize > 1) {
                auto logger(Log::getLogger());
                logger->debug(_("Multiple module platforms provided by installed packages\n"));
            }
            if (!parsedPlatform.first.empty() && !parsedPlatform.second.empty()) {
                name = parsedPlatform.first;
                stream = parsedPlatform.second;
            }
        }
    }

    if (name.empty() || stream.empty()) {
        for (auto & osReleasePath: osReleasePaths) {
            std::string path;
            if (install_root == "/") {
                path = osReleasePath;
            } else {
                if (install_root.back() == '/') {
                    path = install_root.substr(0, install_root.size() -1);
                } else {
                    path = install_root;
                }
                path += osReleasePath;
            }
            std::pair<std::string, std::string> platform;
            try {
                platform = getPlatformStream(path);
            } catch (const std::exception & except) {
                auto logger(Log::getLogger());
                logger->debug(tfm::format(_("Detection of Platform Module in %s failed: %s"),
                                          osReleasePath, std::string(except.what())));
            }
            if (!platform.first.empty() && !platform.second.empty()) {
                name = platform.first;
                stream = platform.second;
                break;
            } else {
                auto logger(Log::getLogger());
                logger->debug(tfm::format(_("Missing PLATFORM_ID in %s"), osReleasePath));
            }
        }
    }
    if (name.empty() || stream.empty()) {
        throw std::runtime_error(_("No valid Platform ID detected"));
    }
    std::string version = "0";
    std::string context = "00000000";

    Pool * pool = dnf_sack_get_pool(moduleSack);
    HyRepo hrepo = hy_repo_create(HY_SYSTEM_REPO_NAME);
    auto repoImpl = libdnf::repoGetImpl(hrepo);
    LibsolvRepo *repo = repo_create(pool, HY_SYSTEM_REPO_NAME);
    repo->appdata = hrepo;
    repoImpl->libsolvRepo = repo;
    repoImpl->needs_internalizing = 1;
    Id id = repo_add_solvable(repo);
    Solvable *solvable = pool_id2solvable(pool, id);
    setSovable(pool, solvable, name, stream, version, context, "noarch");
    repoImpl->needs_internalizing = 1;
    dnf_sack_set_provides_not_ready(moduleSack);
    dnf_sack_set_considered_to_update(moduleSack);
    pool_set_installed(pool, repo);
    return id;
}
Exemplo n.º 2
0
EXPORT_C CUrl* CUrl::ResolveL(CUrl& aBaseUrl, CUrl& aRelativeUrl)
//
//	Based on the relative parsing algorithm in RFC2396
	{
	//	Return copy of aRelativeUrl if aBaseUrl is empty
	if (aBaseUrl.UrlDes().Compare(KNullDesC)==0)
		return aRelativeUrl.AllocL();

	TPtrC relativeUrl(aRelativeUrl.UrlDes());

	TPtrC relPath(aRelativeUrl.Component(EUrlPath));
	TPtrC relAuth(aRelativeUrl.Component(EUrlAuthority));
	TPtrC relScheme(aRelativeUrl.Component(EUrlScheme));
	TPtrC relQuery(aRelativeUrl.Component(EUrlQuery));
	TPtrC relFragment(aRelativeUrl.Component(EUrlFragment));

	if (relScheme.Length() > 0)
		{
		// LOOPHOLE in RFC 1630 if schemes match then remove the scheme from the relative url
		if (aBaseUrl.UrlDes().FindF(relScheme) == 0)
			relativeUrl.Set(relativeUrl.Mid(relScheme.Length() + 1)); // remove the ':' as well
		else // the relative url is absolute
			return NewL(relativeUrl);
		}

	TBool useBaseAuth = ETrue;
	TBool useRelQuery = ETrue;
	TPtrC basePath(aBaseUrl.Component(EUrlPath));
	HBufC* resolvedPath = NULL;
	if (relPath.Compare(KNullDesC)==0 && relAuth.Compare(KNullDesC)==0 
		&& relScheme.Compare(KNullDesC)==0 && relQuery.Compare(KNullDesC)==0) // relative URL could just be a fragment
		{
		// Use current document url (assume that it is aBaseUrl), including query, then add relative URL fragment
		useRelQuery = EFalse;
		resolvedPath = basePath.AllocLC();
		}
	else if (relativeUrl.Find(KUrlLoc) == 0) // relative url is a network path
		{
		// Set resolved path to be the relative path
		useBaseAuth = EFalse;
		resolvedPath = relPath.AllocLC();
		}	
	else if (relPath.Locate('/') == 0) // relative url is an absolute path
		{
		resolvedPath = relPath.AllocLC();
		}
	else 
		{
		//	Do path resolution, merge the base path and relative path
		if (relPath.Length() != 0)
			// if the relative path is a query or fragment then shouldn't strip the document from the basePath
			{
			TInt endBasePath = basePath.LocateReverse('/');
			if (endBasePath != KErrNotFound)
				basePath.Set(basePath.Left(endBasePath + 1)); // keep the '/' 
			else
				basePath.Set(_L("/"));	//	Create path of just '/'
			}
		//	Resolve relative path against base path
		resolvedPath = HBufC::NewLC(relPath.Length() + basePath.Length());
		TRelativePaths relativePaths(basePath, relPath, resolvedPath->Des());
		relativePaths.ResolveRelativePaths();
		}

	// put the url together
	TPtrC baseScheme(aBaseUrl.Component(EUrlScheme));
	TPtrC baseAuth(aBaseUrl.Component(EUrlAuthority));
	TPtrC baseQuery(aBaseUrl.Component(EUrlQuery));

	HBufC* resolvedUrl = HBufC::NewLC(aBaseUrl.UrlDes().Length()  
										 + relativeUrl.Length()
										 + KUrlColon().Length() 
										 + KUrlLoc().Length()
										 + KUrlQMark().Length()
										 + KUrlHash().Length()
										 + 1); // this will be long enough - extra 1 just in case basePath was empty
	TPtr resolvedBuf = resolvedUrl->Des();

	if (baseScheme.Length() > 0)
		{
		resolvedBuf.Append(baseScheme);
		resolvedBuf.Append(KUrlColon);
		}

	resolvedBuf.Append(KUrlLoc);	

	if (useBaseAuth && baseAuth.Length() >0)
		{
		resolvedBuf.Append(baseAuth);
		}
	else if (relAuth.Length() > 0)
		{
		resolvedBuf.Append(relAuth);
		}

	resolvedBuf.Append(*resolvedPath);

	if (useRelQuery && relQuery.Length() >0)
		{
		resolvedBuf.Append(KUrlQMark);
		resolvedBuf.Append(relQuery);
		}
	else if (!useRelQuery && baseQuery.Length() >0)
		{
		resolvedBuf.Append(KUrlQMark);
		resolvedBuf.Append(baseQuery);
		}

	if (relFragment.Length() >0)
		{
		resolvedBuf.Append(KUrlHash);
		resolvedBuf.Append(relFragment);
		}

	CUrl * url = CUrl::NewL(*resolvedUrl);
	CleanupStack::PopAndDestroy(2); // resolvedUrl, resolvedPath

	return url;
	}