Skip to content

Commit

Permalink
Merge pull request #433 from oliverkurth/stable-3.5
Browse files Browse the repository at this point in the history
update to 3.5.3
  • Loading branch information
oliverkurth authored Jun 13, 2023
2 parents 476197e + bd269d0 commit 676c901
Show file tree
Hide file tree
Showing 7 changed files with 106 additions and 18 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.2 LANGUAGES C)
project(tdnf VERSION 3.5.3 LANGUAGES C)
set(VERSION ${PROJECT_VERSION})
set(PROJECT_YEAR 2023)

Expand Down
8 changes: 7 additions & 1 deletion client/api.c
Original file line number Diff line number Diff line change
Expand Up @@ -2072,7 +2072,7 @@ TDNFHistoryResolve(
goto cleanup;
case HISTORY_CMD_ROLLBACK:
hd = history_get_delta(ctx, pHistoryArgs->nTo);
hfd = history_get_flags_delta(ctx, ctx->trans_id, pHistoryArgs->nTo - 1);
hfd = history_get_flags_delta(ctx, ctx->trans_id, pHistoryArgs->nTo);
break;
case HISTORY_CMD_UNDO:
hd = history_get_delta_range(ctx, pHistoryArgs->nFrom - 1, pHistoryArgs->nTo);
Expand Down Expand Up @@ -2117,6 +2117,9 @@ TDNFHistoryResolve(
char *pszPkgName = history_get_nevra(hnm, hd->added_ids[i]);
if (pszPkgName)
{
if (strncmp(pszPkgName, "gpg-pubkey-", 11) == 0)
continue;

Queue qResult = {0};
queue_init(&qResult);

Expand Down Expand Up @@ -2163,6 +2166,9 @@ TDNFHistoryResolve(
char *pszPkgName = history_get_nevra(hnm, hd->removed_ids[i]);
if (pszPkgName)
{
if (strncmp(pszPkgName, "gpg-pubkey-", 11) == 0)
continue;

dwError = SolvFindSolvablesByNevraStr(pTdnf->pSack->pPool, pszPkgName, &qErase, SOLV_NEVRA_INSTALLED);
BAIL_ON_TDNF_ERROR(dwError);
}
Expand Down
23 changes: 20 additions & 3 deletions client/goal.c
Original file line number Diff line number Diff line change
Expand Up @@ -1090,9 +1090,26 @@ TDNFSolvAddProtectPkgs(
break;
}
if (i < qPkgs.count) {
pr_err("package %s is protected\n", ppszProtectedPkgs[i]);
dwError = ERROR_TDNF_PROTECTED;
BAIL_ON_TDNF_ERROR(dwError);
const char *pszPkgName = ppszProtectedPkgs[i];
/* if this is a history transaction,
we may add it again (with another version) */
for (i = 0; i < pQueueJobs->count; i += 2) {
if (i == j)
continue;
Id how = pQueueJobs->elements[i];
if (((how & SOLVER_JOBMASK) == SOLVER_INSTALL) && (how & SOLVER_SOLVABLE)) {
Id what_add = pQueueJobs->elements[i+1];
Solvable *s_add = pool_id2solvable(pPool, what_add);
if (s_add->name == s->name) {
break;
}
}
}
if (i == pQueueJobs->count) { /* not found in re-adds */
pr_err("package %s is protected\n", pszPkgName);
dwError = ERROR_TDNF_PROTECTED;
BAIL_ON_TDNF_ERROR(dwError);
}
}
}
}
Expand Down
14 changes: 8 additions & 6 deletions client/repo.c
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,14 @@ TDNFInitRepo(
NULL);
BAIL_ON_TDNF_ERROR(dwError);

if (pRepoData->nHasMetaData) {
dwError = TDNFGetRepoMD(pTdnf,
pRepoData,
pszRepoDataDir,
&pRepoMD);
BAIL_ON_TDNF_ERROR(dwError);
}

dwError = TDNFAllocateMemory(
1,
sizeof(SOLV_REPO_INFO_INTERNAL),
Expand All @@ -74,12 +82,6 @@ TDNFInitRepo(
pRepo->appdata = pSolvRepoInfo;

if (pRepoData->nHasMetaData) {
dwError = TDNFGetRepoMD(pTdnf,
pRepoData,
pszRepoDataDir,
&pRepoMD);
BAIL_ON_TDNF_ERROR(dwError);

dwError = SolvCalculateCookieForFile(pRepoMD->pszRepoMD, pSolvRepoInfo->cookie);
BAIL_ON_TDNF_ERROR(dwError);
pSolvRepoInfo->nCookieSet = 1;
Expand Down
33 changes: 32 additions & 1 deletion pytests/tests/test_history.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#

import pytest
import os


@pytest.fixture(scope='function', autouse=True)
Expand Down Expand Up @@ -228,7 +229,7 @@ def test_history_mark(utils):

# redo may pull additional deps if they were already installed
# when the transaction was made, but were removed later. They
# should to be pulled in and marked autoinstalled
# should be pulled in and marked autoinstalled
def test_history_redo_and_autoinstall(utils):
pkgname = 'tdnf-test-cleanreq-leaf1'
pkgname_req = 'tdnf-test-cleanreq-required'
Expand All @@ -255,3 +256,33 @@ def test_history_memcheck(utils):

ret = utils.run_memcheck(['tdnf', 'history', '--info'])
assert ret['retval'] == 0


# ignore gpg-pubkey packages since we cannot revert a removal
def test_history_pubkey_removed(utils):
keypath = os.path.join(utils.config['repo_path'], 'photon-test', 'keys', 'pubkey.asc')
utils.run(['rpm', '--import', keypath])
utils.run(['tdnf', 'history', 'update'])

ret = utils.run(['tdnf', 'history'])
baseline = ret['stdout'][-1].split()[0]

utils.run(['rpm', '-e', '--allmatches', 'gpg-pubkey'])
utils.run(['tdnf', 'history', 'update'])

ret = utils.run(['tdnf', 'history', '-y', 'rollback', '--to', baseline])
assert ret['retval'] == 0


def test_history_pubkey_added(utils):
utils.run(['rpm', '-e', '--allmatches', 'gpg-pubkey'])

ret = utils.run(['tdnf', 'history'])
baseline = ret['stdout'][-1].split()[0]

keypath = os.path.join(utils.config['repo_path'], 'photon-test', 'keys', 'pubkey.asc')
utils.run(['rpm', '--import', keypath])
utils.run(['tdnf', 'history', 'update'])

ret = utils.run(['tdnf', 'history', '-y', 'rollback', '--to', baseline])
assert ret['retval'] == 0
24 changes: 24 additions & 0 deletions pytests/tests/test_protected.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ def teardown_test(utils):

utils.erase_package('tdnf-test-cleanreq-required')
utils.erase_package('tdnf-test-cleanreq-leaf1')
utils.erase_package(utils.config["mulversion_pkgname"])


# helper to create directory tree without complains when it exists:
Expand Down Expand Up @@ -109,3 +110,26 @@ def test_protected_obsoleted(utils):
ret = utils.run(['tdnf', 'install', '-y', '--nogpgcheck', PKGNAME_OBSING])
assert ret['retval'] == 1030
assert utils.check_package(PKGNAME_OBSED)


def test_protected_history_rollback_update(utils):
mpkg = utils.config["mulversion_pkgname"]
mpkg_version = utils.config["mulversion_lower"]

# install lower version
utils.install_package(mpkg, mpkg_version)

# protect it
set_protected_file(utils, mpkg)

# save the history id to roll back to
ret = utils.run(['tdnf', 'history'])
baseline = ret['stdout'][-1].split()[0]

# perform an upgrade
ret = utils.run(['tdnf', 'update', '-y', '--nogpgcheck', mpkg])
assert ret['retval'] == 0

# we should be able to roll it back
ret = utils.run(['tdnf', 'history', '-y', 'rollback', '--to', baseline])
assert ret['retval'] == 0
20 changes: 14 additions & 6 deletions pytests/tests/test_tdnf_python.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,24 @@ def setup_test(utils):
sglpkgname = utils.config['sglversion_pkgname']

global config
config = utils.config['repo_path'] + '/tdnf.conf'
config = os.path.join(utils.config['repo_path'], "tdnf.conf")

if not utils.config.get('installed', False):
path = '{builddir}/python/build/lib.linux-{arch}-{pymajor}.{pyminor}'
# find path to our tdnf python module
builddir = utils.config['build_dir']
arch = os.uname().machine
pymajor = sys.version_info.major
pyminor = sys.version_info.minor

path = path.format(builddir=utils.config['build_dir'],
arch=os.uname().machine,
pymajor=str(sys.version_info.major),
pyminor=str(sys.version_info.minor))
# only support python3
assert pymajor == 3

if pyminor < 11:
path = f"{builddir}/python/build/lib.linux-{arch}-{pymajor}.{pyminor}"
else:
path = f"{builddir}/python/build/lib.linux-{arch}-cpython-{pymajor}{pyminor}"

assert os.path.isdir(path)
sys.path.append(path)

global tdnf
Expand Down

0 comments on commit 676c901

Please sign in to comment.