Skip to content

Commit

Permalink
remove packages from dir for --installtodir option
Browse files Browse the repository at this point in the history
  • Loading branch information
oliverkurth committed May 23, 2023
1 parent 851c3f9 commit 1e77023
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 32 deletions.
31 changes: 11 additions & 20 deletions client/goal.c
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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;
Expand All @@ -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)
Expand Down Expand Up @@ -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(
Expand Down
15 changes: 5 additions & 10 deletions client/prototypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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,
Expand Down
33 changes: 32 additions & 1 deletion client/rpmtrans.c
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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;
}
Expand Down
1 change: 1 addition & 0 deletions common/utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
1 change: 1 addition & 0 deletions include/tdnftypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion solv/tdnfpackage.c
Original file line number Diff line number Diff line change
Expand Up @@ -792,7 +792,7 @@ SolvGetPkgLocationFromId(
}
if(ppszLocation)
{
ppszLocation = NULL;
*ppszLocation = NULL;
}
TDNF_SAFE_FREE_MEMORY(pszLocation);
goto cleanup;
Expand Down

0 comments on commit 1e77023

Please sign in to comment.