Skip to content

Commit

Permalink
add quiet option. singleton load global resources
Browse files Browse the repository at this point in the history
Change-Id: Id11c299f16fc3c6297f2678b1d62940d81f9528a
  • Loading branch information
Priyesh Padmavilasom committed Nov 4, 2016
1 parent c675a4d commit 3977aad
Show file tree
Hide file tree
Showing 16 changed files with 270 additions and 54 deletions.
9 changes: 9 additions & 0 deletions Makefile.am
Original file line number Diff line number Diff line change
@@ -1,10 +1,19 @@
ACLOCAL_AMFLAGS = -I m4

CLEANFILES =
EXTRA_DIST =
conf_DATA = tdnf.conf
pkginclude_HEADERS = include/tdnfclient.h include/tdnferror.h include/tdnftypes.h
pkgconfigdir = $(libdir)/pkgconfig

SUBDIRS = \
common \
client \
tests \
tools

pkgconfig_DATA = tdnf.pc
tdnf.pc: $(top_srcdir)/tdnf.pc.in
./config.status --file=${subdir}/tdnf.pc:${subdir}/tdnf.pc.in
CLEANFILES += tdnf.pc
EXTRA_DIST += tdnf.pc.in
82 changes: 82 additions & 0 deletions client/api.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,88 @@

#include "includes.h"

static TDNF_ENV gEnv = {0};

uint32_t
TDNFInit(
)
{
uint32_t dwError = 0;
int nLocked = 0;

pthread_mutex_lock (&gEnv.mutexInitialize);
nLocked = 1;
if(!gEnv.nInitialized)
{
dwError = rpmReadConfigFiles(NULL, NULL);
BAIL_ON_TDNF_ERROR(dwError);

gEnv.nInitialized = 1;
}

cleanup:
if(nLocked)
{
pthread_mutex_unlock(&gEnv.mutexInitialize);
}
return dwError;

error:
goto cleanup;
}

uint32_t
TDNFIsInitialized(
int *pnInitialized
)
{
uint32_t dwError = 0;
int nInitialized = 0;
int nLocked = 0;

if(!pnInitialized)
{
dwError = ERROR_TDNF_INVALID_PARAMETER;
BAIL_ON_TDNF_ERROR(dwError);
}

pthread_mutex_lock (&gEnv.mutexInitialize);
nLocked = 1;

nInitialized = gEnv.nInitialized;

*pnInitialized = nInitialized;

cleanup:
if(nLocked)
{
pthread_mutex_unlock(&gEnv.mutexInitialize);
}
return dwError;

error:
if(pnInitialized)
{
*pnInitialized = 0;
}
goto cleanup;
}

void
TDNFUninit(
)
{
pthread_mutex_lock (&gEnv.mutexInitialize);

if(gEnv.nInitialized)
{
rpmFreeRpmrc();
}
gEnv.nInitialized = 0;

pthread_mutex_unlock(&gEnv.mutexInitialize);
}

