Skip to content

Commit

Permalink
Merge pull request #329 from oliverkurth/topic/okurth/clean-options
Browse files Browse the repository at this point in the history
add clean options and refactor
  • Loading branch information
oliverkurth authored Jun 24, 2022
2 parents b8240ea + 15add0e commit c935626
Show file tree
Hide file tree
Showing 12 changed files with 67 additions and 129 deletions.
81 changes: 36 additions & 45 deletions client/api.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
2 changes: 1 addition & 1 deletion client/repoutils.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
12 changes: 0 additions & 12 deletions common/utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
8 changes: 1 addition & 7 deletions include/tdnf.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -206,11 +205,6 @@ TDNFCloseHandle(
PTDNF pTdnf
);

void
TDNFFreeCleanInfo(
PTDNF_CLEAN_INFO pCleanInfo
);

void
TDNFFreeCmdArgs(
PTDNF_CMD_ARGS pCmdArgs
Expand Down
4 changes: 2 additions & 2 deletions include/tdnfcli.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 1 addition & 2 deletions include/tdnfclitypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
31 changes: 9 additions & 22 deletions include/tdnftypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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;
Expand Down
8 changes: 4 additions & 4 deletions pytests/tests/test_clean.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
26 changes: 3 additions & 23 deletions tools/cli/lib/api.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand All @@ -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:
Expand Down
9 changes: 5 additions & 4 deletions tools/cli/lib/parsecleanargs.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down Expand Up @@ -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;
Expand All @@ -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},
};
Expand Down
5 changes: 2 additions & 3 deletions tools/cli/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 3 additions & 4 deletions tools/cli/prototypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,7 @@ TDNFCliInvokeCheckUpdate(
uint32_t
TDNFCliInvokeClean(
PTDNF_CLI_CONTEXT pContext,
TDNF_CLEANTYPE nCleanType,
PTDNF_CLEAN_INFO *ppTDNFCleanInfo
uint32_t nCleanType
);

uint32_t
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit c935626

Please sign in to comment.