Skip to content

Commit

Permalink
Retain installonlypkg install status on upgrade
Browse files Browse the repository at this point in the history
  • Loading branch information
sameluch committed Feb 6, 2025
1 parent e602bc9 commit fbbaffa
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 0 deletions.
30 changes: 30 additions & 0 deletions client/goal.c
Original file line number Diff line number Diff line change
Expand Up @@ -754,6 +754,36 @@ TDNFMarkAutoInstalled(
}
}
}
/* During upgrades, ppInfo->pPkgsToInstall contains any packages that are
being installed as a dependency automatically as well as any
ppszInstallOnlyPkgs which are installing a new version. The packages
configured as installonlypkgs need to retain to retain their previous
install status.
*/
if (nFlag == 1 && pTdnf->pConf && pTdnf->pConf->ppszInstallOnlyPkgs)
{
for (int i = 0; pTdnf->pConf->ppszInstallOnlyPkgs[i]; i++)
{
if (strcmp(pTdnf->pConf->ppszInstallOnlyPkgs[i], pszName) == 0)
{
// Lookup current auto install status, ensure matching status
int value = 0;
int rc = history_get_auto_flag(pHistoryCtx, pszName, &value);
if (rc != 0)
{
dwError = ERROR_TDNF_HISTORY_ERROR;
BAIL_ON_TDNF_ERROR(dwError);
}
if (value == 0)
{
// Packages previously marked as user installed should
// remain user installed.
nFlag = 0;
break;
}
}
}
}
if (!nAutoOnly || nFlag == 1)
{
int rc = history_set_auto_flag(pHistoryCtx, pszName, nFlag);
Expand Down
44 changes: 44 additions & 0 deletions pytests/tests/test_multiinstall.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,3 +149,47 @@ def test_install_reinstall(utils):
# both pkgs should remain installed:
assert utils.check_package(pkgname, version=first)
assert utils.check_package(pkgname, version=second)


def test_autoremove_after_upgrade_user_installed(utils):
pkgname = PKGNAME
utils.erase_package(pkgname)

# install first version
first = PKG_VERSIONS[0]
utils.run(['tdnf', 'install', '-y', '--nogpgcheck', f"{pkgname}={first}"])
assert utils.check_package(pkgname, version=first)

# upgrade to latest
upgrade_version = PKG_VERSIONS[3]
utils.run(['tdnf', 'upgrade', '-y', '--nogpgcheck'])
assert utils.check_package(pkgname, version=upgrade_version)

utils.run(['tdnf', 'autoremove', '-y'])
# check both packages remain installed after autoremove
assert utils.check_package(pkgname, version=upgrade_version)
assert utils.check_package(pkgname, version=first)


def test_autoremove_after_upgrade_auto_installed(utils):
pkgname = PKGNAME
utils.erase_package(pkgname)

# install first version
first = PKG_VERSIONS[0]
utils.run(['tdnf', 'install', '-y', '--nogpgcheck', f"{pkgname}={first}"])
assert utils.check_package(pkgname, version=first)

# mark package as autoinstalled
ret = utils.run(['tdnf', 'mark', 'remove', pkgname])
assert ret['retval'] == 0

# upgrade to latest
upgrade_version = PKG_VERSIONS[3]
utils.run(['tdnf', 'upgrade', '-y', '--nogpgcheck'])
assert utils.check_package(pkgname, version=upgrade_version)

utils.run(['tdnf', 'autoremove', '-y'])
# check both packages remain installed after autoremove
assert not utils.check_package(pkgname, version=upgrade_version)
assert not utils.check_package(pkgname, version=first)

0 comments on commit fbbaffa

Please sign in to comment.