From 1e7702350d52b1fc4085799b5ea22b0b123163c2 Mon Sep 17 00:00:00 2001 From: Oliver Kurth Date: Fri, 7 Oct 2022 17:10:38 -0700 Subject: [PATCH] remove packages from dir for --installtodir option --- client/goal.c | 31 +++++++++++-------------------- client/prototypes.h | 15 +++++---------- client/rpmtrans.c | 33 ++++++++++++++++++++++++++++++++- common/utils.c | 1 + include/tdnftypes.h | 1 + solv/tdnfpackage.c | 2 +- 6 files changed, 51 insertions(+), 32 deletions(-) diff --git a/client/goal.c b/client/goal.c index f1fb2447..43d4c62d 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/prototypes.h b/client/prototypes.h index c15a9df3..2278b3bd 100644 --- a/client/prototypes.h +++ b/client/prototypes.h @@ -483,10 +483,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( @@ -502,14 +505,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 7e78b4fa..e2597d7e 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 2fef6963..c2661111 100644 --- a/common/utils.c +++ b/common/utils.c @@ -281,6 +281,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 c02d6465..02103799 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; diff --git a/solv/tdnfpackage.c b/solv/tdnfpackage.c index cfa66e14..aebde3ff 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;