diff --git a/client/Makefile.am b/client/Makefile.am index b850d05c..50eeaec0 100644 --- a/client/Makefile.am +++ b/client/Makefile.am @@ -9,7 +9,6 @@ libtdnfclient_la_SOURCES = \ goal.c \ gpgcheck.c \ init.c \ - makecache.c \ memory.c \ packageutils.c \ repo.c \ diff --git a/client/api.c b/client/api.c index 870890df..6041565e 100644 --- a/client/api.c +++ b/client/api.c @@ -459,25 +459,18 @@ TDNFMakeCache( ) { uint32_t dwError = 0; - PTDNF_CLEAN_INFO pCleanInfo = NULL; if(!pTdnf) { dwError = ERROR_TDNF_INVALID_PARAMETER; BAIL_ON_TDNF_ERROR(dwError); } - //Do clean metadata and refresh - dwError = TDNFClean(pTdnf, CLEANTYPE_ALL, &pCleanInfo); - BAIL_ON_TDNF_ERROR(dwError); - dwError = TDNFRefreshCache(pTdnf); + //Pass in clean metadata as 1 + dwError = TDNFRefreshSack(pTdnf, 1); BAIL_ON_TDNF_ERROR(dwError); cleanup: - if(pCleanInfo) - { - TDNFFreeCleanInfo(pCleanInfo); - } return dwError; error: @@ -494,8 +487,6 @@ TDNFOpenHandle( { uint32_t dwError = 0; PTDNF pTdnf = NULL; - HyRepo hRepo = NULL; - int nYumFlags = HY_LOAD_FILELISTS | HY_LOAD_UPDATEINFO; if(!pArgs || !ppTdnf) { @@ -520,42 +511,9 @@ TDNFOpenHandle( &pTdnf->pRepos); BAIL_ON_TDNF_ERROR(dwError); - dwError = TDNFInitSack(pTdnf, &pTdnf->hSack, HY_LOAD_FILELISTS); + dwError = TDNFRefreshSack(pTdnf, pTdnf->pArgs->nRefresh); BAIL_ON_TDNF_ERROR(dwError); - //If there is an empty repo directory, do nothing - if(pTdnf->pRepos) - { - PTDNF_REPO_DATA pTempRepo = pTdnf->pRepos; - while(pTempRepo) - { - if(pTempRepo->nEnabled) - { - dwError = TDNFInitRepo(pTdnf, pTempRepo, &hRepo); - if(dwError) - { - if(pTempRepo->nSkipIfUnavailable) - { - pTempRepo->nEnabled = 0; - fprintf(stderr, "Disabling Repo: '%s'\n", pTempRepo->pszName); - - dwError = 0; - } - } - BAIL_ON_TDNF_ERROR(dwError); - - if(pTempRepo->nEnabled) - { - pTempRepo->hRepo = hRepo; - - dwError = TDNFLoadYumRepo(pTdnf->hSack, hRepo, nYumFlags); - BAIL_ON_TDNF_ERROR(dwError); - } - } - pTempRepo = pTempRepo->pNext; - } - } - *ppTdnf = pTdnf; cleanup: diff --git a/client/goal.c b/client/goal.c index 99864697..612298f0 100644 --- a/client/goal.c +++ b/client/goal.c @@ -266,11 +266,11 @@ TDNFGoalReportProblems( nCount = hy_goal_count_problems(hGoal); if(nCount > 0) { - fprintf(stderr, "Found %d problem(s) while resolving\n", nCount); + fprintf(stdout, "Found %d problem(s) while resolving\n", nCount); for(; i < nCount; ++i) { pszProblem = hy_goal_describe_problem(hGoal, i); - fprintf(stderr, "%d. %s\n", i+1, pszProblem); + fprintf(stdout, "%d. %s\n", i+1, pszProblem); hy_free(pszProblem); pszProblem = NULL; diff --git a/client/init.c b/client/init.c index ebf574d8..b0da9009 100644 --- a/client/init.c +++ b/client/init.c @@ -155,3 +155,85 @@ TDNFCloneCmdArgs( goto cleanup; } +uint32_t +TDNFRefreshSack( + PTDNF pTdnf, + int nCleanMetadata + ) +{ + uint32_t dwError = 0; + HyRepo hRepo = NULL; + int nYumFlags = HY_LOAD_FILELISTS | HY_LOAD_UPDATEINFO; + + if(!pTdnf) + { + dwError = ERROR_TDNF_INVALID_PARAMETER; + BAIL_ON_TDNF_ERROR(dwError); + } + + if(pTdnf->hSack) + { + hy_sack_free(pTdnf->hSack); + pTdnf->hSack = NULL; + } + + dwError = TDNFInitSack(pTdnf, &pTdnf->hSack, HY_LOAD_FILELISTS); + BAIL_ON_TDNF_ERROR(dwError); + + //If there is an empty repo directory, do nothing + if(pTdnf->pRepos) + { + PTDNF_REPO_DATA pTempRepo = pTdnf->pRepos; + while(pTempRepo) + { + if(pTempRepo->nEnabled) + { + if(nCleanMetadata) + { + fprintf(stdout, + "Refreshing metadata for: '%s'\n", + pTempRepo->pszName); + dwError = TDNFRepoRemoveCache(pTdnf, pTempRepo->pszId); + if(dwError == ERROR_TDNF_FILE_NOT_FOUND) + { + dwError = 0;//Ignore non existent folders + } + BAIL_ON_TDNF_ERROR(dwError); + } + + dwError = TDNFInitRepo(pTdnf, pTempRepo, &hRepo); + if(dwError) + { + if(pTempRepo->nSkipIfUnavailable) + { + pTempRepo->nEnabled = 0; + fprintf(stdout, "Disabling Repo: '%s'\n", pTempRepo->pszName); + + dwError = 0; + } + } + BAIL_ON_TDNF_ERROR(dwError); + + if(pTempRepo->nEnabled) + { + if(pTempRepo->hRepo) + { + hy_repo_free(pTempRepo->hRepo); + pTempRepo->hRepo = NULL; + } + pTempRepo->hRepo = hRepo; + + dwError = TDNFLoadYumRepo(pTdnf->hSack, hRepo, nYumFlags); + BAIL_ON_TDNF_ERROR(dwError); + } + } + pTempRepo = pTempRepo->pNext; + } + } + +cleanup: + return dwError; + +error: + goto cleanup; +} diff --git a/client/makecache.c b/client/makecache.c deleted file mode 100644 index db9a10b8..00000000 --- a/client/makecache.c +++ /dev/null @@ -1,85 +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 : makecache.c - * - * Abstract : - * - * tdnfclientlib - * - * client library - * - * Authors : Priyesh Padmavilasom (ppadmavilasom@vmware.com) - */ - -#include "includes.h" - - -uint32_t -TDNFRefreshCache( - PTDNF pTdnf - ) -{ - uint32_t dwError = 0; - HySack hSack = NULL; - - if(!pTdnf) - { - dwError = ERROR_TDNF_INVALID_PARAMETER; - BAIL_ON_TDNF_ERROR(dwError); - } - - //Creating a new sack without removing the - //old one did not work well. Remove first, then - //create - if(pTdnf->hSack) - { - hy_sack_free(pTdnf->hSack); - pTdnf->hSack = NULL; - } - - //init with cache - dwError = TDNFInitSack(pTdnf, &hSack, HY_LOAD_FILELISTS); - BAIL_ON_TDNF_ERROR(dwError); - - //Do the same for all enabled repos - if(pTdnf->pRepos) - { - PTDNF_REPO_DATA pRepo = pTdnf->pRepos; - while(pRepo) - { - if(pRepo->nEnabled) - { - hy_repo_free(pRepo->hRepo); - pRepo->hRepo = NULL; - - dwError = TDNFInitRepo(pTdnf, pRepo, &pRepo->hRepo); - BAIL_ON_TDNF_ERROR(dwError); - } - pRepo = pRepo->pNext; - } - } - - pTdnf->hSack = hSack; - -cleanup: - return dwError; - -error: - if(hSack) - { - hy_sack_free(hSack); - } - if(pTdnf->hSack) - { - hy_sack_free(pTdnf->hSack); - pTdnf->hSack = NULL; - } - goto cleanup; -} diff --git a/client/prototypes.h b/client/prototypes.h index 33aa8ba4..62fdfde1 100644 --- a/client/prototypes.h +++ b/client/prototypes.h @@ -100,6 +100,12 @@ TDNFLoadYumRepo( int nFlags ); +uint32_t +TDNFRefreshSack( + PTDNF pTdnf, + int nCleanMetadata + ); + //makecache.c uint32_t TDNFRefreshCache( diff --git a/client/repo.c b/client/repo.c index 4b5c7ee6..ddaf8357 100644 --- a/client/repo.c +++ b/client/repo.c @@ -340,8 +340,13 @@ TDNFGetGPGCheck( if(pRepo) { nGPGCheck = pRepo->nGPGCheck; - dwError = TDNFAllocateString(pRepo->pszUrlGPGKey, &pszUrlGPGKey); - BAIL_ON_TDNF_ERROR(dwError); + if(nGPGCheck) + { + dwError = TDNFAllocateString( + pRepo->pszUrlGPGKey, + &pszUrlGPGKey); + BAIL_ON_TDNF_ERROR(dwError); + } } } diff --git a/client/repoutils.c b/client/repoutils.c index 6cc104d0..2f8e6538 100644 --- a/client/repoutils.c +++ b/client/repoutils.c @@ -239,6 +239,11 @@ TDNFRepoRemoveCache( dwError = errno; BAIL_ON_TDNF_SYSTEM_ERROR(dwError); } + if(pszFilePath) + { + g_free(pszFilePath); + pszFilePath = NULL; + } } if(rmdir(pszRepoCacheDir)) { @@ -255,6 +260,10 @@ TDNFRepoRemoveCache( { g_free(pszRepoCacheDir); } + if(pDir) + { + g_dir_close(pDir); + } return dwError; error: diff --git a/configure.ac b/configure.ac index c47f4793..be4bb601 100644 --- a/configure.ac +++ b/configure.ac @@ -1,4 +1,4 @@ -AC_INIT(tdnf, 1.0.2) +AC_INIT(tdnf, 1.0.3) AC_MSG_NOTICE([tdnf configuration]) AC_CANONICAL_SYSTEM diff --git a/tools/cli/main.c b/tools/cli/main.c index a57009a3..f2551f70 100644 --- a/tools/cli/main.c +++ b/tools/cli/main.c @@ -78,6 +78,11 @@ int main(int argc, char* argv[]) { nFound = 1; + if(!strcmp(pszCmd, "makecache")) + { + pCmdArgs->nRefresh = 1; + } + dwError = TDNFOpenHandle(pCmdArgs, &pTdnf); BAIL_ON_CLI_ERROR(dwError); @@ -515,8 +520,8 @@ TDNFCliMakeCacheCommand( dwError = ERROR_TDNF_CLI_INVALID_ARGUMENT; BAIL_ON_CLI_ERROR(dwError); } - dwError = TDNFMakeCache(pTdnf); - BAIL_ON_CLI_ERROR(dwError); + //Empty as refresh flag is set for makecache command + //and will execute refresh on all enabled repos fprintf(stdout, "Metadata cache created.\n");