CBL-Mariner/SPECS/tdnf/tdnf-add-download-no-deps-c...

366 lines
9.7 KiB
Diff

From f37784ca2b1656f74310215759d7f9cb7803c5a0 Mon Sep 17 00:00:00 2001
From: Joe Schmitt <joschmit@microsoft.com>
Date: Tue, 28 Jul 2020 15:49:55 -0700
Subject: [PATCH] Add download-nodeps command
---
client/api.c | 142 +++++++++++++++++++++++++++++++++++++++++
client/packageutils.c | 6 ++
include/tdnfcli.h | 6 ++
include/tdnfclitypes.h | 9 +++
tools/cli/lib/api.c | 49 ++++++++++++++
tools/cli/lib/help.c | 1 +
tools/cli/main.c | 18 ++++++
tools/cli/prototypes.h | 8 +++
8 files changed, 239 insertions(+)
diff --git a/client/api.c b/client/api.c
index 002fe88..d3ecf9d 100644
--- a/client/api.c
+++ b/client/api.c
@@ -484,6 +484,148 @@ error:
goto cleanup;
}
+//Downloads all requested packages without any of their dependencies.
+uint32_t
+TDNFDownloadNoDepsCommand(
+ PTDNF pTdnf,
+ TDNF_SCOPE nScope,
+ char** ppszPackageNameSpecs,
+ PTDNF_PKG_INFO* ppPkgInfo,
+ uint32_t* pdwCount
+ )
+{
+ const int nSkipInstalledRpms = 1;
+ const int nUpgrade = 0;
+
+ uint32_t dwError = 0;
+ uint32_t dwCount = 0;
+ uint32_t dwIndex = 0;
+
+ PSolvQuery pQuery = NULL;
+ PTDNF_PKG_INFO pPkgInfo = NULL;
+ PTDNF_PKG_INFO pPkg = NULL;
+ PSolvPackageList pPkgList = NULL;
+
+ TDNFRPMTS ts = {0};
+
+ if(!pTdnf || !pTdnf->pSack ||!pdwCount || !ppPkgInfo ||
+ !ppszPackageNameSpecs || IsNullOrEmptyString(pTdnf->pArgs->pszDestDir))
+ {
+ dwError = ERROR_TDNF_INVALID_PARAMETER;
+ BAIL_ON_TDNF_ERROR(dwError);
+ }
+
+ dwError = TDNFResetSack(pTdnf, nSkipInstalledRpms);
+ BAIL_ON_TDNF_ERROR(dwError);
+
+ dwError = SolvCreateQuery(pTdnf->pSack, &pQuery);
+ BAIL_ON_TDNF_ERROR(dwError);
+
+ dwError = TDNFApplyScopeFilter(pQuery, nScope);
+ BAIL_ON_TDNF_ERROR(dwError);
+
+ dwError = SolvApplyPackageFilter(pQuery, ppszPackageNameSpecs);
+ BAIL_ON_TDNF_ERROR(dwError);
+
+ dwError = SolvApplyListQuery(pQuery);
+ BAIL_ON_TDNF_ERROR(dwError);
+
+ dwError = SolvGetQueryResult(pQuery, &pPkgList);
+ BAIL_ON_TDNF_ERROR(dwError);
+
+ dwError = TDNFPopulatePkgInfoArray(
+ pTdnf->pSack,
+ pPkgList,
+ DETAIL_INFO,
+ &pPkgInfo,
+ &dwCount);
+ BAIL_ON_TDNF_ERROR(dwError);
+
+ if(dwError == ERROR_TDNF_NO_MATCH && !*ppszPackageNameSpecs)
+ {
+ dwError = 0;
+ }
+
+ *ppPkgInfo = pPkgInfo;
+ *pdwCount = dwCount;
+
+ ts.nQuiet = pTdnf->pArgs->nQuiet;
+
+ ts.pTS = rpmtsCreate();
+ if(!ts.pTS)
+ {
+ dwError = ERROR_TDNF_RPMTS_CREATE_FAILED;
+ BAIL_ON_TDNF_ERROR(dwError);
+ }
+
+ ts.nTransFlags = rpmtsSetFlags (ts.pTS, RPMTRANS_FLAG_NONE);
+
+ if(rpmtsSetNotifyCallback(ts.pTS, TDNFRpmCB, (void*)&ts))
+ {
+ dwError = ERROR_TDNF_RPMTS_SET_CB_FAILED;
+ BAIL_ON_TDNF_ERROR(dwError);
+ }
+
+ ts.pKeyring = rpmKeyringNew();
+ if(!ts.pKeyring)
+ {
+ dwError = ERROR_TDNF_RPMTS_KEYRING_FAILED;
+ BAIL_ON_TDNF_ERROR(dwError);
+ }
+
+ for(dwIndex = 0; dwIndex < dwCount; ++dwIndex)
+ {
+ pPkg = &pPkgInfo[dwIndex];
+
+ dwError = TDNFTransAddInstallPkg(
+ &ts,
+ pTdnf,
+ pPkg->pszLocation,
+ pPkg->pszName,
+ pPkg->pszRepoName,
+ nUpgrade);
+ BAIL_ON_TDNF_ERROR(dwError);
+ rpmtsEmpty(ts.pTS);
+ }
+
+cleanup:
+ if(pQuery)
+ {
+ SolvFreeQuery(pQuery);
+ }
+ if(pPkgList)
+ {
+ SolvFreePackageList(pPkgList);
+ }
+ if(ts.pTS)
+ {
+ rpmtsCloseDB(ts.pTS);
+ rpmtsFree(ts.pTS);
+ }
+ if(ts.pKeyring)
+ {
+ rpmKeyringFree(ts.pKeyring);
+ }
+
+ return dwError;
+
+error:
+ if(ppPkgInfo)
+ {
+ *ppPkgInfo = NULL;
+ }
+ if(pdwCount)
+ {
+ *pdwCount = 0;
+ }
+ if(pPkgInfo)
+ {
+ TDNFFreePackageInfoArray(pPkgInfo, dwCount);
+ }
+ goto cleanup;
+}
+
+
//Lists info on each installed package
//Returns a sum of installed size
uint32_t
diff --git a/client/packageutils.c b/client/packageutils.c
index 66aca2a..053d610 100644
--- a/client/packageutils.c
+++ b/client/packageutils.c
@@ -182,6 +182,12 @@ TDNFPopulatePkgInfoArray(
dwPkgId,
&pPkgInfo->pszDescription);
BAIL_ON_TDNF_ERROR(dwError);
+
+ dwError = SolvGetPkgLocationFromId(
+ pSack,
+ dwPkgId,
+ &pPkgInfo->pszLocation);
+ BAIL_ON_TDNF_ERROR(dwError);
}
}
diff --git a/include/tdnfcli.h b/include/tdnfcli.h
index 0afea1c..be17ac6 100644
--- a/include/tdnfcli.h
+++ b/include/tdnfcli.h
@@ -148,6 +148,12 @@ TDNFCliDownloadCommand(
PTDNF_CMD_ARGS pCmdArgs
);
+uint32_t
+TDNFCliDownloadNoDepsCommand(
+ PTDNF_CLI_CONTEXT pContext,
+ PTDNF_CMD_ARGS pCmdArgs
+ );
+
uint32_t
TDNFCliSearchCommand(
PTDNF_CLI_CONTEXT pContext,
diff --git a/include/tdnfclitypes.h b/include/tdnfclitypes.h
index 11f76ea..3ec8943 100644
--- a/include/tdnfclitypes.h
+++ b/include/tdnfclitypes.h
@@ -138,6 +138,14 @@ typedef uint32_t
PTDNF_UPDATEINFO_ARGS,
PTDNF_UPDATEINFO_SUMMARY *);
+typedef uint32_t
+(*PFN_TDNF_DOWNLOAD_NO_DEPS)(
+ PTDNF_CLI_CONTEXT,
+ PTDNF_LIST_ARGS,
+ PTDNF_PKG_INFO *,
+ uint32_t *
+ );
+
typedef struct _TDNF_CLI_CONTEXT_
{
HTDNF hTdnf;
@@ -158,6 +166,7 @@ typedef struct _TDNF_CLI_CONTEXT_
PFN_TDNF_SEARCH pFnSearch;
PFN_TDNF_UPDATEINFO pFnUpdateInfo;
PFN_TDNF_UPDATEINFO_SUMMARY pFnUpdateInfoSummary;
+ PFN_TDNF_DOWNLOAD_NO_DEPS pFnDownloadNoDeps;
}TDNF_CLI_CONTEXT, *PTDNF_CLI_CONTEXT;
#ifdef __cplusplus
diff --git a/tools/cli/lib/api.c b/tools/cli/lib/api.c
index cb9b160..3605bf6 100644
--- a/tools/cli/lib/api.c
+++ b/tools/cli/lib/api.c
@@ -292,6 +292,55 @@ error:
goto cleanup;
}
+uint32_t
+TDNFCliDownloadNoDepsCommand(
+ PTDNF_CLI_CONTEXT pContext,
+ PTDNF_CMD_ARGS pCmdArgs
+ )
+{
+ uint32_t dwError = 0;
+
+ PTDNF_PKG_INFO pPkgInfo = NULL;
+ PTDNF_PKG_INFO pPkg = NULL;
+ PTDNF_LIST_ARGS pInfoArgs = NULL;
+
+ uint32_t dwCount = 0;
+ uint32_t dwIndex = 0;
+ uint64_t dwTotalSize = 0;
+
+ if(!pContext ||
+ !pContext->hTdnf ||
+ !pContext->pFnDownloadNoDeps ||
+ !pCmdArgs ||
+ IsNullOrEmptyString(pCmdArgs->pszDestDir))
+ {
+ dwError = ERROR_TDNF_INVALID_PARAMETER;
+ BAIL_ON_CLI_ERROR(dwError);
+ }
+
+ dwError = TDNFCliParseInfoArgs(pCmdArgs, &pInfoArgs);
+ BAIL_ON_CLI_ERROR(dwError);
+
+ dwError = pContext->pFnDownloadNoDeps(pContext, pInfoArgs, &pPkgInfo, &dwCount);
+ BAIL_ON_CLI_ERROR(dwError);
+
+ printf("Download %d packages\n", dwCount);
+
+cleanup:
+ if(pInfoArgs)
+ {
+ TDNFCliFreeListArgs(pInfoArgs);
+ }
+ if(pPkgInfo)
+ {
+ TDNFFreePackageInfoArray(pPkgInfo, dwCount);
+ }
+ return dwError;
+
+error:
+ goto cleanup;
+}
+
uint32_t
TDNFCliInfoCommand(
PTDNF_CLI_CONTEXT pContext,
diff --git a/tools/cli/lib/help.c b/tools/cli/lib/help.c
index d9fbfd6..1e72d4b 100644
--- a/tools/cli/lib/help.c
+++ b/tools/cli/lib/help.c
@@ -67,6 +67,7 @@ TDNFCliShowHelp(
printf("clean Remove cached data\n");
printf("distro-sync Synchronize installed packages to the latest available versions\n");
printf("download download a package\n");
+ printf("download-nodeps download a package without dependencies\n");
printf("downgrade downgrade a package\n");
printf("erase Remove a package or packages from your system\n");
printf("help Display a helpful usage message\n");
diff --git a/tools/cli/main.c b/tools/cli/main.c
index d638640..4a15689 100644
--- a/tools/cli/main.c
+++ b/tools/cli/main.c
@@ -40,6 +40,7 @@ int main(int argc, char* argv[])
{"distro-sync", TDNFCliDistroSyncCommand},
{"downgrade", TDNFCliDowngradeCommand},
{"download", TDNFCliDownloadCommand},
+ {"download-nodeps", TDNFCliDownloadNoDepsCommand},
{"erase", TDNFCliEraseCommand},
{"help", TDNFCliHelpCommand},
{"info", TDNFCliInfoCommand},
@@ -90,6 +91,7 @@ int main(int argc, char* argv[])
_context.pFnSearch = TDNFCliInvokeSearch;
_context.pFnUpdateInfo = TDNFCliInvokeUpdateInfo;
_context.pFnUpdateInfoSummary = TDNFCliInvokeUpdateInfoSummary;
+ _context.pFnDownloadNoDeps = TDNFCliInvokeDownloadNoDeps;
dwError = TDNFCliParseArgs(argc, argv, &pCmdArgs);
BAIL_ON_CLI_ERROR(dwError);
@@ -422,3 +424,19 @@ TDNFCliInvokeUpdateInfoSummary(
pInfoArgs->ppszPackageNameSpecs,
ppSummary);
}
+
+
+uint32_t
+TDNFCliInvokeDownloadNoDeps(
+ PTDNF_CLI_CONTEXT pContext,
+ PTDNF_LIST_ARGS pInfoArgs,
+ PTDNF_PKG_INFO *ppPkgInfo,
+ uint32_t *pdwCount
+ )
+{
+ return TDNFDownloadNoDepsCommand(pContext->hTdnf,
+ pInfoArgs->nScope,
+ pInfoArgs->ppszPackageNameSpecs,
+ ppPkgInfo,
+ pdwCount);
+}
\ No newline at end of file
diff --git a/tools/cli/prototypes.h b/tools/cli/prototypes.h
index 053f4a7..6798fcb 100644
--- a/tools/cli/prototypes.h
+++ b/tools/cli/prototypes.h
@@ -168,6 +168,14 @@ TDNFCliInvokeUpdateInfoSummary(
PTDNF_UPDATEINFO_SUMMARY *ppSummary
);
+uint32_t
+TDNFCliInvokeDownloadNoDeps(
+ PTDNF_CLI_CONTEXT pContext,
+ PTDNF_LIST_ARGS pInfoArgs,
+ PTDNF_PKG_INFO *ppPkgInfo,
+ uint32_t *pdwCount
+ );
+
//main.c
void
TDNFCliShowVersion(
--
2.17.1