Skip to content

Commit

Permalink
add check command
Browse files Browse the repository at this point in the history
Change-Id: I52ffea0bb351718af8a27e9391d05fa18f2c85c8
  • Loading branch information
Priyesh Padmavilasom committed Sep 29, 2017
1 parent df91812 commit 0ba0916
Show file tree
Hide file tree
Showing 9 changed files with 118 additions and 1 deletion.
47 changes: 47 additions & 0 deletions client/api.c
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,53 @@ TDNFUninit(
pthread_mutex_unlock(&gEnv.mutexInitialize);
}

//Check all available packages
uint32_t
TDNFCheckPackages(
PTDNF pTdnf
)
{
uint32_t dwError = 0;
PTDNF_SOLVED_PKG_INFO pSolvedPkgInfo = NULL;
PTDNF_CMD_ARGS pArgs = NULL;
int nCmdCountOrig = 0;
char **ppszCmdsOrig = NULL;
char *ppszCheckCmds[] = {"check", "*", NULL};

if(!pTdnf || !pTdnf->pArgs)
{
dwError = ERROR_TDNF_INVALID_PARAMETER;
BAIL_ON_TDNF_ERROR(dwError);
}

pArgs = pTdnf->pArgs;
nCmdCountOrig = pArgs->nCmdCount;
ppszCmdsOrig = pArgs->ppszCmds;

//We dont intend to follow through on this install command
pArgs->nAssumeNo = 1;

//pass all packages available to resolve with install operation
pArgs->nCmdCount = 2;
pArgs->ppszCmds = ppszCheckCmds;

dwError = TDNFResolve(pTdnf, ALTER_INSTALL, &pSolvedPkgInfo);
BAIL_ON_TDNF_ERROR(dwError);

cleanup:
if(pArgs)
{
pArgs->nCmdCount = nCmdCountOrig;
pArgs->ppszCmds = ppszCmdsOrig;
}

return dwError;

error:
goto cleanup;
}


