From c39db3bab69eb6ea6d10a481ab491aaec6bd9039 Mon Sep 17 00:00:00 2001 From: Oliver Kurth Date: Mon, 25 Apr 2022 22:38:42 +0000 Subject: [PATCH 1/4] replace TDNFPrepareAndAddPkg with TDNFPrepareSinglePkg - the forer was just wrapping the latter without anything useful to add --- client/resolve.c | 41 ++++------------------------------------- 1 file changed, 4 insertions(+), 37 deletions(-) diff --git a/client/resolve.c b/client/resolve.c index 50fca771..9ca3d6ab 100644 --- a/client/resolve.c +++ b/client/resolve.c @@ -115,7 +115,7 @@ TDNFPrepareAllPackages( BAIL_ON_TDNF_ERROR(dwError); for(nPkgIndex = 0; (uint32_t)nPkgIndex < dwCount; ++nPkgIndex) { - dwError = TDNFPrepareAndAddPkg( + dwError = TDNFPrepareSinglePkg( pTdnf, ppszPkgArray[nPkgIndex], *pAlterType, @@ -154,7 +154,7 @@ TDNFPrepareAllPackages( &pszName); BAIL_ON_TDNF_ERROR(dwError); - dwError = TDNFPrepareAndAddPkg( + dwError = TDNFPrepareSinglePkg( pTdnf, pszName, nAlterType, @@ -189,7 +189,7 @@ TDNFPrepareAllPackages( } BAIL_ON_TDNF_ERROR(dwError); - dwError = TDNFPrepareAndAddPkg( + dwError = TDNFPrepareSinglePkg( pTdnf, pszPkgName, nAlterType, @@ -252,7 +252,7 @@ TDNFFilterPackages( &pszName); BAIL_ON_TDNF_ERROR(dwError); - dwError = TDNFPrepareAndAddPkg( + dwError = TDNFPrepareSinglePkg( pTdnf, pszName, nAlterType, @@ -275,39 +275,6 @@ TDNFFilterPackages( goto cleanup; } -uint32_t -TDNFPrepareAndAddPkg( - PTDNF pTdnf, - const char* pszPkgName, - TDNF_ALTERTYPE nAlterType, - char** ppszPkgsNotResolved, - Queue* queueGoal - ) -{ - uint32_t dwError = 0; - if( !pTdnf || - IsNullOrEmptyString(pszPkgName) || - !ppszPkgsNotResolved || - !queueGoal) - { - dwError = ERROR_TDNF_INVALID_PARAMETER; - BAIL_ON_TDNF_ERROR(dwError); - } - - dwError = TDNFPrepareSinglePkg( - pTdnf, - pszPkgName, - nAlterType, - ppszPkgsNotResolved, - queueGoal); - BAIL_ON_TDNF_ERROR(dwError); - -cleanup: - return dwError; -error: - goto cleanup; -} - uint32_t TDNFPrepareSinglePkg( PTDNF pTdnf, From 5f1ce46c595bf15816a7745afd000a3ce5510dd0 Mon Sep 17 00:00:00 2001 From: Oliver Kurth Date: Mon, 25 Apr 2022 23:59:09 +0000 Subject: [PATCH 2/4] remove redundant code to protect itself from removing itself (TDNFCheckProtectedPkgs checks already) --- client/api.c | 14 +------------- 1 file changed, 1 insertion(+), 13 deletions(-) diff --git a/client/api.c b/client/api.c index 4d267410..9b743261 100644 --- a/client/api.c +++ b/client/api.c @@ -847,7 +847,7 @@ TDNFAddCmdLinePackages( BAIL_ON_TDNF_ERROR(dwError); TDNF_SAFE_FREE_MEMORY(pszCopyOfPkgName); - } + } } id = repo_add_rpm(pTdnf->pSolvCmdLineRepo, pszRPMPath, REPO_REUSE_REPODATA|REPO_NO_INTERNALIZE|RPM_ADD_WITH_HDRID|RPM_ADD_WITH_SHA256SUM); @@ -1604,18 +1604,6 @@ TDNFResolve( nAlterType); BAIL_ON_TDNF_ERROR(dwError); - pPkgInfo = pSolvedPkgInfo->pPkgsToRemove; - while(pPkgInfo != NULL) - { - if(pPkgInfo->pszName != NULL && - strcmp(pPkgInfo->pszName, TDNF_NAME) == 0) - { - dwError = ERROR_TDNF_SELF_ERASE; - BAIL_ON_TDNF_ERROR(dwError); - } - pPkgInfo = pPkgInfo->pNext; - } - dwError = TDNFCheckProtectedPkgs(pSolvedPkgInfo); BAIL_ON_TDNF_ERROR(dwError); From b42bf38a31acc1dc2e1b088a2bf2977c7e0c4f5d Mon Sep 17 00:00:00 2001 From: Oliver Kurth Date: Tue, 26 Apr 2022 00:30:06 +0000 Subject: [PATCH 3/4] simplify pkgs from cmd line logic --- client/api.c | 25 +++++++++---------------- client/structs.h | 1 - include/tdnf.h | 5 ----- 3 files changed, 9 insertions(+), 22 deletions(-) diff --git a/client/api.c b/client/api.c index 9b743261..06864825 100644 --- a/client/api.c +++ b/client/api.c @@ -769,7 +769,8 @@ TDNFOpenHandle( uint32_t TDNFAddCmdLinePackages( - PTDNF pTdnf + PTDNF pTdnf, + Queue *pQueueGoal ) { uint32_t dwError = 0; @@ -789,8 +790,6 @@ TDNFAddCmdLinePackages( BAIL_ON_TDNF_ERROR(dwError); } - queue_init(&pTdnf->queueCmdLinePkgs); - pCmdArgs = pTdnf->pArgs; pSack = pTdnf->pSack; @@ -857,7 +856,7 @@ TDNFAddCmdLinePackages( dwError = ERROR_TDNF_INVALID_PARAMETER; BAIL_ON_TDNF_ERROR(dwError); } - queue_push(&pTdnf->queueCmdLinePkgs, id); + queue_push(pQueueGoal, id); } pool_createwhatprovides(pSack->pPool); repo_internalize(pTdnf->pSolvCmdLineRepo); @@ -1556,9 +1555,7 @@ TDNFResolve( uint32_t dwError = 0; Queue queueGoal = {0}; char** ppszPkgsNotResolved = NULL; - PTDNF_SOLVED_PKG_INFO pSolvedPkgInfo = NULL; - PTDNF_PKG_INFO pPkgInfo = NULL; if(!pTdnf || !ppSolvedPkgInfo) { @@ -1566,21 +1563,17 @@ TDNFResolve( BAIL_ON_TDNF_ERROR(dwError); } - dwError = TDNFAddCmdLinePackages(pTdnf); - BAIL_ON_TDNF_ERROR(dwError); - - dwError = TDNFRefresh(pTdnf); - BAIL_ON_TDNF_ERROR(dwError); + queue_init(&queueGoal); if(nAlterType == ALTER_INSTALL || nAlterType == ALTER_REINSTALL) { - queue_init_clone(&queueGoal, &pTdnf->queueCmdLinePkgs); - } - else - { - queue_init(&queueGoal); + dwError = TDNFAddCmdLinePackages(pTdnf, &queueGoal); + BAIL_ON_TDNF_ERROR(dwError); } + dwError = TDNFRefresh(pTdnf); + BAIL_ON_TDNF_ERROR(dwError); + dwError = TDNFValidateCmdArgs(pTdnf); BAIL_ON_TDNF_ERROR(dwError); diff --git a/client/structs.h b/client/structs.h index 49adc657..15473d1a 100644 --- a/client/structs.h +++ b/client/structs.h @@ -26,7 +26,6 @@ typedef struct _TDNF_ PTDNF_CONF pConf; PTDNF_REPO_DATA pRepos; Repo *pSolvCmdLineRepo; - Queue queueCmdLinePkgs; PTDNF_PLUGIN pPlugins; } TDNF; diff --git a/include/tdnf.h b/include/tdnf.h index e6f828db..6c7e7990 100644 --- a/include/tdnf.h +++ b/include/tdnf.h @@ -37,11 +37,6 @@ TDNFRefresh( PTDNF pTdnf ); -uint32_t -TDNFAddCmdLinePackages( - PTDNF pTdnf -); - //check for updates uint32_t TDNFCheckUpdates( From cf8a27d7c16957fe2148427a85ffb9c443f5c737 Mon Sep 17 00:00:00 2001 From: Oliver Kurth Date: Tue, 26 Apr 2022 00:50:56 +0000 Subject: [PATCH 4/4] remove validate.c --- client/CMakeLists.txt | 1 - client/api.c | 14 +++++++--- client/validate.c | 54 ------------------------------------- pytests/tests/test_erase.py | 2 +- 4 files changed, 12 insertions(+), 59 deletions(-) delete mode 100644 client/validate.c diff --git a/client/CMakeLists.txt b/client/CMakeLists.txt index c8063281..77cd687e 100644 --- a/client/CMakeLists.txt +++ b/client/CMakeLists.txt @@ -44,7 +44,6 @@ add_library(${LIB_TDNF} SHARED rpmtrans.c updateinfo.c utils.c - validate.c metalink.c list.c ) diff --git a/client/api.c b/client/api.c index 06864825..04c0d432 100644 --- a/client/api.c +++ b/client/api.c @@ -1563,6 +1563,17 @@ TDNFResolve( BAIL_ON_TDNF_ERROR(dwError); } + if (nAlterType == ALTER_INSTALL || + nAlterType == ALTER_REINSTALL || + nAlterType == ALTER_ERASE) + { + if(pTdnf->pArgs->nCmdCount <= 1) + { + dwError = ERROR_TDNF_PACKAGE_REQUIRED; + BAIL_ON_TDNF_ERROR(dwError); + } + } + queue_init(&queueGoal); if(nAlterType == ALTER_INSTALL || nAlterType == ALTER_REINSTALL) @@ -1574,9 +1585,6 @@ TDNFResolve( dwError = TDNFRefresh(pTdnf); BAIL_ON_TDNF_ERROR(dwError); - dwError = TDNFValidateCmdArgs(pTdnf); - BAIL_ON_TDNF_ERROR(dwError); - dwError = TDNFAllocateMemory( pTdnf->pArgs->nCmdCount, sizeof(char*), diff --git a/client/validate.c b/client/validate.c deleted file mode 100644 index 06c5f842..00000000 --- a/client/validate.c +++ /dev/null @@ -1,54 +0,0 @@ -/* - * Copyright (C) 2015 VMware, Inc. All Rights Reserved. - * - * Licensed under the GNU Lesser General Public License v2.1 (the "License"); - * you may not use this file except in compliance with the License. The terms - * of the License are located in the COPYING file of this distribution. - */ - -/* - * Module : validate.c - * - * Abstract : - * - * tdnfclientlib - * - * client library - * - * Authors : Priyesh Padmavilasom (ppadmavilasom@vmware.com) - */ - -#include "includes.h" - -uint32_t -TDNFValidateCmdArgs( - PTDNF pTdnf - ) -{ - uint32_t dwError = 0; - PTDNF_CMD_ARGS pCmdArgs = NULL; - - if(!pTdnf || !pTdnf->pArgs) - { - dwError = ERROR_TDNF_INVALID_PARAMETER; - BAIL_ON_TDNF_ERROR(dwError); - } - pCmdArgs = pTdnf->pArgs; - - //TODO: make a better mechanism to handle requirements per cmd - //For now, check if at least one argument exists for install - if(!strcmp(pCmdArgs->ppszCmds[0], CMD_INSTALL)) - { - if(pCmdArgs->nCmdCount <= 1) - { - dwError = ERROR_TDNF_PACKAGE_REQUIRED; - BAIL_ON_TDNF_ERROR(dwError); - } - } - -cleanup: - return dwError; - -error: - goto cleanup; -} diff --git a/pytests/tests/test_erase.py b/pytests/tests/test_erase.py index 77844492..26872d42 100644 --- a/pytests/tests/test_erase.py +++ b/pytests/tests/test_erase.py @@ -21,7 +21,7 @@ def teardown_test(utils): def test_erase_no_arg(utils): ret = utils.run(['tdnf', 'erase']) - assert(ret['stderr'][0] == 'Nothing to do.') + assert(ret['retval'] == 1001) def test_erase_invalid_package(utils):