Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

implement --installtodir option #427

Open
wants to merge 2 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions client/api.c
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
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
1 change: 1 addition & 0 deletions client/init.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
15 changes: 5 additions & 10 deletions client/prototypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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,
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 @@ -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);
Expand Down
2 changes: 2 additions & 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 Expand Up @@ -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
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
2 changes: 2 additions & 0 deletions tools/cli/lib/parseargs.c
Original file line number Diff line number Diff line change
Expand Up @@ -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},
Expand Down Expand Up @@ -355,6 +356,7 @@ TDNFCopyOptions(
pArgs->nSkipBroken = pOptionArgs->nSkipBroken;
pArgs->nSource = pOptionArgs->nSource;
pArgs->nBuildDeps = pOptionArgs->nBuildDeps;
pArgs->nInstallToDir = pOptionArgs->nInstallToDir;

cleanup:
return dwError;
Expand Down