Skip to content

Commit

Permalink
Merge pull request #465 from oliverkurth/topic/okurth/stable-3.3/fix-…
Browse files Browse the repository at this point in the history
…multiple-repofrompath

fix multiple --repofrompath options
  • Loading branch information
oliverkurth authored Feb 29, 2024
2 parents ab710b5 + 09f7e9a commit b96b505
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 24 deletions.
52 changes: 30 additions & 22 deletions client/repolist.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,14 @@ TDNFLoadRepoData(
uint32_t dwError = 0;
char* pszRepoFilePath = NULL;
PTDNF_REPO_DATA pReposAll = NULL;
PTDNF_REPO_DATA pReposTemp = NULL;
PTDNF_REPO_DATA pRepos = NULL;
PTDNF_REPO_DATA *ppRepoNext = NULL;
PTDNF_CONF pConf = NULL;
PTDNF_CMD_OPT pSetOpt = NULL;
DIR *pDir = NULL;
struct dirent *pEnt = NULL;
char **ppszUrlIdTuple = NULL;
PTDNF_REPO_DATA pRepoParsePre = NULL;
PTDNF_REPO_DATA pRepoParseNext = NULL;

if(!pTdnf || !pTdnf->pConf || !pTdnf->pArgs || !ppReposAll)
{
Expand All @@ -46,26 +47,34 @@ TDNFLoadRepoData(
}
pConf = pTdnf->pConf;

dwError = TDNFCreateCmdLineRepo(&pReposAll);
ppRepoNext = &pReposAll;

dwError = TDNFCreateCmdLineRepo(ppRepoNext);
BAIL_ON_TDNF_ERROR(dwError);

ppRepoNext = &((*ppRepoNext)->pNext);

for(pSetOpt = pTdnf->pArgs->pSetOpt;
pSetOpt;
pSetOpt = pSetOpt->pNext)
{
if(strcmp(pSetOpt->pszOptName, "repofrompath") == 0)
{
TDNFSplitStringToArray(pSetOpt->pszOptValue, ",", &ppszUrlIdTuple);
dwError = TDNFSplitStringToArray(pSetOpt->pszOptValue, ",", &ppszUrlIdTuple);
BAIL_ON_TDNF_ERROR(dwError);
if ((ppszUrlIdTuple[0] == NULL) || ppszUrlIdTuple[1] == NULL)
{
dwError = ERROR_TDNF_INVALID_PARAMETER;
BAIL_ON_TDNF_ERROR(dwError);
}
dwError = TDNFCreateRepoFromPath(&pReposAll,

dwError = TDNFCreateRepoFromPath(ppRepoNext,
ppszUrlIdTuple[0],
ppszUrlIdTuple[1]);
BAIL_ON_TDNF_ERROR(dwError);

ppRepoNext = &((*ppRepoNext)->pNext);

TDNF_SAFE_FREE_STRINGARRAY(ppszUrlIdTuple);
ppszUrlIdTuple = NULL;
}
Expand Down Expand Up @@ -95,34 +104,33 @@ TDNFLoadRepoData(
NULL);
BAIL_ON_TDNF_ERROR(dwError);

dwError = TDNFLoadReposFromFile(pTdnf, pszRepoFilePath, &pRepos);
dwError = TDNFLoadReposFromFile(pTdnf, pszRepoFilePath, ppRepoNext);
BAIL_ON_TDNF_ERROR(dwError);

TDNF_SAFE_FREE_MEMORY(pszRepoFilePath);
pszRepoFilePath = NULL;

//Apply filter
if((nFilter == REPOLISTFILTER_ENABLED && !pRepos->nEnabled) ||
(nFilter == REPOLISTFILTER_DISABLED && pRepos->nEnabled))
if((nFilter == REPOLISTFILTER_ENABLED && !(*ppRepoNext)->nEnabled) ||
(nFilter == REPOLISTFILTER_DISABLED && (*ppRepoNext)->nEnabled))
{
TDNFFreeReposInternal(pRepos);
pRepos = NULL;
TDNFFreeReposInternal(*ppRepoNext);
*ppRepoNext = NULL;
continue;
}
/* may habe added multiple repos, go to last one */
while (*ppRepoNext)
ppRepoNext = &((*ppRepoNext)->pNext);
}

if(!pReposAll)
{
pReposAll = pRepos;
}
else
{
pReposTemp = pReposAll;
while(pReposAll->pNext)
{
pReposAll = pReposAll->pNext;
for (pRepoParsePre = pReposAll; pRepoParsePre; pRepoParsePre = pRepoParsePre->pNext) {

for (pRepoParseNext = pRepoParsePre->pNext; pRepoParseNext; pRepoParseNext = pRepoParseNext->pNext) {
if (!strcmp(pRepoParsePre->pszId, pRepoParseNext->pszId)) {
pr_err("ERROR: duplicate repo id: %s\n", pRepoParsePre->pszId);
dwError = ERROR_TDNF_DUPLICATE_REPO_ID;
BAIL_ON_TDNF_ERROR(dwError);
}
pReposAll->pNext = pRepos;
pReposAll = pReposTemp;
}
}

Expand Down
2 changes: 2 additions & 0 deletions include/tdnferror.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@ extern "C" {
// cache only set, but no cache available
#define ERROR_TDNF_CACHE_DISABLED 1034
#define ERROR_TDNF_DOWNGRADE_NOT_ALLOWED 1035
// There are duplicate repo ids
#define ERROR_TDNF_DUPLICATE_REPO_ID 1037

//curl errors
#define ERROR_TDNF_CURL_INIT 1200
Expand Down
19 changes: 19 additions & 0 deletions pytests/tests/test_repofrompath.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,3 +65,22 @@ def test_repofrompath_created_repo(utils):
cwd=workdir)
assert ret['retval'] == 0
assert utils.check_package(pkgname)

empty_repodir = os.path.join(workdir, "empty")
os.makedirs(empty_repodir)
utils.run(["createrepo", empty_repodir])

# test again with an additional but empty repo
# to make sure we can use --repofrompath multiple times
utils.erase_package(pkgname)

ret = utils.run(['tdnf',
'-y', '--nogpgcheck',
'--repofrompath=synced-repo,{}'.format(synced_dir),
'--repofrompath=empty-repo,{}'.format(empty_repodir),
'--repo=synced-repo',
'--repo=empty-repo',
'install', pkgname],
cwd=workdir)
assert ret['retval'] == 0
assert utils.check_package(pkgname)
5 changes: 3 additions & 2 deletions pytests/tests/test_setopt_reposdir.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
import pytest

REPODIR = '/root/yum.repos.d'
REPOFILENAME = 'reposync.repo'
REPONAME = "reposdir-test"
REPOFILENAME = 'setopt.repo'
REPONAME = "setopt-test"


@pytest.fixture(scope='function', autouse=True)
Expand All @@ -32,4 +32,5 @@ def test_setopt_reposdir(utils):
"http://foo.bar.com/packages",
REPONAME)
ret = utils.run(['tdnf', '--setopt=reposdir={}'.format(REPODIR), 'repolist'])
assert ret['retval'] == 0
assert REPONAME in "\n".join(ret['stdout'])

0 comments on commit b96b505

Please sign in to comment.