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 28, 2023
1 parent ed235f7 commit 45b547d
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 2 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: 18 additions & 1 deletion client/repolist.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ TDNFLoadRepoData(
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 Down Expand Up @@ -115,12 +117,27 @@ TDNFLoadRepoData(

TDNF_SAFE_FREE_MEMORY(pszRepoFilePath);
pszRepoFilePath = NULL;

/* may have added multiple repos, go to last one */
while (*ppRepoNext)
ppRepoNext = &((*ppRepoNext)->pNext);
}

pRepoParsePre = pReposAll;

while (pRepoParsePre != NULL && pRepoParsePre->pNext != NULL) {
pRepoParseNext = pRepoParsePre;

while (pRepoParseNext->pNext != NULL) {
if (!strcmp(pRepoParsePre->pszId, pRepoParseNext->pNext->pszId)) {
dwError = ERROR_TDNF_DUPLICATE_REPO_ID;
BAIL_ON_TDNF_ERROR(dwError);
}
else
pRepoParseNext = pRepoParseNext->pNext;
}
pRepoParsePre = pRepoParsePre->pNext;
}

*ppReposAll = pReposAll;
cleanup:
if(pDir)
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
2 changes: 1 addition & 1 deletion pytests/tests/test_baseurls.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def teardown_test(utils):


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

Expand Down
34 changes: 34 additions & 0 deletions pytests/tests/test_repolist.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ def setup_test(utils):
def teardown_test(utils):
os.remove(os.path.join(utils.config['repo_path'], 'yum.repos.d', 'foo.repo'))
os.remove(os.path.join(utils.config['repo_path'], 'yum.repos.d', 'bar.repo'))
os.remove(os.path.join(utils.config['repo_path'], "yum.repos.d", 'test.repo'))
os.remove(os.path.join(utils.config['repo_path'], "yum.repos.d", 'test1.repo'))


def find_repo(repolist, id):
Expand Down Expand Up @@ -126,3 +128,35 @@ def test_repolist_invalid(utils):
def test_repolist_memcheck(utils):
ret = utils.run_memcheck(['tdnf', 'repolist'])
assert ret['retval'] == 0


# multiple repoid
def test_multiple_repoid(utils):
reponame = 'test.repo'
repofile_test = os.path.join(utils.config['repo_path'], 'yum.repos.d', reponame)
utils.edit_config(
{
'name': 'Test Repo',
'enabled': '1',
'baseurl': 'http://pkgs.test.org/test'
},
section='test',
filename=repofile_test
)

reponame = 'test1.repo'
repofile_test1 = os.path.join(utils.config['repo_path'], 'yum.repos.d', reponame)
utils.edit_config(
{
'name': 'Test Repo',
'enabled': '1',
'baseurl': 'http://pkgs.test1.org/test1'
},
section='test',
filename=repofile_test1
)

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

0 comments on commit 45b547d

Please sign in to comment.