//All alter commands such as install/update/erase
uint32_t
TDNFAlterCommand(
Expand Down
14 changes: 13 additions & 1 deletion client/resolve.c
Original file line number Diff line number Diff line change
Expand Up @@ -612,8 +612,20 @@ TDNFPrepareSinglePkg(
error:
if(dwError == ERROR_TDNF_ALREADY_INSTALLED)
{
int nShowAlreadyInstalled = 1;
//dont show already installed errors in the check path
if(pTdnf && pTdnf->pArgs)
{
if(!strcmp(pTdnf->pArgs->ppszCmds[0], "check"))
{
nShowAlreadyInstalled = 0;
}
}
dwError = 0;
fprintf(stderr, "Package %s is already installed.\n", pszPkgName);
if(nShowAlreadyInstalled)
{
fprintf(stderr, "Package %s is already installed.\n", pszPkgName);
}
}
if(dwError == ERROR_TDNF_NO_UPGRADE_PATH)
{
Expand Down
6 changes: 6 additions & 0 deletions include/tdnf.h
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,12 @@ TDNFMakeCache(
PTDNF pTdnf
);

//check all packages in all enables repositories
uint32_t
TDNFCheckPackages(
PTDNF pTdnf
);

//check all packages in a local directory
//using the local directory contents
//for dep resolution.
Expand Down
6 changes: 6 additions & 0 deletions include/tdnfcli.h
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,12 @@ TDNFCliRepoListCommand(
PTDNF_CMD_ARGS pCmdArgs
);

uint32_t
TDNFCliCheckCommand(
PTDNF_CLI_CONTEXT pContext,
PTDNF_CMD_ARGS pCmdArgs
);

uint32_t
TDNFCliCheckLocalCommand(
PTDNF_CLI_CONTEXT pContext,
Expand Down
5 changes: 5 additions & 0 deletions include/tdnfclitypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@ typedef uint32_t
TDNF_ALTERTYPE,
PTDNF_SOLVED_PKG_INFO);

typedef uint32_t
(*PFN_TDNF_CHECK)(
PTDNF_CLI_CONTEXT);

typedef uint32_t
(*PFN_TDNF_CHECK_LOCAL)(
PTDNF_CLI_CONTEXT,
Expand Down Expand Up @@ -147,6 +151,7 @@ typedef struct _TDNF_CLI_CONTEXT_
PFN_TDNF_SEARCH pFnSearch;
PFN_TDNF_UPDATEINFO pFnUpdateInfo;
PFN_TDNF_UPDATEINFO_SUMMARY pFnUpdateInfoSummary;
PFN_TDNF_CHECK pFnCheck;
}TDNF_CLI_CONTEXT, *PTDNF_CLI_CONTEXT;

#ifdef __cplusplus
Expand Down
25 changes: 25 additions & 0 deletions tools/cli/lib/api.c
Original file line number Diff line number Diff line change
Expand Up @@ -533,3 +533,28 @@ TDNFCliMakeCacheCommand(
error:
goto cleanup;
}

uint32_t
TDNFCliCheckCommand(
PTDNF_CLI_CONTEXT pContext,
PTDNF_CMD_ARGS pCmdArgs
)
{
uint32_t dwError = 0;

if(!pContext || !pContext->hTdnf || !pCmdArgs)
{
dwError = ERROR_TDNF_CLI_INVALID_ARGUMENT;
BAIL_ON_CLI_ERROR(dwError);
}

dwError = pContext->pFnCheck(pContext);
BAIL_ON_CLI_ERROR(dwError);

fprintf(stdout, "Check completed without issues\n");
cleanup:
return dwError;

error:
goto cleanup;
}
1 change: 1 addition & 0 deletions tools/cli/lib/help.c
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ TDNFCliShowHelp(
printf("List of Main Commands\n");
printf("\n");

printf("check Checks for problems in installed and available packages\n");
printf("check-local Checks local rpm folder for problems\n");
printf("check-update Check for available package upgrades\n");
printf("clean Remove cached data\n");
Expand Down
10 changes: 10 additions & 0 deletions tools/cli/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ int main(int argc, char* argv[])
{
{"autoerase", TDNFCliAutoEraseCommand},
{"autoremove", TDNFCliAutoEraseCommand},
{"check", TDNFCliCheckCommand},
{"check-local", TDNFCliCheckLocalCommand},
{"check-update", TDNFCliCheckUpdateCommand},
{"clean", TDNFCliCleanCommand},
Expand Down Expand Up @@ -62,6 +63,7 @@ int main(int argc, char* argv[])
PTDNF pTdnf = NULL;
int nFound = 0;

_context.pFnCheck = TDNFCliInvokeCheck;
_context.pFnCheckLocal = TDNFCliInvokeCheckLocal;
_context.pFnCheckUpdate = TDNFCliInvokeCheckUpdate;
_context.pFnClean = TDNFCliInvokeClean;
Expand Down Expand Up @@ -241,6 +243,14 @@ TDNFCliVerboseShowEnv(
goto cleanup;
}

uint32_t
TDNFCliInvokeCheck(
PTDNF_CLI_CONTEXT pContext
)
{
return TDNFCheckPackages(pContext->hTdnf);
}

uint32_t
TDNFCliInvokeCheckLocal(
PTDNF_CLI_CONTEXT pContext,
Expand Down
5 changes: 5 additions & 0 deletions tools/cli/prototypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@ TDNFCliInvokeAlter(
PTDNF_SOLVED_PKG_INFO pSolvedPkgInfo
);

uint32_t
TDNFCliInvokeCheck(
PTDNF_CLI_CONTEXT pContext
);

uint32_t
TDNFCliInvokeCheckLocal(
PTDNF_CLI_CONTEXT pContext,
Expand Down

0 comments on commit 0ba0916

Please sign in to comment.