diff --git a/client/api.c b/client/api.c index 6b0ae7da..0e4ef75f 100644 --- a/client/api.c +++ b/client/api.c @@ -410,76 +410,67 @@ TDNFCheckUpdates( uint32_t TDNFClean( PTDNF pTdnf, - TDNF_CLEANTYPE nCleanType, - PTDNF_CLEAN_INFO* ppCleanInfo + uint32_t nCleanType ) { uint32_t dwError = 0; - PTDNF_CLEAN_INFO pCleanInfo = NULL; - char** ppszReposUsed = NULL; + PTDNF_REPO_DATA pRepo = NULL; - if(!pTdnf || !ppCleanInfo) + if(!pTdnf) { dwError = ERROR_TDNF_INVALID_PARAMETER; BAIL_ON_TDNF_ERROR(dwError); } - //Rest of the clean options will be - //supported in the next release - if(nCleanType != CLEANTYPE_ALL) + if(nCleanType == CLEANTYPE_PLUGINS) { dwError = ERROR_TDNF_CLEAN_UNSUPPORTED; BAIL_ON_TDNF_ERROR(dwError); } - dwError = TDNFAllocateMemory( - 1, - sizeof(TDNF_CLEAN_INFO), - (void**)&pCleanInfo); - BAIL_ON_TDNF_ERROR(dwError); - - dwError = TDNFCopyEnabledRepos(pTdnf->pRepos, &pCleanInfo->ppszReposUsed); - BAIL_ON_TDNF_ERROR(dwError); - - ppszReposUsed = pCleanInfo->ppszReposUsed; - if(nCleanType == CLEANTYPE_ALL) + for (pRepo = pTdnf->pRepos; pRepo; pRepo = pRepo->pNext) { - while(*ppszReposUsed) + if (strcmp(pRepo->pszId, CMDLINE_REPO_NAME) == 0) { - dwError = TDNFRepoRemoveCache(pTdnf,*ppszReposUsed); + continue; + } + pr_info("cleaning %s:", pRepo->pszId); + if (nCleanType & CLEANTYPE_METADATA) + { + pr_info(" metadata"); + dwError = TDNFRepoRemoveCache(pTdnf, pRepo->pszId); BAIL_ON_TDNF_ERROR(dwError); - - dwError = TDNFRemoveSolvCache(pTdnf, *ppszReposUsed); + } + if (nCleanType & CLEANTYPE_DBCACHE) + { + pr_info(" dbcache"); + dwError = TDNFRemoveSolvCache(pTdnf, pRepo->pszId); BAIL_ON_TDNF_ERROR(dwError); - - if (!pTdnf->pConf->nKeepCache) - { - dwError = TDNFRemoveRpmCache(pTdnf, *ppszReposUsed); - BAIL_ON_TDNF_ERROR(dwError); - } - - dwError = TDNFRemoveKeysCache(pTdnf, *ppszReposUsed); + } + if (nCleanType & CLEANTYPE_PACKAGES) + { + pr_info(" packages"); + dwError = TDNFRemoveRpmCache(pTdnf, pRepo->pszId); BAIL_ON_TDNF_ERROR(dwError); - - ++ppszReposUsed; } + if (nCleanType & CLEANTYPE_KEYS) + { + pr_info(" keys"); + dwError = TDNFRemoveKeysCache(pTdnf, pRepo->pszId); + BAIL_ON_TDNF_ERROR(dwError); + } + if (nCleanType & CLEANTYPE_EXPIRE_CACHE) + { + pr_info(" expire-cache"); + dwError = TDNFRemoveLastRefreshMarker(pTdnf, pRepo->pszId); + BAIL_ON_TDNF_ERROR(dwError); + } + pr_info("\n"); } - - pCleanInfo->nCleanAll = (nCleanType == CLEANTYPE_ALL); - - *ppCleanInfo = pCleanInfo; cleanup: return dwError; error: - if(ppCleanInfo) - { - *ppCleanInfo = NULL; - } - if(pCleanInfo) - { - TDNFFreeCleanInfo(pCleanInfo); - } goto cleanup; } diff --git a/client/repoutils.c b/client/repoutils.c index 5171c931..99c6062e 100644 --- a/client/repoutils.c +++ b/client/repoutils.c @@ -351,7 +351,7 @@ TDNFRemoveLastRefreshMarker( BAIL_ON_TDNF_ERROR(dwError); if (pszLastRefreshMarker) { - if(unlink(pszLastRefreshMarker)) + if(unlink(pszLastRefreshMarker) && errno != ENOENT) { dwError = errno; BAIL_ON_TDNF_SYSTEM_ERROR(dwError); diff --git a/common/utils.c b/common/utils.c index 18ed5ab8..525d428d 100644 --- a/common/utils.c +++ b/common/utils.c @@ -408,18 +408,6 @@ TDNFFreeRepos( } } -void -TDNFFreeCleanInfo( - PTDNF_CLEAN_INFO pCleanInfo - ) -{ - if(pCleanInfo) - { - TDNF_SAFE_FREE_STRINGARRAY(pCleanInfo->ppszReposUsed); - TDNFFreeMemory(pCleanInfo); - } -} - uint32_t TDNFYesOrNo( PTDNF_CMD_ARGS pArgs, diff --git a/include/tdnf.h b/include/tdnf.h index 6c7e7990..80a0e309 100644 --- a/include/tdnf.h +++ b/include/tdnf.h @@ -51,8 +51,7 @@ TDNFCheckUpdates( uint32_t TDNFClean( PTDNF pTdnf, - TDNF_CLEANTYPE nCleanType, - PTDNF_CLEAN_INFO* ppCleanInfo + uint32_t nCleanType ); //show list of packages filtered by scope, name @@ -206,11 +205,6 @@ TDNFCloseHandle( PTDNF pTdnf ); -void -TDNFFreeCleanInfo( - PTDNF_CLEAN_INFO pCleanInfo - ); - void TDNFFreeCmdArgs( PTDNF_CMD_ARGS pCmdArgs diff --git a/include/tdnfcli.h b/include/tdnfcli.h index e4be1d50..e2b412f4 100644 --- a/include/tdnfcli.h +++ b/include/tdnfcli.h @@ -51,13 +51,13 @@ TDNFCliFreeListArgs( uint32_t TDNFCliParseCleanType( const char* pszCleanType, - TDNF_CLEANTYPE* pnCleanType + uint32_t* pnCleanType ); uint32_t TDNFCliParseCleanArgs( PTDNF_CMD_ARGS pCmdArgs, - TDNF_CLEANTYPE* pnCleanType + uint32_t* pnCleanType ); uint32_t diff --git a/include/tdnfclitypes.h b/include/tdnfclitypes.h index a0a340ff..79cbbb62 100644 --- a/include/tdnfclitypes.h +++ b/include/tdnfclitypes.h @@ -69,8 +69,7 @@ typedef uint32_t typedef uint32_t (*PFN_TDNF_CLEAN)( PTDNF_CLI_CONTEXT, - TDNF_CLEANTYPE, - PTDNF_CLEAN_INFO * + uint32_t ); typedef uint32_t diff --git a/include/tdnftypes.h b/include/tdnftypes.h index 9400fdaf..f794f626 100644 --- a/include/tdnftypes.h +++ b/include/tdnftypes.h @@ -108,18 +108,15 @@ typedef enum UPDATE_ENHANCEMENT }TDNF_UPDATEINFO_TYPE; -//Clean command type -typedef enum -{ - CLEANTYPE_NONE = -1, - CLEANTYPE_PACKAGES, - CLEANTYPE_METADATA, - CLEANTYPE_DBCACHE, - CLEANTYPE_PLUGINS, - CLEANTYPE_EXPIRE_CACHE, - CLEANTYPE_RPMDB, - CLEANTYPE_ALL -}TDNF_CLEANTYPE; +#define CLEANTYPE_NONE 0x00 +#define CLEANTYPE_PACKAGES 0x01 +#define CLEANTYPE_METADATA 0x02 +#define CLEANTYPE_DBCACHE 0x04 +#define CLEANTYPE_PLUGINS 0x08 +#define CLEANTYPE_EXPIRE_CACHE 0x10 +#define CLEANTYPE_KEYS 0x20 +#define CLEANTYPE_ALL 0xff + //RepoList command filter typedef enum @@ -282,16 +279,6 @@ typedef struct _TDNF_REPO_DATA struct _TDNF_REPO_DATA* pNext; }TDNF_REPO_DATA, *PTDNF_REPO_DATA; -typedef struct _TDNF_CLEAN_INFO -{ - int nCleanAll; - char** ppszReposUsed; - int nRpmDbFilesRemoved; - int nMetadataFilesRemoved; - int nDbCacheFilesRemoved; - int nPackageFilesRemoved; -}TDNF_CLEAN_INFO, *PTDNF_CLEAN_INFO; - typedef struct _TDNF_ERROR_DESC { int nCode; diff --git a/pytests/tests/test_clean.py b/pytests/tests/test_clean.py index 31411478..33fe7302 100644 --- a/pytests/tests/test_clean.py +++ b/pytests/tests/test_clean.py @@ -31,22 +31,22 @@ def test_clean_invalid_arg(utils): def test_clean_packages(utils): ret = utils.run(['tdnf', 'clean', 'packages']) - assert(ret['retval'] == 1016) + assert(ret['retval'] == 0) def test_clean_dbcache(utils): ret = utils.run(['tdnf', 'clean', 'dbcache']) - assert(ret['retval'] == 1016) + assert(ret['retval'] == 0) def test_clean_metadata(utils): ret = utils.run(['tdnf', 'clean', 'metadata']) - assert(ret['retval'] == 1016) + assert(ret['retval'] == 0) def test_clean_expire_cache(utils): ret = utils.run(['tdnf', 'clean', 'expire-cache']) - assert(ret['retval'] == 1016) + assert(ret['retval'] == 0) def test_clean_plugins(utils): diff --git a/tools/cli/lib/api.c b/tools/cli/lib/api.c index c1a0637e..777e0d5e 100644 --- a/tools/cli/lib/api.c +++ b/tools/cli/lib/api.c @@ -55,9 +55,7 @@ TDNFCliCleanCommand( ) { uint32_t dwError = 0; - TDNF_CLEANTYPE nCleanType = CLEANTYPE_NONE; - PTDNF_CLEAN_INFO pTDNFCleanInfo = NULL; - char** ppszReposUsed = NULL; + uint32_t nCleanType = CLEANTYPE_NONE; if(!pContext || !pContext->hTdnf || !pContext->pFnClean) { @@ -68,30 +66,12 @@ TDNFCliCleanCommand( dwError = TDNFCliParseCleanArgs(pCmdArgs, &nCleanType); BAIL_ON_CLI_ERROR(dwError); - dwError = pContext->pFnClean(pContext, nCleanType, &pTDNFCleanInfo); + dwError = pContext->pFnClean(pContext, nCleanType); BAIL_ON_CLI_ERROR(dwError); - //Print clean info - pr_info("Cleaning repos:"); - ppszReposUsed = pTDNFCleanInfo->ppszReposUsed; - while(*ppszReposUsed) - { - pr_info(" %s", *ppszReposUsed); - ++ppszReposUsed; - } - - pr_info("\n"); - - if(pTDNFCleanInfo->nCleanAll) - { - pr_info("Cleaning up everything\n"); - } + pr_info("Done.\n"); cleanup: - if(pTDNFCleanInfo) - { - TDNFFreeCleanInfo(pTDNFCleanInfo); - } return dwError; error: diff --git a/tools/cli/lib/parsecleanargs.c b/tools/cli/lib/parsecleanargs.c index fc1587d4..da428c9d 100644 --- a/tools/cli/lib/parsecleanargs.c +++ b/tools/cli/lib/parsecleanargs.c @@ -24,11 +24,11 @@ uint32_t TDNFCliParseCleanArgs( PTDNF_CMD_ARGS pCmdArgs, - TDNF_CLEANTYPE* pnCleanType + uint32_t* pnCleanType ) { uint32_t dwError = 0; - TDNF_CLEANTYPE nCleanType = CLEANTYPE_NONE; + uint32_t nCleanType = CLEANTYPE_NONE; if(!pCmdArgs) { @@ -64,12 +64,12 @@ TDNFCliParseCleanArgs( uint32_t TDNFCliParseCleanType( const char* pszCleanType, - TDNF_CLEANTYPE* pnCleanType + uint32_t* pnCleanType ) { uint32_t dwError = 0; int nIndex = 0; - TDNF_CLEANTYPE nCleanType = CLEANTYPE_ALL; + uint32_t nCleanType = CLEANTYPE_ALL; struct stTemp { char* pszTypeName; @@ -81,6 +81,7 @@ TDNFCliParseCleanType( {"metadata", CLEANTYPE_METADATA}, {"dbcache", CLEANTYPE_DBCACHE}, {"plugins", CLEANTYPE_PLUGINS}, + {"keys", CLEANTYPE_KEYS}, {"expire-cache", CLEANTYPE_EXPIRE_CACHE}, {"all", CLEANTYPE_ALL}, }; diff --git a/tools/cli/main.c b/tools/cli/main.c index 20fc4106..dc2f9caa 100644 --- a/tools/cli/main.c +++ b/tools/cli/main.c @@ -337,11 +337,10 @@ TDNFCliInvokeCheckUpdate( uint32_t TDNFCliInvokeClean( PTDNF_CLI_CONTEXT pContext, - TDNF_CLEANTYPE nCleanType, - PTDNF_CLEAN_INFO *ppTDNFCleanInfo + uint32_t nCleanType ) { - return TDNFClean(pContext->hTdnf, nCleanType, ppTDNFCleanInfo); + return TDNFClean(pContext->hTdnf, nCleanType); } uint32_t diff --git a/tools/cli/prototypes.h b/tools/cli/prototypes.h index be64fca8..9263213f 100644 --- a/tools/cli/prototypes.h +++ b/tools/cli/prototypes.h @@ -51,8 +51,7 @@ TDNFCliInvokeCheckUpdate( uint32_t TDNFCliInvokeClean( PTDNF_CLI_CONTEXT pContext, - TDNF_CLEANTYPE nCleanType, - PTDNF_CLEAN_INFO *ppTDNFCleanInfo + uint32_t nCleanType ); uint32_t @@ -285,13 +284,13 @@ TDNFCliParseArgs( uint32_t ParseCleanType( const char* pszCleanType, - TDNF_CLEANTYPE* pnCleanType + uint32_t* pnCleanType ); uint32_t TDNFCliParseCleanArgs( PTDNF_CMD_ARGS pCmdArgs, - TDNF_CLEANTYPE* pnCleanType + uint32_t* pnCleanType ); //parselistargs.c