//All alter commands such as install/update/erase
uint32_t
TDNFAlterCommand(
Expand Down
2 changes: 2 additions & 0 deletions client/init.c
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,8 @@ TDNFCloneCmdArgs(
pCmdArgs->nCacheOnly = pCmdArgsIn->nCacheOnly;
pCmdArgs->nDebugSolver = pCmdArgsIn->nDebugSolver;
pCmdArgs->nNoGPGCheck = pCmdArgsIn->nNoGPGCheck;
pCmdArgs->nNoOutput = pCmdArgsIn->nNoOutput;
pCmdArgs->nQuiet = pCmdArgsIn->nQuiet;
pCmdArgs->nRefresh = pCmdArgsIn->nRefresh;
pCmdArgs->nRpmVerbosity = pCmdArgsIn->nRpmVerbosity;
pCmdArgs->nShowDuplicates= pCmdArgsIn->nShowDuplicates;
Expand Down
4 changes: 4 additions & 0 deletions client/prototypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -810,3 +810,7 @@ uint32_t
TDNFValidateCmdArgs(
PTDNF pTdnf
);

uint32_t
TDNFIsInitialized(
);
55 changes: 43 additions & 12 deletions client/remoterepo.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,42 @@ lrProgressCB(
return 0;
}

uint32_t
set_progress_cb(
LrHandle *pRepoHandle,
const char *pszPkgName
)
{
uint32_t dwError = 0;
gboolean bRet = FALSE;

if(!pRepoHandle || IsNullOrEmptyString(pszPkgName))
{
dwError = ERROR_TDNF_INVALID_PARAMETER;
BAIL_ON_TDNF_ERROR(dwError);
}

bRet = lr_handle_setopt(pRepoHandle, NULL, LRO_PROGRESSCB, lrProgressCB);
if(bRet == FALSE)
{
//TODO: Add repo specific
dwError = ERROR_TDNF_INVALID_PARAMETER;
BAIL_ON_TDNF_ERROR(dwError);
}
bRet = lr_handle_setopt(pRepoHandle, NULL, LRO_PROGRESSDATA, pszPkgName);
if(bRet == FALSE)
{
//TODO: Add repo specific
dwError = ERROR_TDNF_INVALID_PARAMETER;
BAIL_ON_TDNF_ERROR(dwError);
}

cleanup:
return dwError;

error:
goto cleanup;
}

uint32_t
TDNFDownloadPackage(
Expand All @@ -59,13 +95,16 @@ TDNFDownloadPackage(
char* pszUserPass = NULL;
char* pszBaseUrl = NULL;
const char* pszPkgName = NULL;
int nSilent = 0;

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

nSilent = pTdnf->pArgs->nNoOutput;

pRepoHandle = lr_handle_init();

if(!pRepoHandle)
Expand Down Expand Up @@ -97,18 +136,10 @@ TDNFDownloadPackage(
{
lr_handle_setopt(pRepoHandle, NULL, LRO_USERPWD, pszUserPass);
}
bRet = lr_handle_setopt(pRepoHandle, NULL, LRO_PROGRESSCB, lrProgressCB);
if(bRet == FALSE)
{
//TODO: Add repo specific
dwError = ERROR_TDNF_INVALID_PARAMETER;
BAIL_ON_TDNF_ERROR(dwError);
}
bRet = lr_handle_setopt(pRepoHandle, NULL, LRO_PROGRESSDATA, pszPkgName);
if(bRet == FALSE)

if(!nSilent)
{
//TODO: Add repo specific
dwError = ERROR_TDNF_INVALID_PARAMETER;
dwError = set_progress_cb(pRepoHandle, pszPkgName);
BAIL_ON_TDNF_ERROR(dwError);
}

Expand Down
24 changes: 19 additions & 5 deletions client/rpmtrans.c
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,6 @@ TDNFRpmExecTransaction(
BAIL_ON_TDNF_ERROR(dwError);
}

dwError = rpmReadConfigFiles(NULL, NULL);
BAIL_ON_TDNF_ERROR(dwError);

rpmSetVerbosity(TDNFConfGetRpmVerbosity(pTdnf));

//Allow downgrades
Expand Down Expand Up @@ -212,6 +209,15 @@ TDNFRunTransaction(
)
{
uint32_t dwError = 0;
int nSilent = 0;

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

nSilent = pTdnf->pArgs->nNoOutput;

dwError = rpmtsOrder(pTS->pTS);
BAIL_ON_TDNF_ERROR(dwError);
Expand All @@ -221,13 +227,21 @@ TDNFRunTransaction(

rpmtsClean(pTS->pTS);

fprintf(stdout, "Testing transaction\n");
//TODO do callbacks for output
if(!nSilent)
{
fprintf(stdout, "Testing transaction\n");
}

rpmtsSetFlags(pTS->pTS, RPMTRANS_FLAG_TEST);
dwError = rpmtsRun(pTS->pTS, NULL, pTS->nProbFilterFlags);
BAIL_ON_TDNF_ERROR(dwError);

fprintf(stdout, "Running transaction\n");
//TODO do callbacks for output
if(!nSilent)
{
fprintf(stdout, "Running transaction\n");
}
rpmtsSetFlags(pTS->pTS, RPMTRANS_FLAG_NONE);
dwError = rpmtsRun(pTS->pTS, NULL, pTS->nProbFilterFlags);
BAIL_ON_TDNF_ERROR(dwError);
Expand Down
6 changes: 6 additions & 0 deletions client/structs.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,9 @@ typedef struct _TDNF_RPM_TS_
FD_t pFD;
GArray* pCachedRpmsArray;
}TDNFRPMTS, *PTDNFRPMTS;

typedef struct _TDNF_ENV_
{
pthread_mutex_t mutexInitialize;
int nInitialized;
}TDNF_ENV, *PTDNF_ENV;
3 changes: 0 additions & 3 deletions client/utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -387,9 +387,6 @@ TDNFRawGetPackageVersion(
BAIL_ON_TDNF_ERROR(dwError);
}

dwError = rpmReadConfigFiles(NULL, NULL);
BAIL_ON_TDNF_ERROR(dwError);

pTS = rpmtsCreate();
if(!pTS)
{
Expand Down
2 changes: 1 addition & 1 deletion configure.ac
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
AC_INIT(tdnf, 1.0.9)
AC_INIT(tdnf, 1.1.0)
AC_MSG_NOTICE([tdnf configuration])

AC_CANONICAL_SYSTEM
Expand Down
11 changes: 11 additions & 0 deletions include/tdnfclient.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@ extern "C" {

//api.c

//global init.
uint32_t
TDNFInit(
);

//Open a handle using initial args
//args can define a command, have config overrides
uint32_t
Expand Down Expand Up @@ -242,6 +247,12 @@ TDNFFreeCmdOpt(
PTDNF_CMD_OPT pCmdOpt
);

//free global resources.
void
TDNFUninit(
);


#ifdef __cplusplus
}
#endif
Expand Down
2 changes: 2 additions & 0 deletions include/tdnftypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,8 @@ typedef struct _TDNF_CMD_ARGS
int nShowDuplicates; //show dups in list/search
int nShowVersion; //show version and exit
int nNoGPGCheck; //skip gpg check
int nNoOutput; //if quiet and assumeyes are provided
int nQuiet; //quiet option
int nVerbose; //print debug info
int nIPv4; //resolve to IPv4 addresses only
int nIPv6; //resolve to IPv6 addresses only
Expand Down
11 changes: 11 additions & 0 deletions tdnf.pc.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
prefix=@prefix@
exec_prefix=@exec_prefix@
libdir=@libdir@
includedir=@includedir@/tdnf

Name: tdnf
Description: tiny dandified yum
Version: @VERSION@
Requires:hawkey librepo rpm
Libs: -L${libdir} -ltdnfclient
Cflags: -I${includedir}
Loading

0 comments on commit 3977aad

Please sign in to comment.