diff --git a/client/api.c b/client/api.c index 85517357..3860ed5e 100644 --- a/client/api.c +++ b/client/api.c @@ -700,10 +700,18 @@ TDNFOpenHandle( pTdnf->pArgs->pszInstallRoot); BAIL_ON_TDNF_ERROR(dwError); - if(!pArgs->nAllDeps) - { + if(!pArgs->nAllDeps) { dwError = SolvReadInstalledRpms(pSack->pPool->installed, pszCacheDir); BAIL_ON_TDNF_LIBSOLV_ERROR(dwError); + } else if (pArgs->nInstallToDir) { + if (pArgs->nDownloadOnly && !IsNullOrEmptyString(pArgs->pszDownloadDir)) { + dwError = SolvReadRpmsFromDirectory(pSack->pPool->installed, pArgs->pszDownloadDir); + BAIL_ON_TDNF_ERROR(dwError); + } else { + pr_err("--installtodir requires --downloadonly and --downloaddir"); + dwError = ERROR_TDNF_INVALID_PARAMETER; + BAIL_ON_TDNF_ERROR(dwError); + } } dwError = TDNFLoadRepoData( diff --git a/client/goal.c b/client/goal.c index ae5725bd..2e5ac3eb 100644 --- a/client/goal.c +++ b/client/goal.c @@ -106,19 +106,6 @@ TDNFGetReinstallPackages( SOLVER_TRANSACTION_REINSTALL); } -uint32_t -TDNFGetUpgradePackages( - Transaction* pTrans, - PTDNF pTdnf, - PTDNF_PKG_INFO* pPkgInfo) -{ - return TDNFGetPackagesWithSpecifiedType( - pTrans, - pTdnf, - pPkgInfo, - SOLVER_TRANSACTION_UPGRADE); -} - uint32_t TDNFGetErasePackages( Transaction* pTrans, @@ -146,11 +133,12 @@ TDNFGetObsoletedPackages( } uint32_t -TDNFGetDownGradePackages( +TDNFGetUpDowngradePackages( Transaction* pTrans, PTDNF pTdnf, PTDNF_PKG_INFO* pPkgInfo, - PTDNF_PKG_INFO* pRemovePkgInfo) + PTDNF_PKG_INFO* pRemovePkgInfo, + int nIsUpgrade) { uint32_t dwError = 0; PSolvPackageList pInstalledPkgList = NULL; @@ -170,7 +158,7 @@ TDNFGetDownGradePackages( pTrans, pTdnf, pPkgInfo, - SOLVER_TRANSACTION_DOWNGRADE); + nIsUpgrade ? SOLVER_TRANSACTION_UPGRADE : SOLVER_TRANSACTION_DOWNGRADE); BAIL_ON_TDNF_ERROR(dwError); pInfo = *pPkgInfo; if(!pInfo) @@ -869,17 +857,20 @@ TDNFGoalGetAllResultsIgnoreNoData( &pInfo->pPkgsToInstall); BAIL_ON_TDNF_ERROR(dwError); - dwError = TDNFGetUpgradePackages( + dwError = TDNFGetUpDowngradePackages( pTrans, pTdnf, - &pInfo->pPkgsToUpgrade); + &pInfo->pPkgsToUpgrade, + &pInfo->pPkgsRemovedByUpgrade, + 1); BAIL_ON_TDNF_ERROR(dwError); - dwError = TDNFGetDownGradePackages( + dwError = TDNFGetUpDowngradePackages( pTrans, pTdnf, &pInfo->pPkgsToDowngrade, - &pInfo->pPkgsRemovedByDowngrade); + &pInfo->pPkgsRemovedByDowngrade, + 0); BAIL_ON_TDNF_ERROR(dwError); dwError = TDNFGetErasePackages( diff --git a/client/init.c b/client/init.c index 7053e9ca..d0acc9ef 100644 --- a/client/init.c +++ b/client/init.c @@ -64,6 +64,7 @@ TDNFCloneCmdArgs( pCmdArgs->nSkipBroken = pCmdArgsIn->nSkipBroken; pCmdArgs->nSource = pCmdArgsIn->nSource; pCmdArgs->nBuildDeps = pCmdArgsIn->nBuildDeps; + pCmdArgs->nInstallToDir = pCmdArgsIn->nInstallToDir; pCmdArgs->nArgc = pCmdArgsIn->nArgc; pCmdArgs->ppszArgv = pCmdArgsIn->ppszArgv; diff --git a/client/prototypes.h b/client/prototypes.h index 4e52f3ab..c555035c 100644 --- a/client/prototypes.h +++ b/client/prototypes.h @@ -491,10 +491,13 @@ TDNFGetReinstallPackages( ); uint32_t -TDNFGetUpgradePackages( +TDNFGetUpDowngradePackages( Transaction* pTrans, PTDNF pTdnf, - PTDNF_PKG_INFO* pPkgInfo); + PTDNF_PKG_INFO* pPkgInfo, + PTDNF_PKG_INFO* pRemovePkgInfo, + int nIsUpgrade +); uint32_t TDNFGetErasePackages( @@ -510,14 +513,6 @@ TDNFGetObsoletedPackages( PTDNF_PKG_INFO* pPkgInfo ); -uint32_t -TDNFGetDownGradePackages( - Transaction* pTrans, - PTDNF pTdnf, - PTDNF_PKG_INFO* pPkgInfo, - PTDNF_PKG_INFO* pRemovePkgInfo - ); - uint32_t TDNFPkgsToExclude( PTDNF pTdnf, diff --git a/client/rpmtrans.c b/client/rpmtrans.c index f5d122ed..8752669c 100644 --- a/client/rpmtrans.c +++ b/client/rpmtrans.c @@ -365,6 +365,29 @@ TDNFRpmExecHistoryTransaction( goto cleanup; } +static +uint32_t +TDNFDeletePackages(PTDNF_PKG_INFO pInfoList) +{ + uint32_t dwError = 0; + PTDNF_PKG_INFO pInfo = NULL; + + for (pInfo = pInfoList; + pInfo; + pInfo = pInfo->pNext) { + if (pInfo->pszLocation) { + if(unlink(pInfo->pszLocation)) { + dwError = errno; + BAIL_ON_TDNF_SYSTEM_ERROR(dwError); + } + } + } +cleanup: + return dwError; +error: + goto cleanup; +} + uint32_t TDNFPopulateTransaction( PTDNFRPMTS pTS, @@ -430,9 +453,17 @@ TDNFPopulateTransaction( } } + if (pTdnf->pArgs->nInstallToDir) { + dwError = TDNFDeletePackages(pSolvedInfo->pPkgsRemovedByUpgrade); + BAIL_ON_TDNF_ERROR(dwError); + dwError = TDNFDeletePackages(pSolvedInfo->pPkgsRemovedByDowngrade); + BAIL_ON_TDNF_ERROR(dwError); + dwError = TDNFDeletePackages(pSolvedInfo->pPkgsObsoleted); + BAIL_ON_TDNF_ERROR(dwError); + } + cleanup: return dwError; - error: goto cleanup; } diff --git a/common/utils.c b/common/utils.c index 46595541..bc00406c 100644 --- a/common/utils.c +++ b/common/utils.c @@ -291,6 +291,7 @@ TDNFFreeSolvedPackageInfo( TDNF_SAFE_FREE_PKGINFO(pSolvedPkgInfo->pPkgsToReinstall); TDNF_SAFE_FREE_PKGINFO(pSolvedPkgInfo->pPkgsObsoleted); TDNF_SAFE_FREE_PKGINFO(pSolvedPkgInfo->pPkgsRemovedByDowngrade); + TDNF_SAFE_FREE_PKGINFO(pSolvedPkgInfo->pPkgsRemovedByUpgrade); TDNF_SAFE_FREE_STRINGARRAY(pSolvedPkgInfo->ppszPkgsNotResolved); TDNF_SAFE_FREE_STRINGARRAY(pSolvedPkgInfo->ppszPkgsUserInstall); diff --git a/include/tdnftypes.h b/include/tdnftypes.h index 9a45b00c..77e8bd5c 100644 --- a/include/tdnftypes.h +++ b/include/tdnftypes.h @@ -187,6 +187,7 @@ typedef struct _TDNF_SOLVED_PKG_INFO PTDNF_PKG_INFO pPkgsUnNeeded; PTDNF_PKG_INFO pPkgsToReinstall; PTDNF_PKG_INFO pPkgsObsoleted; + PTDNF_PKG_INFO pPkgsRemovedByUpgrade; PTDNF_PKG_INFO pPkgsRemovedByDowngrade; char** ppszPkgsNotResolved; char** ppszPkgsUserInstall; @@ -231,6 +232,7 @@ typedef struct _TDNF_CMD_ARGS int nSkipBroken; int nSource; int nBuildDeps; + int nInstallToDir; char* pszDownloadDir; //directory for download, if nDownloadOnly is set char* pszInstallRoot; //set install root char* pszConfFile; //set conf file location diff --git a/solv/tdnfpackage.c b/solv/tdnfpackage.c index e5d95133..060a5d1b 100644 --- a/solv/tdnfpackage.c +++ b/solv/tdnfpackage.c @@ -792,7 +792,7 @@ SolvGetPkgLocationFromId( } if(ppszLocation) { - ppszLocation = NULL; + *ppszLocation = NULL; } TDNF_SAFE_FREE_MEMORY(pszLocation); goto cleanup; diff --git a/tools/cli/lib/parseargs.c b/tools/cli/lib/parseargs.c index 9029c1bc..eb765586 100644 --- a/tools/cli/lib/parseargs.c +++ b/tools/cli/lib/parseargs.c @@ -47,6 +47,7 @@ static struct option pstOptions[] = {"exclude", required_argument, 0, 0}, //--exclude {"help", no_argument, 0, 'h'}, //-h --help {"installroot", required_argument, 0, 'i'}, //--installroot + {"installtodir", no_argument, &_opt.nInstallToDir, 1}, {"json", no_argument, &_opt.nJsonOutput, 1}, {"noautoremove", no_argument, &_opt.nNoAutoRemove, 1}, {"nodeps", no_argument, &_opt.nNoDeps, 1}, @@ -355,6 +356,7 @@ TDNFCopyOptions( pArgs->nSkipBroken = pOptionArgs->nSkipBroken; pArgs->nSource = pOptionArgs->nSource; pArgs->nBuildDeps = pOptionArgs->nBuildDeps; + pArgs->nInstallToDir = pOptionArgs->nInstallToDir; cleanup: return dwError;