Пример #1
0
uint32_t
TDNFRunTransaction(
    PTDNFRPMTS pTS,
    PTDNF pTdnf
    )
{
    uint32_t dwError = 0;

    dwError = rpmtsOrder(pTS->pTS);
    BAIL_ON_TDNF_ERROR(dwError);

    dwError = doCheck(pTS);
    BAIL_ON_TDNF_ERROR(dwError);

    rpmtsClean(pTS->pTS);

    fprintf(stdout, "Testing transaction\n");

    rpmtsSetFlags(pTS->pTS, RPMTRANS_FLAG_TEST);
    dwError = rpmtsRun(pTS->pTS, NULL, pTS->nProbFilterFlags);
    BAIL_ON_TDNF_ERROR(dwError);

    fprintf(stdout, "Running transaction\n");
    rpmtsSetFlags(pTS->pTS, RPMTRANS_FLAG_NONE);
    dwError = rpmtsRun(pTS->pTS, NULL, pTS->nProbFilterFlags);
    BAIL_ON_TDNF_ERROR(dwError);

cleanup:
    return dwError;

error:
    doCheck(pTS);
    goto cleanup;
}
Пример #2
0
uint32_t
TDNFGPGCheck(
    rpmKeyring pKeyring,
    const char* pszUrlKeyFile,
    const char* pszPkgFile
    )
{
    uint32_t dwError = 0;
    char* pszKeyData = NULL;

    if(!pKeyring || IsNullOrEmptyString(pszUrlKeyFile) || !pszPkgFile)
    {
        dwError = ERROR_TDNF_INVALID_PARAMETER;
        BAIL_ON_TDNF_ERROR(dwError);
    }

    dwError = AddKeyToKeyRing(pszUrlKeyFile, pKeyring); 
    BAIL_ON_TDNF_ERROR(dwError);

    dwError = VerifyRpmSig(pKeyring, pszPkgFile);
    BAIL_ON_TDNF_ERROR(dwError);

cleanup:
    TDNF_SAFE_FREE_MEMORY(pszKeyData);
    return dwError;

error:
    goto cleanup;
}
Пример #3
0
uint32_t
TDNFCloneCmdArgs(
    PTDNF_CMD_ARGS pCmdArgsIn,
    PTDNF_CMD_ARGS* ppCmdArgs
    )
{
    uint32_t dwError = 0;
    int nIndex = 0;
    PTDNF_CMD_ARGS pCmdArgs = NULL;

    dwError = TDNFAllocateMemory(
                            sizeof(TDNF_CMD_ARGS),
                            (void**)&pCmdArgs);
    BAIL_ON_TDNF_ERROR(dwError);

    pCmdArgs->nAllowErasing  = pCmdArgsIn->nAllowErasing;
    pCmdArgs->nAssumeNo      = pCmdArgsIn->nAssumeNo;
    pCmdArgs->nAssumeYes     = pCmdArgsIn->nAssumeYes;
    pCmdArgs->nBest          = pCmdArgsIn->nBest;
    pCmdArgs->nCacheOnly     = pCmdArgsIn->nCacheOnly;
    pCmdArgs->nDebugSolver   = pCmdArgsIn->nDebugSolver;
    pCmdArgs->nNoGPGCheck    = pCmdArgsIn->nNoGPGCheck;
    pCmdArgs->nRefresh       = pCmdArgsIn->nRefresh;
    pCmdArgs->nRpmVerbosity  = pCmdArgsIn->nRpmVerbosity;
    pCmdArgs->nShowDuplicates= pCmdArgsIn->nShowDuplicates;
    pCmdArgs->nShowHelp      = pCmdArgsIn->nShowHelp;
    pCmdArgs->nShowVersion   = pCmdArgsIn->nShowVersion;
    pCmdArgs->nVerbose       = pCmdArgsIn->nVerbose;
    pCmdArgs->nIPv4          = pCmdArgsIn->nIPv4;
    pCmdArgs->nIPv6          = pCmdArgsIn->nIPv6;

    pCmdArgs->nCmdCount = pCmdArgsIn->nCmdCount;
    dwError = TDNFAllocateMemory(
                            pCmdArgs->nCmdCount * sizeof(char*),
                            (void**)&pCmdArgs->ppszCmds
                            );
    BAIL_ON_TDNF_ERROR(dwError);
        
    for(nIndex = 0; nIndex < pCmdArgs->nCmdCount; ++nIndex)
    {
        dwError = TDNFAllocateString(
                         pCmdArgsIn->ppszCmds[nIndex],
                         &pCmdArgs->ppszCmds[nIndex]);
        BAIL_ON_TDNF_ERROR(dwError);
    }

    *ppCmdArgs = pCmdArgs;

cleanup:
    return dwError;

error:
    if(ppCmdArgs)
    {
        *ppCmdArgs = NULL;
    }
    TDNFFreeCmdArgs(pCmdArgs);
    goto cleanup;
}
Пример #4
0
Файл: repo.c Проект: jreypo/tdnf
uint32_t
TDNFGetGPGCheck(
    PTDNF pTdnf,
    const char* pszRepo,
    int* pnGPGCheck,
    char** ppszUrlGPGKey
    )
{
    uint32_t dwError = 0;
    PTDNF_REPO_DATA pRepo = NULL;
    int nGPGCheck = 0;
    char* pszUrlGPGKey = NULL;

    if(!pTdnf || !ppszUrlGPGKey || IsNullOrEmptyString(pszRepo))
    {
        dwError = ERROR_TDNF_INVALID_PARAMETER;
        BAIL_ON_TDNF_ERROR(dwError);
    }
    if(!pTdnf->pArgs->nNoGPGCheck)
    {
        dwError = TDNFGetRepoById(pTdnf, pszRepo, &pRepo);
        if(dwError == ERROR_TDNF_NO_DATA)
        {
            dwError = 0;
        }
        BAIL_ON_TDNF_ERROR(dwError);
        if(pRepo)
        {
            nGPGCheck = pRepo->nGPGCheck;
            if(nGPGCheck)
            {
                dwError = TDNFAllocateString(
                             pRepo->pszUrlGPGKey,
                             &pszUrlGPGKey);
                BAIL_ON_TDNF_ERROR(dwError);
            }
        }
    }

    *pnGPGCheck = nGPGCheck;
    *ppszUrlGPGKey = pszUrlGPGKey;

cleanup:
    return dwError;

error:
    if(ppszUrlGPGKey)
    {
        *ppszUrlGPGKey = NULL;
    }
    TDNF_SAFE_FREE_MEMORY(pszUrlGPGKey);
    goto cleanup;
}
Пример #5
0
uint32_t
TDNFPopulateTransaction(
    PTDNFRPMTS pTS,
    PTDNF pTdnf,
    PTDNF_SOLVED_PKG_INFO pSolvedInfo
    )
{
    uint32_t dwError = 0;

    if(pSolvedInfo->pPkgsToInstall)
    {
        dwError = TDNFTransAddInstallPkgs(
                      pTS,
                      pTdnf);
        BAIL_ON_TDNF_ERROR(dwError);
    }
    if(pSolvedInfo->pPkgsToReinstall)
    {
        dwError = TDNFTransAddReInstallPkgs(
                      pTS,
                      pTdnf);
        BAIL_ON_TDNF_ERROR(dwError);
    }
    if(pSolvedInfo->pPkgsToUpgrade)
    {
        dwError = TDNFTransAddUpgradePkgs(
                      pTS,
                      pTdnf);
        BAIL_ON_TDNF_ERROR(dwError);
    }
    if(pSolvedInfo->pPkgsToRemove)
    {
        dwError = TDNFTransAddErasePkgs(
                      pTS,
                      pTdnf);
        BAIL_ON_TDNF_ERROR(dwError);
    }
    if(pSolvedInfo->pPkgsToDowngrade)
    {
        dwError = TDNFTransAddDowngradePkgs(
                      pTS,
                      pTdnf);
        BAIL_ON_TDNF_ERROR(dwError);
    }

cleanup:
    return dwError;

error:
    goto cleanup;
}
Пример #6
0
//TODO: This needs to be GetRepoById.
uint32_t
TDNFGetRepoByName(
    PTDNF pTdnf,
    const char* pszName,
    PTDNF_REPO_DATA* ppRepo
    )
{
    uint32_t dwError = 0;
    PTDNF_REPO_DATA pRepo = NULL;
    PTDNF_REPO_DATA pRepos = NULL;

    if(!pTdnf || IsNullOrEmptyString(pszName) || !ppRepo)
    {
        dwError = ERROR_TDNF_INVALID_PARAMETER;
        BAIL_ON_TDNF_ERROR(dwError);
    }

    if(!pTdnf->pRepos)
    {
        dwError = ERROR_TDNF_NO_DATA;
        BAIL_ON_TDNF_ERROR(dwError);
    }

    pRepos = pTdnf->pRepos;

    while(pRepos)
    {
        if(!strcmp(pszName, pRepos->pszId))
        {
            pRepo = pRepos;
            break;
        }
        pRepos = pRepos->pNext;
    }

    if(!pRepo)
    {
        dwError = ERROR_TDNF_NO_DATA;
        BAIL_ON_TDNF_ERROR(dwError);
    }

    *ppRepo = pRepo;
cleanup:
    return dwError;

error:
    goto cleanup;
}
Пример #7
0
uint32_t
TDNFRemoveCachedRpms(
    GArray* pCachedRpmsArray
    )
{
    uint32_t dwError = 0;
    uint32_t dwIndex = 0;
    char* pszCachedRpm = NULL;

    if(!pCachedRpmsArray)
    {
        dwError = ERROR_TDNF_INVALID_PARAMETER;
        BAIL_ON_TDNF_ERROR(dwError);
    }

    for(dwIndex = 0; dwIndex < pCachedRpmsArray->len; ++dwIndex)
    {
        pszCachedRpm = g_array_index(pCachedRpmsArray, char*, dwIndex);
        if(access(pszCachedRpm, F_OK) != -1)
        {
            if(unlink(pszCachedRpm))
            {
                dwError = errno;
                BAIL_ON_TDNF_SYSTEM_ERROR(dwError);
            }
        }
    }

cleanup:
    return dwError;

error:
    goto cleanup;
}
Пример #8
0
uint32_t
TDNFLoadYumRepo(
    HySack hSack,
    HyRepo hRepo,
    int nFlags
    )
{
    uint32_t dwError = 0;

    if(!hSack || !hRepo)
    {
        dwError = ERROR_TDNF_INVALID_PARAMETER;
        BAIL_ON_TDNF_ERROR(dwError);
    }

    dwError = hy_sack_load_yum_repo(hSack, hRepo, nFlags);
    BAIL_ON_TDNF_HAWKEY_ERROR(dwError);

cleanup:
    return dwError;

error:
    if(hSack)
    {
        hy_sack_free(hSack);
    }
    goto cleanup;
}
Пример #9
0
Файл: goal.c Проект: jreypo/tdnf
uint32_t
TDNFGoal(
    PTDNF pTdnf,
    HyPackageList hPkgList,
    PTDNF_SOLVED_PKG_INFO pInfo
    )
{
    uint32_t dwError = 0;

    HyGoal hGoal = NULL;
    HyPackage hPkg = NULL;
    PTDNF_SOLVED_PKG_INFO pInfoTemp = NULL;

    int nFlags = 0;
    int i = 0;

    if(!pTdnf || !hPkgList || !pInfo )
    {
        dwError = ERROR_TDNF_INVALID_PARAMETER;
        BAIL_ON_TDNF_ERROR(dwError);
    }

    hGoal = hy_goal_create(pTdnf->hSack);
    if(!hGoal)
    {
        dwError = ERROR_TDNF_GOAL_CREATE;
        BAIL_ON_TDNF_ERROR(dwError);
    }

    if(pInfo->nAlterType == ALTER_UPGRADEALL)
    {
        dwError = hy_goal_upgrade_all(hGoal);
        BAIL_ON_TDNF_HAWKEY_ERROR(dwError);
    }
    else if(pInfo->nAlterType == ALTER_DISTRO_SYNC)
    {
        dwError = hy_goal_distupgrade_all(hGoal);
        BAIL_ON_TDNF_HAWKEY_ERROR(dwError);
    }
    else
    {
        FOR_PACKAGELIST(hPkg, hPkgList, i)
        {
            TDNFAddGoal(pTdnf, pInfo->nAlterType, hGoal, hPkg);
        }
    }
Пример #10
0
uint32_t
TDNFInitSack(
    PTDNF pTdnf,
    HySack* phSack,
    int nFlags
    )
{
    uint32_t dwError = 0;
    HySack hSack = NULL;
    char* pszHawkeyCacheDir = NULL;

    if(!pTdnf || !pTdnf->pConf || !phSack)
    {
        dwError = ERROR_TDNF_INVALID_PARAMETER;
        BAIL_ON_TDNF_ERROR(dwError);
    }

    pszHawkeyCacheDir = pTdnf->pConf->pszCacheDir;

    hSack = hy_sack_create(pszHawkeyCacheDir, NULL, "/", 0);
    if(!hSack)
    {
        dwError = ERROR_TDNF_INVALID_PARAMETER;
        BAIL_ON_TDNF_ERROR(dwError);
    }

    dwError = hy_sack_load_system_repo(hSack, NULL, nFlags);
    BAIL_ON_TDNF_HAWKEY_ERROR(dwError);

    *phSack = hSack;
cleanup:
    return dwError;

error:
    if(hSack)
    {
        hy_sack_free(hSack);
    }
    if(phSack)
    {
        *phSack = NULL;
    }
    goto cleanup;
}
Пример #11
0
uint32_t
TDNFTransAddErasePkg(
    PTDNFRPMTS pTS,
    HyPackage hPkg
    )
{
    uint32_t dwError = 0;
    Header pRpmHeader = NULL;
    rpmdbMatchIterator pIterator = NULL;
    const char* pszName = NULL;
    unsigned int nOffset = 0;

    if(!pTS || !hPkg)
    {
        dwError = ERROR_TDNF_INVALID_PARAMETER;
        BAIL_ON_TDNF_ERROR(dwError);
    }

    pszName = hy_package_get_name(hPkg);

    pIterator = rpmtsInitIterator(pTS->pTS, (rpmTag)RPMDBI_LABEL, pszName, 0);
    while ((pRpmHeader = rpmdbNextIterator(pIterator)) != NULL)
    {
        nOffset = rpmdbGetIteratorOffset(pIterator);
        if(nOffset)
        {
            dwError = rpmtsAddEraseElement(pTS->pTS, pRpmHeader, nOffset);
            BAIL_ON_TDNF_ERROR(dwError);
        }
    }

cleanup:
    if(pIterator)
    {
        rpmdbFreeIterator(pIterator);
    }
    return dwError;

error:
    goto cleanup;
}
Пример #12
0
uint32_t
TDNFGoalGetResults(
    HyPackageList hPkgList,
    PTDNF_PKG_INFO* ppPkgInfoResults
    )
{
    uint32_t dwError = 0;
    PTDNF_PKG_INFO pPkgInfoResults = NULL;

    if(!hPkgList || !ppPkgInfoResults)
    {
        dwError = ERROR_TDNF_INVALID_PARAMETER;
        BAIL_ON_TDNF_ERROR(dwError);
    }

    dwError = TDNFPopulatePkgInfos(
                  hPkgList,
                  &pPkgInfoResults);
    BAIL_ON_TDNF_ERROR(dwError);

    *ppPkgInfoResults = pPkgInfoResults;
cleanup:
    if(hPkgList)
    {
        hy_packagelist_free(hPkgList);
    }
    return dwError;

error:
    if(ppPkgInfoResults)
    {
        *ppPkgInfoResults = NULL;
    }
    if(pPkgInfoResults)
    {
        TDNFFreePackageInfo(pPkgInfoResults);
    }
    goto cleanup;
}
Пример #13
0
uint32_t
TDNFPrintRepoMetadata(
    LrYumRepoMd* pRepoMD
    )
{
    uint32_t dwError = 0;

    GSList* pElem = NULL;

    if(!pRepoMD)
    {
        dwError = ERROR_TDNF_INVALID_PARAMETER;
        BAIL_ON_TDNF_ERROR(dwError);
    }

    pElem = pRepoMD->records;

    printf("Repo metadata info:\n");

    for (; pElem; pElem = g_slist_next(pElem))
    {
        LrYumRepoMdRecord* pRec = (LrYumRepoMdRecord*) pElem->data;
        printf(" Type: %s\n", pRec->type);
        printf(" Location href: %s\n", pRec->location_href);
        if (pRec->location_base)
            printf(" Location base: %s\n", pRec->location_base);
        if (pRec->checksum)
            printf(" Checksum: %s\n", pRec->checksum);
        if (pRec->checksum_type)
            printf(" Checksum type: %s\n", pRec->checksum_type);
        if (pRec->checksum_open)
            printf(" Checksum open: %s\n", pRec->checksum_open);
        if (pRec->checksum_open_type)
            printf(" Checksum open type: %s\n", pRec->checksum_open_type);
        if (pRec->timestamp > 0)
            printf(" Timestamp: %"G_GINT64_FORMAT"\n", pRec->timestamp);
        if (pRec->size > 0)
            printf(" Size: %"G_GINT64_FORMAT"\n", pRec->size);
        if (pRec->size_open > 0)
            printf(" Size open: %"G_GINT64_FORMAT"\n", pRec->size_open);
        if (pRec->db_version > 0)
            printf(" Db version: %d\n", pRec->db_version);
        printf("------------------------------------------------\n");
    }
cleanup:
    return dwError;

error:
    goto cleanup;
}
Пример #14
0
uint32_t
TDNFTransAddErasePkgs(
    PTDNFRPMTS pTS,
    PTDNF pTdnf
    )
{
    uint32_t dwError = 0;
    int i = 0;
    HyPackage hPkg = NULL;
    HyPackageList hPkgList = NULL;

    hPkgList = hy_goal_list_erasures(pTdnf->hGoal);
    if(!hPkgList)
    {
        dwError = ERROR_TDNF_NO_DATA;
        BAIL_ON_TDNF_ERROR(dwError);
    }
    for(i = 0; (hPkg = hy_packagelist_get(hPkgList, i)) != NULL; ++i)
    {
        dwError = TDNFTransAddErasePkg(pTS, hPkg);
        BAIL_ON_TDNF_ERROR(dwError);
    }

cleanup:
    if(hPkgList)
    {
        hy_packagelist_free(hPkgList);
    }
    return dwError;

error:
    if(dwError == ERROR_TDNF_NO_DATA)
    {
        dwError = 0;
    }
    goto cleanup;
}
Пример #15
0
Файл: api.c Проект: jreypo/tdnf
//All alter commands such as install/update/erase
uint32_t
TDNFAlterCommand(
    PTDNF pTdnf,
    TDNF_ALTERTYPE nAlterType,
    PTDNF_SOLVED_PKG_INFO pSolvedInfo
    )
{
    uint32_t dwError = 0;

    if(!pTdnf || !pSolvedInfo)
    {
        dwError = ERROR_TDNF_INVALID_PARAMETER;
        BAIL_ON_TDNF_ERROR(dwError);
    }

    dwError = TDNFRpmExecTransaction(pTdnf, pSolvedInfo);
    BAIL_ON_TDNF_ERROR(dwError);

cleanup:
    return dwError;

error:
    goto cleanup;
}
Пример #16
0
uint32_t
TDNFGoalSetUserInstalled(
    HyGoal hGoal,
    HyPackageList hPkgList
    )
{
    uint32_t dwError = 0;
    int i = 0;
    HyPackage hPkg = NULL;

    if(!hGoal || !hPkgList)
    {
        dwError = ERROR_TDNF_INVALID_PARAMETER;
        BAIL_ON_TDNF_ERROR(dwError);
    }

    FOR_PACKAGELIST(hPkg, hPkgList, i)
    {
        dwError = hy_goal_userinstalled(hGoal, hPkg);
        BAIL_ON_TDNF_HAWKEY_ERROR(dwError);
    }
Пример #17
0
uint32_t
TDNFGoalReportProblems(
    HyGoal hGoal
    )
{
    uint32_t dwError = 0;
    int i = 0;
    int nCount = 0;
    char* pszProblem = NULL;

    if(!hGoal)
    {
        dwError = ERROR_TDNF_INVALID_PARAMETER;
        BAIL_ON_TDNF_ERROR(dwError);
    }

    nCount = hy_goal_count_problems(hGoal);
    if(nCount > 0)
    {
        fprintf(stdout, "Found %d problem(s) while resolving\n", nCount);
        for(; i < nCount; ++i)
        {
            pszProblem = hy_goal_describe_problem(hGoal, i);
            fprintf(stdout, "%d. %s\n", i+1, pszProblem);

            hy_free(pszProblem);
            pszProblem = NULL;
        }
    }
cleanup:
    if(pszProblem)
    {
        hy_free(pszProblem);
    }
    return dwError;

error:
    goto cleanup;
}
Пример #18
0
uint32_t
TDNFInitRepoFromMetaData(
    HyRepo hRepo,
    LrYumRepo* pRepo
    )
{
    uint32_t dwError = 0;
    const char* pszValue = NULL;
    
    if(!pRepo)
    {
        dwError = ERROR_TDNF_INVALID_PARAMETER;
        BAIL_ON_TDNF_ERROR(dwError);
    }

    hy_repo_set_string(hRepo, HY_REPO_MD_FN, pRepo->repomd);
    pszValue = lr_yum_repo_path(pRepo, "primary");
    if(pszValue)
    {
        hy_repo_set_string(hRepo, HY_REPO_PRIMARY_FN, pszValue);
    }
    pszValue = lr_yum_repo_path(pRepo, "filelists");
    if(pszValue != NULL)
    {
        hy_repo_set_string(hRepo, HY_REPO_FILELISTS_FN, pszValue);
    }
    pszValue = lr_yum_repo_path(pRepo, "updateinfo");
    if(pszValue != NULL)
    {
        hy_repo_set_string (hRepo, HY_REPO_UPDATEINFO_FN, pszValue);
    }

cleanup:
    return dwError;

error:
    goto cleanup;
}
Пример #19
0
Файл: api.c Проект: jreypo/tdnf
//check a local rpm folder for dependency issues.
uint32_t
TDNFCheckLocalPackages(
    PTDNF pTdnf,
    const char* pszLocalPath
    )
{
    uint32_t dwError = 0;
    int i = 0;
    char* pszRPMPath = NULL;
    const char* pszFile = NULL;
    GDir* pDir = NULL;
    HySack hSack = NULL;
    HyPackage hPkg = NULL;
    HyGoal hGoal = NULL;
    HyPackageList hPkgList = NULL;

    if(!pTdnf || !pszLocalPath)
    {
        dwError = ERROR_TDNF_INVALID_PARAMETER;
        BAIL_ON_TDNF_ERROR(dwError);
    }

    pDir = g_dir_open(pszLocalPath, 0, NULL);
    if(!pDir)
    {
        dwError = errno;
        BAIL_ON_TDNF_SYSTEM_ERROR(dwError);
    }
    fprintf(stdout, "Checking all packages from: %s\n", pszLocalPath);

    hSack = hy_sack_create(NULL, NULL, NULL, 0);
    if(!hSack)
    {
        dwError = ERROR_TDNF_INVALID_PARAMETER;
        BAIL_ON_TDNF_ERROR(dwError);
    }

    hy_sack_create_cmdline_repo(hSack);
    hPkgList = hy_packagelist_create();
    if(!hPkgList)
    {
        dwError = ERROR_TDNF_INVALID_PARAMETER;
        BAIL_ON_TDNF_ERROR(dwError);
    }

    while ((pszFile = g_dir_read_name (pDir)) != NULL)
    {
        if (!g_str_has_suffix (pszFile, TDNF_RPM_EXT))
        {
            continue;
        }
        pszRPMPath = g_build_filename(pszLocalPath, pszFile, NULL);
        hPkg = hy_sack_add_cmdline_package(hSack, pszRPMPath);

        g_free(pszRPMPath);
        pszRPMPath = NULL;

        if(!hPkg)
        {
            dwError = ERROR_TDNF_INVALID_PARAMETER; 
            BAIL_ON_TDNF_ERROR(dwError);
        }
        hy_packagelist_push(hPkgList, hPkg);
        hPkg = NULL;
    }

    fprintf(stdout, "Found %d packages\n", hy_packagelist_count(hPkgList));

    hGoal = hy_goal_create(hSack);
    if(!hGoal)
    {
        dwError = ERROR_TDNF_INVALID_PARAMETER;
        BAIL_ON_TDNF_ERROR(dwError);
    }

    FOR_PACKAGELIST(hPkg, hPkgList, i)
    {
        dwError = hy_goal_install(hGoal, hPkg);
        BAIL_ON_TDNF_HAWKEY_ERROR(dwError);
    }
Пример #20
0
uint32_t
TDNFRpmExecTransaction(
    PTDNF pTdnf,
    PTDNF_SOLVED_PKG_INFO pSolvedInfo
    )
{
    uint32_t dwError = 0;
    int nKeepCachedRpms = 0;
    TDNFRPMTS ts = {0};

    if(!pTdnf || !pTdnf->pConf || !pSolvedInfo)
    {
        dwError = ERROR_TDNF_INVALID_PARAMETER;
        BAIL_ON_TDNF_ERROR(dwError);
    }

    nKeepCachedRpms = pTdnf->pConf->nKeepCache;

    ts.pCachedRpmsArray = g_array_new(TRUE, TRUE, sizeof(char*));
    if(!ts.pCachedRpmsArray)
    {
        dwError = ERROR_TDNF_OUT_OF_MEMORY;
        BAIL_ON_TDNF_ERROR(dwError);
    }

    dwError = rpmReadConfigFiles(NULL, NULL);
    BAIL_ON_TDNF_ERROR(dwError);

    rpmSetVerbosity(TDNFConfGetRpmVerbosity(pTdnf));

    //Allow downgrades
    ts.nProbFilterFlags = RPMPROB_FILTER_OLDPACKAGE;
    if(pSolvedInfo->nAlterType == ALTER_REINSTALL)
    {
        ts.nProbFilterFlags = ts.nProbFilterFlags | RPMPROB_FILTER_REPLACEPKG;
    }

    ts.pTS = rpmtsCreate();
    if(!ts.pTS)
    {
        dwError = ERROR_TDNF_RPMTS_CREATE_FAILED;
        BAIL_ON_TDNF_ERROR(dwError);
    }
    ts.pKeyring = rpmKeyringNew();
    if(!ts.pKeyring)
    {
        dwError = ERROR_TDNF_RPMTS_KEYRING_FAILED;
        BAIL_ON_TDNF_ERROR(dwError);
    }

    ts.nTransFlags = rpmtsSetFlags (ts.pTS, RPMTRANS_FLAG_NONE);

    if(rpmtsSetRootDir (ts.pTS, pTdnf->pArgs->pszInstallRoot))
    {
        dwError = ERROR_TDNF_RPMTS_BAD_ROOT_DIR;
        BAIL_ON_TDNF_ERROR(dwError);
    }

    if(rpmtsSetNotifyCallback(ts.pTS, TDNFRpmCB, (void*)&ts))
    {
        dwError = ERROR_TDNF_RPMTS_SET_CB_FAILED;
        BAIL_ON_TDNF_ERROR(dwError);
    }


    dwError = TDNFPopulateTransaction(&ts, pTdnf, pSolvedInfo);
    BAIL_ON_TDNF_ERROR(dwError);

    dwError = TDNFRunTransaction(&ts, pTdnf);
    BAIL_ON_TDNF_ERROR(dwError);

cleanup:
    if(ts.pTS)
    {
        rpmtsCloseDB(ts.pTS);
        rpmtsFree(ts.pTS);
    }
    if(ts.pKeyring)
    {
        rpmKeyringFree(ts.pKeyring);
    }
    if(ts.pCachedRpmsArray)
    {
        if(!nKeepCachedRpms)
        {
            TDNFRemoveCachedRpms(ts.pCachedRpmsArray);
        }
        TDNFFreeCachedRpmsArray(ts.pCachedRpmsArray);
    }
    return dwError;

error:
    goto cleanup;
}
Пример #21
0
uint32_t
TDNFGoal(
    PTDNF pTdnf,
    HyPackageList hPkgList,
    HySelector hSelector,
    TDNF_ALTERTYPE nResolveFor,
    PTDNF_SOLVED_PKG_INFO pInfo
    )
{
    uint32_t dwError = 0;
    HyGoal hGoal = NULL;
    HyPackage hPkg = NULL;
    PTDNF_PKG_INFO pPkgsToInstall = NULL;
    PTDNF_PKG_INFO pPkgsToUpgrade = NULL;
    PTDNF_PKG_INFO pPkgsToDowngrade = NULL;
    PTDNF_PKG_INFO pPkgsToRemove = NULL;
    PTDNF_PKG_INFO pPkgsUnNeeded = NULL;
    PTDNF_PKG_INFO pPkgsToReinstall = NULL;

    int nFlags = 0;
    int nRequirePkgList =
        (nResolveFor != ALTER_UPGRADEALL &&
         nResolveFor != ALTER_DISTRO_SYNC);

    if(!pTdnf || !pInfo )
    {
        dwError = ERROR_TDNF_INVALID_PARAMETER;
        BAIL_ON_TDNF_ERROR(dwError);
    }

    if(nResolveFor == ALTER_UPGRADE && !hSelector)
    {
        dwError = ERROR_TDNF_INVALID_PARAMETER;
        BAIL_ON_TDNF_ERROR(dwError);
    }

    if(nRequirePkgList)
    {
        if(!hPkgList)
        {
            dwError = ERROR_TDNF_INVALID_PARAMETER;
            BAIL_ON_TDNF_ERROR(dwError);
        }

        hPkg = hy_packagelist_get(hPkgList, 0);
        if(!hPkg)
        {
            dwError = ERROR_TDNF_PACKAGELIST_EMPTY;
            BAIL_ON_TDNF_ERROR(dwError);
        }
    }

    hGoal = hy_goal_create(pTdnf->hSack);
    if(!hGoal)
    {
        dwError = ERROR_TDNF_GOAL_CREATE;
        BAIL_ON_TDNF_ERROR(dwError);
    }
    switch(nResolveFor)
    {
        case ALTER_DOWNGRADE:
            dwError = hy_goal_downgrade_to(hGoal, hPkg);
            BAIL_ON_TDNF_HAWKEY_ERROR(dwError);
            break;
        case ALTER_ERASE:
            dwError = hy_goal_erase(hGoal, hPkg);
            BAIL_ON_TDNF_HAWKEY_ERROR(dwError);
            break;
        case ALTER_REINSTALL:
            dwError = hy_goal_install(hGoal, hPkg);
            BAIL_ON_TDNF_HAWKEY_ERROR(dwError);
            break;
        case ALTER_INSTALL:
            dwError = TDNFPackageGetLatest(hPkgList, &hPkg);
            BAIL_ON_TDNF_ERROR(dwError);
            dwError = hy_goal_install(hGoal, hPkg);
            BAIL_ON_TDNF_HAWKEY_ERROR(dwError);
            break;
        case ALTER_UPGRADE:
            dwError = hy_goal_upgrade_to_selector(hGoal, hSelector);
            BAIL_ON_TDNF_HAWKEY_ERROR(dwError);
            break;
        case ALTER_UPGRADEALL:
            dwError = hy_goal_upgrade_all(hGoal);
            BAIL_ON_TDNF_HAWKEY_ERROR(dwError);
            break;
        case ALTER_DISTRO_SYNC:
            dwError = hy_goal_distupgrade_all(hGoal);
            BAIL_ON_TDNF_HAWKEY_ERROR(dwError);
            break;
        case ALTER_AUTOERASE:
            dwError = TDNFGoalSetUserInstalled(hGoal, hPkgList);
            BAIL_ON_TDNF_HAWKEY_ERROR(dwError);
            break;
        default:
            dwError = ERROR_TDNF_INVALID_RESOLVE_ARG;
            BAIL_ON_TDNF_ERROR(dwError);
    }

    if(pTdnf->pArgs->nBest)
    {
        nFlags = nFlags | HY_FORCE_BEST;
    }
    if(pTdnf->pArgs->nAllowErasing ||
       nResolveFor == ALTER_ERASE ||
       nResolveFor == ALTER_AUTOERASE)
    {
        nFlags = nFlags | HY_ALLOW_UNINSTALL;
    }

    dwError = hy_goal_run_flags(hGoal, nFlags);
    if(pTdnf->pArgs->nDebugSolver)
    {
        hy_goal_write_debugdata(hGoal, "debugdata");
    }
    BAIL_ON_TDNF_HAWKEY_ERROR(dwError);

    dwError = TDNFGoalGetResultsIgnoreNoData(
                  hy_goal_list_installs(hGoal),
                  &pPkgsToInstall);
    BAIL_ON_TDNF_ERROR(dwError);

    dwError = TDNFGoalGetResultsIgnoreNoData(
                  hy_goal_list_upgrades(hGoal),
                  &pPkgsToUpgrade);
    BAIL_ON_TDNF_ERROR(dwError);

    dwError = TDNFGoalGetResultsIgnoreNoData(
                  hy_goal_list_downgrades(hGoal),
                  &pPkgsToDowngrade);
    BAIL_ON_TDNF_ERROR(dwError);

    dwError = TDNFGoalGetResultsIgnoreNoData(
                  hy_goal_list_erasures(hGoal),
                  &pPkgsToRemove);
    BAIL_ON_TDNF_ERROR(dwError);

    if(nResolveFor == ALTER_AUTOERASE)
    {
        dwError = TDNFGoalGetResultsIgnoreNoData(
                      hy_goal_list_unneeded(hGoal),
                      &pPkgsUnNeeded);
        BAIL_ON_TDNF_ERROR(dwError);
    }
    dwError = TDNFGoalGetResultsIgnoreNoData(
                  hy_goal_list_reinstalls(hGoal),
                  &pPkgsToReinstall);
    BAIL_ON_TDNF_ERROR(dwError);

    pInfo->pPkgsToInstall = pPkgsToInstall;
    pInfo->pPkgsToUpgrade = pPkgsToUpgrade;
    pInfo->pPkgsToDowngrade = pPkgsToDowngrade;
    pInfo->pPkgsToRemove = pPkgsToRemove;
    pInfo->pPkgsUnNeeded = pPkgsUnNeeded;
    pInfo->pPkgsToReinstall = pPkgsToReinstall;
    pTdnf->hGoal = hGoal;

cleanup:
    return dwError;

error:
    if(hGoal)
    {
        TDNFGoalReportProblems(hGoal);
        hy_goal_free(hGoal);
    }
    if(pPkgsToInstall)
    {
        TDNFFreePackageInfo(pPkgsToInstall);
    }
    if(pPkgsToUpgrade)
    {
        TDNFFreePackageInfo(pPkgsToUpgrade);
    }
    if(pPkgsToDowngrade)
    {
        TDNFFreePackageInfo(pPkgsToDowngrade);
    }
    if(pPkgsToRemove)
    {
        TDNFFreePackageInfo(pPkgsToRemove);
    }
    if(pPkgsUnNeeded)
    {
        TDNFFreePackageInfo(pPkgsUnNeeded);
    }
    if(pPkgsToReinstall)
    {
        TDNFFreePackageInfo(pPkgsToReinstall);
    }
    goto cleanup;
}
Пример #22
0
uint32_t
ReadAllBytes(
    const char* pszFile,
    char** ppszData
    )
{
    uint32_t dwError = 0;
    size_t fsize = 0;
    char* pszData = NULL;
    FILE* fp = NULL;

    if(IsNullOrEmptyString(pszFile) || !ppszData)
    {
        dwError = ERROR_TDNF_INVALID_PARAMETER;
        BAIL_ON_TDNF_ERROR(dwError);
    }

    fp = fopen(pszFile, "r");
    if(!fp)
    {
        dwError = errno;
        BAIL_ON_TDNF_SYSTEM_ERROR(dwError);
    }

    if(fseek(fp, 0, SEEK_END))
    {
        dwError = errno;
        BAIL_ON_TDNF_SYSTEM_ERROR(dwError);
    }
    fsize = ftell(fp);
    if(fseek(fp, 0, SEEK_SET))
    {
        dwError = errno;
        BAIL_ON_TDNF_SYSTEM_ERROR(dwError);
    }

    dwError = TDNFAllocateMemory(fsize+1, (void**)&pszData);
    BAIL_ON_TDNF_ERROR(dwError);

    if(!fread(pszData, fsize, 1, fp))
    {
        dwError = errno;
        BAIL_ON_TDNF_SYSTEM_ERROR(dwError);
    }

    *ppszData = pszData;
cleanup:
    if(fp)
    {
        fclose(fp);
    }
    return dwError;

error:
    if(!ppszData)
    {
        *ppszData = NULL;
    }
    TDNF_SAFE_FREE_MEMORY(pszData);
    goto cleanup;
}
Пример #23
0
uint32_t
VerifyRpmSig(
    rpmKeyring pKeyring,
    const char* pszPkgFile
    )
{
    uint32_t dwError = 0;
    FD_t pFD_t = NULL;
    rpmts pTS = NULL;
    rpmtd pTD = NULL;
    Header pPkgHeader = NULL;
    pgpDig pDigest = NULL;


    if(!pKeyring || IsNullOrEmptyString(pszPkgFile))
    {
        dwError = ERROR_TDNF_INVALID_PARAMETER;
        BAIL_ON_TDNF_ERROR(dwError);
    }

    pFD_t = Fopen(pszPkgFile, "r.fdio");
    if(!pFD_t)
    {
        dwError = errno;
        BAIL_ON_TDNF_SYSTEM_ERROR(dwError);
    }

    pTS = rpmtsCreate();
    if(!pTS)
    {
        dwError = ERROR_TDNF_RPMTS_CREATE_FAILED;
        BAIL_ON_TDNF_RPM_ERROR(dwError);
    }
    rpmtsSetVSFlags (pTS, _RPMVSF_NOSIGNATURES);

    pTD = rpmtdNew();
    if(!pTD)
    {
        dwError = ERROR_TDNF_RPMTD_CREATE_FAILED;
        BAIL_ON_TDNF_RPM_ERROR(dwError);
    }

    dwError = rpmReadPackageFile(pTS, pFD_t, pszPkgFile, &pPkgHeader);
    BAIL_ON_TDNF_RPM_ERROR(dwError);

    if(!headerConvert(pPkgHeader, HEADERCONV_RETROFIT_V3))
    {
        dwError = ERROR_TDNF_RPM_HEADER_CONVERT_FAILED; 
        BAIL_ON_TDNF_RPM_ERROR(dwError);
    }

    if(!headerGet(pPkgHeader, RPMTAG_RSAHEADER, pTD, HEADERGET_MINMEM))
    {
        dwError = ERROR_TDNF_RPM_GET_RSAHEADER_FAILED;
        BAIL_ON_TDNF_ERROR(dwError);
    }

    pDigest = pgpNewDig();
    if(pgpPrtPkts(pTD->data, pTD->count, pDigest, 0))
    {
        dwError = ERROR_TDNF_RPM_GPG_PARSE_FAILED;
        BAIL_ON_TDNF_ERROR(dwError);
    }

    if(rpmKeyringLookup(pKeyring, pDigest) != RPMRC_OK)
    {
        dwError = ERROR_TDNF_RPM_GPG_NO_MATCH;
        BAIL_ON_TDNF_ERROR(dwError);
    }

cleanup:
    if(pFD_t)
    {
        Fclose(pFD_t);
    }
    if(pDigest)
    {
        pgpFreeDig(pDigest);
    }
    if(pPkgHeader)
    {
        headerFree(pPkgHeader);
    }
    if(pTD)
    {
        rpmtdFree(pTD);
    }
    if(pTS)
    {
        rpmtsFree(pTS);
    }
    return dwError;

error:
    goto cleanup;
}
Пример #24
0
uint32_t
TDNFTransAddInstallPkg(
    PTDNFRPMTS pTS,
    PTDNF pTdnf,
    HyPackage hPkg,
    int nUpgrade
    )
{
    uint32_t dwError = 0;
    int nGPGCheck = 0;
    char* pszRpmCacheDir = NULL;
    char* pszFilePath = NULL;
    const char* pszRepoName = NULL;
    char* pszHyName = NULL;
    Header rpmHeader = NULL;
    FD_t fp = NULL;
    char* pszDownloadCacheDir = NULL;
    char* pszUrlGPGKey = NULL;

    pszRepoName = hy_package_get_reponame(hPkg);
    pszHyName = hy_package_get_location(hPkg);

    pszRpmCacheDir = g_build_filename(
                           G_DIR_SEPARATOR_S,
                           pTdnf->pConf->pszCacheDir,
                           pszRepoName,
                           "rpms",
                           G_DIR_SEPARATOR_S,
                           NULL);
    pszFilePath = g_build_filename(pszRpmCacheDir, pszHyName, NULL);
    if(pTS->pCachedRpmsArray)
    {
        if(!g_array_append_val(pTS->pCachedRpmsArray, pszFilePath))
        {
            dwError = ERROR_TDNF_OUT_OF_MEMORY;
            BAIL_ON_TDNF_ERROR(dwError);
        }
    }

    pszDownloadCacheDir = g_path_get_dirname(pszFilePath);
    if(!pszDownloadCacheDir)
    {
        dwError = ENOENT;
        BAIL_ON_TDNF_SYSTEM_ERROR(dwError);
    }

    if(access(pszDownloadCacheDir, F_OK))
    {
        if(errno != ENOENT)
        {
            dwError = errno;
        } 
        BAIL_ON_TDNF_SYSTEM_ERROR(dwError);

        dwError = TDNFUtilsMakeDirs(pszDownloadCacheDir);
        BAIL_ON_TDNF_ERROR(dwError);
    }

    if(access(pszFilePath, F_OK))
    {
        if(errno != ENOENT)
        {
            dwError = errno;
            BAIL_ON_TDNF_SYSTEM_ERROR(dwError);
        }
        dwError = TDNFDownloadPackage(pTdnf, hPkg, pszDownloadCacheDir);
        BAIL_ON_TDNF_ERROR(dwError);
    }
    //A download could have been triggered.
    //So check access and bail if not available
    if(access(pszFilePath, F_OK))
    {
        dwError = errno;
        BAIL_ON_TDNF_SYSTEM_ERROR(dwError);
    }

    //Check override, then repo config and launch
    //gpg check if needed
    dwError = TDNFGetGPGCheck(pTdnf, pszRepoName, &nGPGCheck, &pszUrlGPGKey);
    BAIL_ON_TDNF_ERROR(dwError);
    if(nGPGCheck)
    {
        dwError = TDNFGPGCheck(pTS->pKeyring, pszUrlGPGKey, pszFilePath);
        BAIL_ON_TDNF_ERROR(dwError);
    }

    fp = Fopen (pszFilePath, "r.ufdio");
    if(!fp)
    {
        dwError = errno;
        BAIL_ON_TDNF_SYSTEM_ERROR(dwError);
    }

    dwError = rpmReadPackageFile(
                     pTS->pTS,
                     fp,
                     pszFilePath,
                     &rpmHeader);
    //If not checking gpg sigs, ignore signature errors
    if(!nGPGCheck && (dwError == RPMRC_NOTTRUSTED || dwError == RPMRC_NOKEY))
    {
        dwError = 0;
    }
    BAIL_ON_TDNF_RPM_ERROR(dwError);

    dwError = rpmtsAddInstallElement(
                   pTS->pTS,
                   rpmHeader,
                   (fnpyKey)pszFilePath,
                   nUpgrade,
                   NULL);
    BAIL_ON_TDNF_RPM_ERROR(dwError);
cleanup:
    TDNF_SAFE_FREE_MEMORY(pszUrlGPGKey);
    if(pszHyName)
    {
        hy_free(pszHyName);
    }
    if(pszDownloadCacheDir)
    {
        g_free(pszDownloadCacheDir);
    }
    if(pszRpmCacheDir)
    {
        g_free(pszRpmCacheDir);
    }
    if(fp)
    {
        Fclose(fp);
    }
    if(rpmHeader)
    {
        headerFree(rpmHeader);
    }
    return dwError;

error:
    goto cleanup;
}
Пример #25
0
uint32_t
AddKeyToKeyRing(
    const char* pszFile,
    rpmKeyring pKeyring
    )
{
    uint32_t dwError = 0;
    pgpArmor nArmor = PGPARMOR_NONE;
    pgpDig pDig = NULL;
    rpmPubkey pPubkey = NULL;
    uint8_t* pPkt = NULL;
    size_t nPktLen = 0;
    char* pszKeyData = NULL;

    if(IsNullOrEmptyString(pszFile) || !pKeyring)
    {
        dwError = ERROR_TDNF_INVALID_PARAMETER;
        BAIL_ON_TDNF_ERROR(dwError);
    }

    dwError = ReadGPGKey(pszFile, &pszKeyData);
    BAIL_ON_TDNF_ERROR(dwError);

    nArmor = pgpParsePkts(pszKeyData, &pPkt, &nPktLen);
    if(nArmor != PGPARMOR_PUBKEY) 
    {
        dwError = ERROR_TDNF_INVALID_PUBKEY_FILE;
        BAIL_ON_TDNF_ERROR(dwError);
    }
    pPubkey = rpmPubkeyNew (pPkt, nPktLen);
    if(!pPubkey)
    {
        dwError = ERROR_TDNF_CREATE_PUBKEY_FAILED;
        BAIL_ON_TDNF_ERROR(dwError);
    }

    pDig = rpmPubkeyDig(pPubkey);
    if(!pDig)
    {
        dwError = ERROR_TDNF_CREATE_PUBKEY_FAILED;
        BAIL_ON_TDNF_ERROR(dwError);
    }

    dwError = rpmKeyringLookup(pKeyring, pDig);
    if(dwError == RPMRC_OK)
    {
        dwError = 0;//key exists
    }
    else
    {
        dwError = rpmKeyringAddKey(pKeyring, pPubkey);
        if(dwError == 1)
        {
            dwError = 0;//Already added. ignore
        }
        BAIL_ON_TDNF_ERROR(dwError);
    }

cleanup:
    return dwError;
error:
    TDNF_SAFE_FREE_MEMORY(pszKeyData);
    if(pPubkey)
    {
        rpmPubkeyFree(pPubkey);
    }
    goto cleanup;
}
Пример #26
0
uint32_t
ReadGPGKey(
   const char* pszKeyUrl,
   char** ppszKeyData
   )
{
    uint32_t dwError = 0;
    gchar* pszScheme = NULL;
    gchar* pszFile = NULL;
    char* pszKeyData = NULL;
    int nPathIsDir = 0;

    if(IsNullOrEmptyString(pszKeyUrl) || !ppszKeyData)
    {
        dwError = ERROR_TDNF_INVALID_PARAMETER;
        BAIL_ON_TDNF_ERROR(dwError);
    }
    
    pszScheme = g_uri_parse_scheme(pszKeyUrl);
    if(!pszScheme)
    {
        dwError = ERROR_TDNF_KEYURL_INVALID;
        BAIL_ON_TDNF_ERROR(dwError);
    }
    if(strcasecmp("file", pszScheme))
    {
        dwError = ERROR_TDNF_KEYURL_UNSUPPORTED;
        BAIL_ON_TDNF_ERROR(dwError);
    }

    pszFile = g_filename_from_uri(pszKeyUrl, NULL, NULL);
    if(!pszFile)
    {
        dwError = ERROR_TDNF_KEYURL_INVALID;
        BAIL_ON_TDNF_ERROR(dwError);
    }

    dwError = TDNFIsDir(pszFile, &nPathIsDir);
    BAIL_ON_TDNF_ERROR(dwError);

    if(nPathIsDir)
    {
        dwError = ERROR_TDNF_KEYURL_INVALID;
        BAIL_ON_TDNF_ERROR(dwError);
    }

    dwError = ReadAllBytes(pszFile, &pszKeyData);
    BAIL_ON_TDNF_ERROR(dwError);

    *ppszKeyData = pszKeyData;

cleanup:
    if(pszScheme)
    {
        g_free(pszScheme);
    }
    if(pszFile)
    {
        g_free(pszFile);
    }
    return dwError;

error:
    goto cleanup;
}
Пример #27
0
uint32_t
TDNFRefreshCache(
    PTDNF pTdnf
    )
{
    uint32_t dwError = 0;
    HySack hSack = NULL;

    if(!pTdnf)
    {
        dwError = ERROR_TDNF_INVALID_PARAMETER;
        BAIL_ON_TDNF_ERROR(dwError);
    }

    //Creating a new sack without removing the
    //old one did not work well. Remove first, then 
    //create 
    if(pTdnf->hSack)
    {
        hy_sack_free(pTdnf->hSack);
        pTdnf->hSack = NULL;
    }

    //init with cache
    dwError = TDNFInitSack(pTdnf, &hSack, HY_LOAD_FILELISTS);
    BAIL_ON_TDNF_ERROR(dwError);

    //Do the same for all enabled repos
    if(pTdnf->pRepos)
    {
        PTDNF_REPO_DATA pRepo = pTdnf->pRepos;
        while(pRepo)
        {
            if(pRepo->nEnabled)
            {
                hy_repo_free(pRepo->hRepo);
                pRepo->hRepo = NULL;

                dwError = TDNFInitRepo(pTdnf, pRepo, &pRepo->hRepo);
                BAIL_ON_TDNF_ERROR(dwError);
            }
            pRepo = pRepo->pNext;
        }
    }

    pTdnf->hSack = hSack;

cleanup:
    return dwError;

error:
    if(hSack)
    {
        hy_sack_free(hSack);
    }
    if(pTdnf->hSack)
    {
        hy_sack_free(pTdnf->hSack);
        pTdnf->hSack = NULL;
    }
    goto cleanup;
}
Пример #28
0
uint32_t
TDNFTransAddDowngradePkgs(
    PTDNFRPMTS pTS,
    PTDNF pTdnf
    )
{
    uint32_t dwError = 0;
    int i = 0;
    HyPackage hPkg = NULL;
    HyPackageList hPkgList = NULL;
    HyPackage hInstalledPkg = NULL;

    hPkgList = hy_goal_list_downgrades(pTdnf->hGoal);
    if(!hPkgList)
    {
        dwError = ERROR_TDNF_NO_DATA;
        BAIL_ON_TDNF_ERROR(dwError);
    }
    for(i = 0; (hPkg = hy_packagelist_get(hPkgList, i)) != NULL; ++i)
    {
        dwError = TDNFTransAddInstallPkg(pTS, pTdnf, hPkg, 0);
        BAIL_ON_TDNF_ERROR(dwError);

        //Downgrade is a removal of existing and installing old.
        const char* pszName = NULL;
        pszName = hy_package_get_name(hPkg);
        if(IsNullOrEmptyString(pszName))
        {
            dwError = hy_get_errno();
            if(dwError == 0)
            {
                dwError = HY_E_FAILED;
            }
            BAIL_ON_TDNF_HAWKEY_ERROR(dwError);
        }
        dwError = TDNFFindInstalledPkgByName(pTdnf->hSack, pszName, &hInstalledPkg);
        BAIL_ON_TDNF_ERROR(dwError);

        dwError = TDNFTransAddErasePkg(pTS, hInstalledPkg);
        BAIL_ON_TDNF_ERROR(dwError);

        hy_package_free(hInstalledPkg);
        hInstalledPkg = NULL;
    }

cleanup:
    if(hInstalledPkg)
    {
        hy_package_free(hInstalledPkg);
    }
    if(hPkgList)
    {
        hy_packagelist_free(hPkgList);
    }
    return dwError;

error:
    if(dwError == ERROR_TDNF_NO_DATA)
    {
        dwError = 0;
    }
    goto cleanup;
}
Пример #29
0
uint32_t
TDNFDownloadPackage(
    PTDNF pTdnf,
    HyPackage hPkg,
    const char* pszRpmCacheDir
    )
{
    uint32_t dwError = 0;
    LrHandle *pRepoHandle = NULL;
    GError* pError = NULL;
    gboolean bRet = FALSE;
    char* ppszUrls[] = {NULL, NULL};
    const char* pszPackage = NULL;
    const char* pszRepo = NULL;
    char* pszUserPass = NULL;
    
    if(!pTdnf || !hPkg || IsNullOrEmptyString(pszRpmCacheDir))
    {
        dwError = ERROR_TDNF_INVALID_PARAMETER;
        BAIL_ON_TDNF_ERROR(dwError);
    }

    pRepoHandle = lr_handle_init();

    if(!pRepoHandle)
    {
        //TODO: Add repo specific
        dwError = ERROR_TDNF_INVALID_PARAMETER;
        BAIL_ON_TDNF_ERROR(dwError);
    }

    //Get package details
    pszPackage = hy_package_get_location(hPkg);
    pszRepo = hy_package_get_reponame(hPkg);

    dwError = TDNFRepoGetBaseUrl(pTdnf, pszRepo, &ppszUrls[0]);
    BAIL_ON_TDNF_ERROR(dwError);

    lr_handle_setopt(pRepoHandle, NULL, LRO_URLS, ppszUrls);
    lr_handle_setopt(pRepoHandle, NULL, LRO_REPOTYPE, LR_YUMREPO);
    lr_handle_setopt(pRepoHandle, NULL, LRO_SSLVERIFYPEER, 1);
    lr_handle_setopt(pRepoHandle, NULL, LRO_SSLVERIFYHOST, 2);

    dwError = TDNFRepoGetUserPass(pTdnf, pszRepo, &pszUserPass);
    BAIL_ON_TDNF_ERROR(dwError);

    if(!IsNullOrEmptyString(pszUserPass))
    {
        lr_handle_setopt(pRepoHandle, NULL, LRO_USERPWD, pszUserPass);
    }
    bRet = lr_handle_setopt(pRepoHandle, NULL, LRO_PROGRESSCB, lrProgressCB);
    if(bRet == FALSE)
    {
        //TODO: Add repo specific
        dwError = ERROR_TDNF_INVALID_PARAMETER;
        BAIL_ON_TDNF_ERROR(dwError);
    }
    bRet = lr_download_package (
                         pRepoHandle,
                         pszPackage,
                         pszRpmCacheDir,
                         LR_CHECKSUM_UNKNOWN,
                         NULL,
                         0, 
                         NULL, 
                         TRUE,
                         &pError);

    if(bRet == FALSE)
    {
        dwError = ERROR_TDNF_INVALID_PARAMETER;
        BAIL_ON_TDNF_ERROR(dwError);
    }
    fprintf(stdout, "\n");
cleanup:
    if(pRepoHandle)
    {
        lr_handle_free(pRepoHandle);
    }
    return dwError;

error:
    if(pError)
    {
        fprintf(
            stderr,
            "Error during download: %d: %s\n",
            pError->code,
            pError->message
            );
        g_error_free(pError);
    }
    goto cleanup;
}
Пример #30
0
//Download repo metadata and initialize
uint32_t
TDNFInitRepo(
    PTDNF pTdnf,
    PTDNF_REPO_DATA pRepoData,
    HyRepo* phRepo
    )
{
    uint32_t dwError = 0;
    gboolean bRet = 0;
    LrHandle* hLibRepo = NULL;
    LrResult* pResult = NULL;
    LrYumRepo* pRepo = NULL;
    int nLocalOnly = 0;
    char* pszRepoCacheDir = NULL;
    char* pszRepoDataDir = NULL;
    char* pszUserPass = NULL;

    char* ppszRepoUrls[] = {NULL, NULL};
    char* ppszLocalUrls[] = {NULL, NULL};
    char* ppszDownloadList[] = {"primary", "filelists", "updateinfo", NULL};
    PTDNF_CONF pConf = NULL;

    HyRepo hRepo = NULL;

    if(!pTdnf || !pTdnf->pConf || !pRepoData || !phRepo)
    {
        dwError = ERROR_TDNF_INVALID_PARAMETER;
        BAIL_ON_TDNF_ERROR(dwError);
    }

    pConf = pTdnf->pConf;

    pszRepoCacheDir = g_build_path(
                           G_DIR_SEPARATOR_S,
                           pConf->pszCacheDir,
                           pRepoData->pszId,
                           NULL);
    if(!pszRepoCacheDir)
    {
        dwError = ERROR_TDNF_INVALID_PARAMETER;
        BAIL_ON_TDNF_ERROR(dwError);
    }

    pszRepoDataDir = g_build_path(
                           G_DIR_SEPARATOR_S,
                           pszRepoCacheDir,
                           TDNF_REPODATA_DIR_NAME,
                           NULL);
    if(!pszRepoDataDir)
    {
        dwError = ERROR_TDNF_INVALID_PARAMETER;
        BAIL_ON_TDNF_ERROR(dwError);
    }

    ppszRepoUrls[0] = pRepoData->pszBaseUrl;
    ppszLocalUrls[0] = pszRepoCacheDir;

    hLibRepo = lr_handle_init();
    if(!hLibRepo)
    {
        dwError = ERROR_TDNF_INVALID_PARAMETER;
        BAIL_ON_TDNF_ERROR(dwError);
    }

    pResult = lr_result_init();
    if(!pResult)
    {
        dwError = ERROR_TDNF_INVALID_PARAMETER;
        BAIL_ON_TDNF_ERROR(dwError);
    }

    //Look for repodata dir - this is auto created
    //during last refresh so skip download if present
    if(!access(pszRepoDataDir, F_OK))
    {
        nLocalOnly = 1;
        lr_handle_setopt(hLibRepo, NULL, LRO_URLS, ppszLocalUrls);
        lr_handle_setopt(hLibRepo, NULL, LRO_IGNOREMISSING, 1);
    }
    else
    {
        //Look for the repo root cache dir. If not there,
        //try to create and download into it.
        if(access(pszRepoCacheDir, F_OK))
        {
            if(errno != ENOENT)
            {
                dwError = errno;
            }
            BAIL_ON_TDNF_SYSTEM_ERROR(dwError);

            if(mkdir(pszRepoCacheDir, 755))
            {
                dwError = errno;
                BAIL_ON_TDNF_SYSTEM_ERROR(dwError);
            }
        }

        lr_handle_setopt(hLibRepo, NULL, LRO_URLS, ppszRepoUrls);
        lr_handle_setopt(hLibRepo, NULL, LRO_SSLVERIFYPEER, 1);
        lr_handle_setopt(hLibRepo, NULL, LRO_SSLVERIFYHOST, 2);
        lr_handle_setopt(hLibRepo, NULL, LRO_DESTDIR, pszRepoCacheDir);
        lr_handle_setopt(hLibRepo, NULL, LRO_YUMDLIST, ppszDownloadList);
        if(!IsNullOrEmptyString(pRepoData->pszUser) && 
           !IsNullOrEmptyString(pRepoData->pszPass))
        {
            dwError = TDNFAllocateStringPrintf(
                          &pszUserPass,
                          "%s:%s",
                          pRepoData->pszUser,
                          pRepoData->pszPass);
            BAIL_ON_TDNF_ERROR(dwError);
            lr_handle_setopt(
                hLibRepo,
                NULL,
                LRO_USERPWD,
                pszUserPass);
        }
    }

    lr_handle_setopt(hLibRepo, NULL, LRO_REPOTYPE, LR_YUMREPO);
    lr_handle_setopt(hLibRepo, NULL, LRO_LOCAL, nLocalOnly);

    
    bRet = lr_handle_perform(hLibRepo, pResult, NULL);
    if(!bRet)
    {
        dwError = ERROR_TDNF_REPO_PERFORM;
        BAIL_ON_TDNF_ERROR(dwError);
    }

    bRet = lr_result_getinfo(pResult, NULL, LRR_YUM_REPO, &pRepo);
    if(!bRet)
    {
        dwError = ERROR_TDNF_REPO_GETINFO;
        BAIL_ON_TDNF_ERROR(dwError);
    }

    //Create and set repo properties   
    hRepo = hy_repo_create(pRepoData->pszId);
    if(!hRepo)
    {
        dwError = ERROR_TDNF_HAWKEY_FAILED;
        BAIL_ON_TDNF_ERROR(dwError);
    }

    dwError = TDNFInitRepoFromMetaData(hRepo, pRepo);
    BAIL_ON_TDNF_ERROR(dwError);

    *phRepo = hRepo;
cleanup:
    if(pszRepoDataDir)
    {
        g_free(pszRepoDataDir);
    }
    if(pszRepoCacheDir)
    {
        g_free(pszRepoCacheDir);
    }

    if(pResult)
    {
        lr_result_free(pResult);
    }
    if(hLibRepo)
    {
        lr_handle_free(hLibRepo);
    }
    return dwError;

error:
    //If there is an error during init, log the error
    //remove any cache data that could be potentially corrupt.
    if(pRepoData)
    {
        fprintf(
            stderr,
            "Error: Failed to synchronize cache for repo '%s' from '%s'\n",
            pRepoData->pszName,
            pRepoData->pszBaseUrl);

        if(pTdnf)
        {
            TDNFRepoRemoveCache(pTdnf, pRepoData->pszId);
        }
    }
    if(phRepo)
    {
        *phRepo = NULL;
    }
    if(hRepo)
    {
       hy_repo_free(hRepo);
    }
    goto cleanup;
}