Skip to content

Commit

Permalink
Merge pull request #457 from oliverkurth/topic/okurth/stable-3.5.6
Browse files Browse the repository at this point in the history
version 3.5.6
  • Loading branch information
oliverkurth authored Dec 12, 2023
2 parents 98de0bc + 802514c commit e1f4e0a
Show file tree
Hide file tree
Showing 14 changed files with 131 additions and 9 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

CMAKE_MINIMUM_REQUIRED(VERSION 3.0 FATAL_ERROR)

project(tdnf VERSION 3.5.5 LANGUAGES C)
project(tdnf VERSION 3.5.6 LANGUAGES C)
set(VERSION ${PROJECT_VERSION})
set(PROJECT_YEAR 2023)

Expand Down
10 changes: 10 additions & 0 deletions client/api.c
Original file line number Diff line number Diff line change
Expand Up @@ -617,6 +617,7 @@ TDNFOpenHandle(
char *pszCacheDir = NULL;
char *pszRepoDir = NULL;
int nHasOptReposdir = 0;
PTDNF_CMD_OPT pOpt = NULL;

if(!pArgs || !ppTdnf)
{
Expand Down Expand Up @@ -694,6 +695,15 @@ TDNFOpenHandle(
BAIL_ON_TDNF_ERROR(dwError);
}

/* set macros from command line */
for (pOpt = pTdnf->pArgs->pSetOpt; pOpt; pOpt = pOpt->pNext)
{
if (strcmp(pOpt->pszOptName, "rpmdefine") == 0)
{
rpmDefineMacro(NULL, pOpt->pszOptValue, 0);
}
}

dwError = TDNFLoadPlugins(pTdnf);
BAIL_ON_TDNF_ERROR(dwError);

Expand Down
1 change: 1 addition & 0 deletions client/defines.h
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,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
13 changes: 10 additions & 3 deletions client/packageutils.c
Original file line number Diff line number Diff line change
Expand Up @@ -861,21 +861,28 @@ TDNFGetAvailableCacheBytes(
)
{
uint32_t dwError = 0;
struct statfs tmpStatfsBuffer = {0};
struct statfs stfs = {0};
struct stat st = {0};

if(!pConf || !pConf->pszCacheDir || !pqwAvailCacheDirBytes)
{
dwError = ERROR_TDNF_INVALID_PARAMETER;
BAIL_ON_TDNF_ERROR(dwError);
}

if (statfs(pConf->pszCacheDir, &tmpStatfsBuffer) != 0)
if (stat(pConf->pszCacheDir, &st) != 0) {
/* avoid failure when checking space, and dir doesn't exist */
dwError = TDNFUtilsMakeDirs(pConf->pszCacheDir);
BAIL_ON_TDNF_ERROR(dwError);
}

if (statfs(pConf->pszCacheDir, &stfs) != 0)
{
dwError = errno;
BAIL_ON_TDNF_SYSTEM_ERROR(dwError);
}

*pqwAvailCacheDirBytes = tmpStatfsBuffer.f_bsize * tmpStatfsBuffer.f_bavail;
*pqwAvailCacheDirBytes = stfs.f_bsize * stfs.f_bavail;

cleanup:
return dwError;
Expand Down
2 changes: 1 addition & 1 deletion client/remoterepo.c
Original file line number Diff line number Diff line change
Expand Up @@ -408,7 +408,7 @@ TDNFDownloadPackage(
}
else if(dwError == 0)
{
pr_info("%s package already downloaded", pszPkgName);
pr_info("%s package already downloaded\n", pszPkgName);
}
BAIL_ON_TDNF_ERROR(dwError);

Expand Down
13 changes: 13 additions & 0 deletions client/repolist.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,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 @@ -142,6 +144,17 @@ TDNFLoadRepoData(
ppRepoNext = &((*ppRepoNext)->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);
}
}
}

*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
3 changes: 1 addition & 2 deletions pytests/tests/test_baseurls.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@

WORKDIR = '/root/baseurls/workdir'
REPOFILENAME = 'baseurls.repo'
TESTREPO = 'photon-test'
REPONAME = 'baseurls-repo'


Expand All @@ -33,7 +32,7 @@ def teardown_test(utils):


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

Expand Down
13 changes: 13 additions & 0 deletions pytests/tests/test_cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import os
import fnmatch
import pytest
import shutil


@pytest.fixture(scope='module', autouse=True)
Expand Down Expand Up @@ -203,3 +204,15 @@ def test_cache_directory_out_of_disk_space(utils):
clean_cache(utils)
clean_small_cache(utils)
assert ret['retval'] == 1036


# see https://github.com/vmware/tdnf/pull/454
# tdnf should not fail if cache dir does not exist
def test_cachedir_removed(utils):
pkgname = utils.config["sglversion_pkgname"]
utils.install_package(pkgname)

cache_dir = utils.tdnf_config.get('main', 'cachedir')
shutil.rmtree(cache_dir)
ret = utils.run(["tdnf", "-y", "--disablerepo=*", "remove", pkgname])
assert ret['retval'] == 0
3 changes: 2 additions & 1 deletion pytests/tests/test_installroot.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ def setup_test(utils):
def teardown_test(utils):
if os.path.isdir(INSTALLROOT):
shutil.rmtree(INSTALLROOT)
pass
if os.path.isdir(REPODIR):
shutil.rmtree(REPODIR)


def install_root(utils, no_reposd=False):
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
40 changes: 40 additions & 0 deletions pytests/tests/test_rpmdefine.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#
# Copyright (C) 2023 VMware, Inc. All Rights Reserved.
#
# Licensed under the GNU General Public License v2 (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.
#

import os
import shutil
import pytest


INSTALLROOT = '/root/installroot'
REPOFILENAME = 'photon-test.repo'


@pytest.fixture(scope='function', autouse=True)
def setup_test(utils):
yield
teardown_test(utils)


def teardown_test(utils):
if os.path.isdir(INSTALLROOT):
shutil.rmtree(INSTALLROOT)


@pytest.mark.parametrize("dbpath", ["/usr/lib/rpm", "/usr/lib/sysimage/rpm/"])
def test_install(utils, dbpath):
pkgname = utils.config["mulversion_pkgname"]
ret = utils.run(['tdnf', 'install',
'-y', '--nogpgcheck',
'--installroot', INSTALLROOT,
'--releasever=5.0',
'--rpmdefine', f"_dbpath {dbpath}",
pkgname])
assert ret['retval'] == 0
assert os.path.isdir(os.path.join(INSTALLROOT, dbpath.lstrip("/")))
assert os.path.isfile(os.path.join(INSTALLROOT, dbpath.lstrip("/"), "rpmdb.sqlite"))
3 changes: 2 additions & 1 deletion pytests/tests/test_setopt_reposdir.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
import pytest

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


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'])
1 change: 1 addition & 0 deletions tools/cli/lib/parseargs.c
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ static struct option pstOptions[] =
{"repofrompath", required_argument, 0, 0}, //--repofrompath
{"repoid", required_argument, 0, 0}, //--repoid (same as --repo)
{"rpmverbosity", required_argument, 0, 0}, //--rpmverbosity
{"rpmdefine", required_argument, 0, 0},
{"sec-severity", required_argument, 0, 0}, //--sec-severity
{"security", no_argument, 0, 0}, //--security
{"setopt", required_argument, 0, 0}, //--set or override options
Expand Down

0 comments on commit e1f4e0a

Please sign in to comment.