Skip to content

Commit

Permalink
tdnf: Add check to identify duplicate repo id
Browse files Browse the repository at this point in the history
  • Loading branch information
shivania2 committed Sep 26, 2023
1 parent ed235f7 commit 6e1e544
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 7 deletions.
1 change: 1 addition & 0 deletions client/defines.h
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,7 @@ typedef enum
{ERROR_TDNF_INVALID_INPUT, "ERROR_TDNF_INVALID_INPUT", "Invalid input."},\
{ERROR_TDNF_CACHE_DISABLED, "ERROR_TDNF_CACHE_DISABLED", "cache only is set, but no repo data found"},\
{ERROR_TDNF_CACHE_DIR_OUT_OF_DISK_SPACE, "ERROR_TDNF_CACHE_DIR_OUT_OF_DISK_SPACE", "Insufficient disk space at cache directory /var/cache/tdnf (unless specified differently in config). Try freeing space first."},\
{ERROR_TDNF_DUPLICATE_REPO_ID, "ERROR_TDNF_DUPLICATE_REPO_ID", "Duplicate repo id"}, \
{ERROR_TDNF_EVENT_CTXT_ITEM_NOT_FOUND, "ERROR_TDNF_EVENT_CTXT_ITEM_NOT_FOUND", "An event context item was not found. This is usually related to plugin events. Try --noplugins to deactivate all plugins or --disableplugin=<plugin> to deactivate a specific one. You can permanently deactivate an offending plugin by setting enable=0 in the plugin config file."},\
{ERROR_TDNF_EVENT_CTXT_ITEM_INVALID_TYPE, "ERROR_TDNF_EVENT_CTXT_ITEM_INVALID_TYPE", "An event item type had a mismatch. This is usually related to plugin events. Try --noplugins to deactivate all plugins or --disableplugin=<plugin> to deactivate a specific one. You can permanently deactivate an offending plugin by setting enable=0 in the plugin config file."},\
{ERROR_TDNF_NO_GPGKEY_CONF_ENTRY, "ERROR_TDNF_NO_GPGKEY_CONF_ENTRY", "gpgkey entry is missing for this repo. please add gpgkey in repo file or use --nogpgcheck to ignore."}, \
Expand Down
19 changes: 13 additions & 6 deletions client/repoutils.c
Original file line number Diff line number Diff line change
Expand Up @@ -541,7 +541,9 @@ TDNFFindRepoById(
)
{
uint32_t dwError = 0;
PTDNF_REPO_DATA parse_pRepos = NULL;
PTDNF_REPO_DATA pRepos = NULL;
int nFound = 0;

if(!pTdnf || IsNullOrEmptyString(pszRepo))
{
Expand All @@ -553,18 +555,23 @@ TDNFFindRepoById(
dwError = ERROR_TDNF_NO_REPOS;
BAIL_ON_TDNF_ERROR(dwError);
}
pRepos = pTdnf->pRepos;
parse_pRepos = pTdnf->pRepos;

while(pRepos)
while(parse_pRepos)
{
if(!strcmp(pszRepo, pRepos->pszId))
if(!strcmp(pszRepo, parse_pRepos->pszId) && nFound == 0)
{
break;
nFound = 1;
pRepos = parse_pRepos;
} else if(!strcmp(pszRepo, parse_pRepos->pszId) && nFound == 1)
{
dwError = ERROR_TDNF_DUPLICATE_REPO_ID;
BAIL_ON_TDNF_ERROR(dwError);
}
pRepos = pRepos->pNext;
parse_pRepos = parse_pRepos->pNext;
}

if(!pRepos)
if(nFound == 0)
{
dwError = ERROR_TDNF_REPO_NOT_FOUND;
BAIL_ON_TDNF_ERROR(dwError);
Expand Down
2 changes: 2 additions & 0 deletions include/tdnferror.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@ extern "C" {
#define ERROR_TDNF_DOWNGRADE_NOT_ALLOWED 1035
// cache directory out of memory
#define ERROR_TDNF_CACHE_DIR_OUT_OF_DISK_SPACE 1036
// There are duplicate repo id
#define ERROR_TDNF_DUPLICATE_REPO_ID 1037

//curl errors
#define ERROR_TDNF_CURL_INIT 1200
Expand Down
28 changes: 27 additions & 1 deletion pytests/tests/test_baseurls.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,37 @@ def teardown_test(utils):
os.remove(filename)


def test_multiple_baseurls(utils):
def test_multiple_repoid(utils):
reponame = TESTREPO
workdir = WORKDIR
utils.makedirs(workdir)

filename = os.path.join(utils.config['repo_path'], "yum.repos.d", REPOFILENAME)

baseurls = "http://localhost:8080/photon-test"
utils.create_repoconf(filename, baseurls, reponame)

ret = utils.run(['tdnf',
'--disablerepo=*', '--enablerepo={}'.format(reponame),
'makecache'],
cwd=workdir)
assert ret['retval'] == 0

pkgname = utils.config["mulversion_pkgname"]
utils.erase_package(pkgname)
ret = utils.run(['tdnf',
'-y', '--nogpgcheck',
'--disablerepo=*', '--enablerepo={}'.format(reponame),
'install', pkgname],
cwd=workdir)
assert ret['retval'] == 1037


def test_multiple_baseurls(utils):
reponame = REPONAME
workdir = WORKDIR
utils.makedirs(workdir)

filename = os.path.join(utils.config['repo_path'], "yum.repos.d", REPOFILENAME)
# we should get a 404 for the first url and skip to the next one
baseurls = "http://localhost:8080/doesntexist http://localhost:8080/photon-test"
Expand Down

0 comments on commit 6e1e544

Please sign in to comment.