Skip to content

Commit

Permalink
fix bug in upgrade and downgrade by version
Browse files Browse the repository at this point in the history
Change-Id: I0c7c442e72bf5eec7e6cf28c2b09797c90929bac
  • Loading branch information
ppadmavilasom committed May 20, 2016
1 parent 6924599 commit 4a8985d
Show file tree
Hide file tree
Showing 15 changed files with 265 additions and 17 deletions.
1 change: 1 addition & 0 deletions client/defines.h
Original file line number Diff line number Diff line change
Expand Up @@ -192,4 +192,5 @@ typedef enum
{ERROR_TDNF_RPM_GPG_PARSE_FAILED,"ERROR_TDNF_RPM_GPG_PARSE_FAILED","RPM failed to parse gpg key. Use --nogpgcheck to ignore."}, \
{ERROR_TDNF_RPM_GPG_NO_MATCH, "ERROR_TDNF_RPM_GPG_NO_MATCH", "RPM is signed but failed to match with known keys. Use --nogpgcheck to ignore."}, \
{ERROR_TDNF_AUTOERASE_UNSUPPORTED,"ERROR_TDNF_AUTOERASE_UNSUPPORTED","autoerase / autoremove is not supported."}, \
{ERROR_TDNF_RPM_CHECK, "ERROR_TDNF_RPM_CHECK", "rpm check reported errors"}, \
};
15 changes: 12 additions & 3 deletions client/goal.c
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ TDNFAddGoal(
{
uint32_t dwError = 0;
HySelector hSelector = NULL;
const char* pszPkg = NULL;
char* pszPkg = NULL;

if(!hGoal || !hPkg)
{
Expand All @@ -149,8 +149,13 @@ TDNFAddGoal(
BAIL_ON_TDNF_HAWKEY_ERROR(dwError);
break;
case ALTER_UPGRADE:
pszPkg = hy_package_get_name(hPkg);
TDNFGetSelector(pTdnf, pszPkg, &hSelector);
pszPkg = hy_package_get_nevra(hPkg);
if(IsNullOrEmptyString(pszPkg))
{
dwError = ERROR_TDNF_INVALID_PARAMETER;
BAIL_ON_TDNF_ERROR(dwError);
}
dwError = TDNFGetSelector(pTdnf, pszPkg, &hSelector);
BAIL_ON_TDNF_ERROR(dwError);

dwError = hy_goal_upgrade_to_selector(hGoal, hSelector);
Expand All @@ -165,6 +170,10 @@ TDNFAddGoal(
BAIL_ON_TDNF_ERROR(dwError);
}
cleanup:
if(pszPkg)
{
hy_free(pszPkg);
}
return dwError;

error:
Expand Down
124 changes: 111 additions & 13 deletions client/packageutils.c
Original file line number Diff line number Diff line change
Expand Up @@ -747,7 +747,7 @@ TDNFPackageGetDowngrade(

if(!hPkgDowngrade)
{
dwError = ERROR_TDNF_NO_DOWNGRADES;
dwError = ERROR_TDNF_NO_DOWNGRADE_PATH;
BAIL_ON_TDNF_ERROR(dwError);
}

Expand Down Expand Up @@ -913,18 +913,63 @@ TDNFAddPackagesForInstall(
goto cleanup;
}

uint32_t
TDNFFindInstalledPkgByPkg(
HySack hSack,
HyPackage hPkgToFind,
HyPackage* phPkg
)
{
uint32_t dwError = 0;
HyPackage hPkg = NULL;
const char* pszPkgName = NULL;

if(!hSack || !hPkgToFind || !phPkg)
{
dwError = ERROR_TDNF_INVALID_PARAMETER;
BAIL_ON_TDNF_ERROR(dwError);
}

pszPkgName = hy_package_get_name(hPkgToFind);
if(IsNullOrEmptyString(pszPkgName))
{
dwError = ERROR_TDNF_INVALID_PARAMETER;
BAIL_ON_TDNF_ERROR(dwError);
}

dwError = TDNFFindInstalledPkgByName(
hSack,
pszPkgName,
&hPkg);
BAIL_ON_TDNF_ERROR(dwError);

*phPkg = hPkg;

cleanup:
return dwError;

error:
if(phPkg)
{
*phPkg = NULL;
}
goto cleanup;
}

uint32_t
TDNFAddPackagesForUpgrade(
HySack hSack,
HyPackageList hPkgListSource,
HyPackageList hPkgListGoal
)
{
uint32_t dwError = 0;
HyPackage hPkg = NULL;
HyPackage hPkgTemp = NULL;
HyPackage hPkgInstalled = NULL;
int i = 0;

if(!hPkgListSource || !hPkgListGoal)
if(!hSack || !hPkgListSource || !hPkgListGoal)
{
dwError = ERROR_TDNF_INVALID_PARAMETER;
BAIL_ON_TDNF_ERROR(dwError);
Expand All @@ -939,35 +984,64 @@ TDNFAddPackagesForUpgrade(
}
}

if(hPkg == NULL)
if(hPkg != NULL)
{
dwError = ERROR_TDNF_NO_SEARCH_RESULTS;
dwError = TDNFPackageGetLatest(hPkgListSource, &hPkgTemp);
BAIL_ON_TDNF_ERROR(dwError);
}
else
{
hPkgTemp = hy_packagelist_get(hPkgListSource, 0);
//this could be instruction to upgrade to a specific
//version so find out which version is installed.
dwError = TDNFFindInstalledPkgByPkg(
hSack,
hPkgTemp,
&hPkgInstalled);
BAIL_ON_TDNF_ERROR(dwError);

dwError = TDNFPackageGetLatest(hPkgListSource, &hPkgTemp);
BAIL_ON_TDNF_ERROR(dwError);
//If installed pkg is newer than the upgrade dest,
//there is no upgrade path
if(hy_package_cmp(hPkgInstalled, hPkgTemp) > 0)
{
hPkgTemp = NULL;
dwError = ERROR_TDNF_NO_UPGRADE_PATH;
BAIL_ON_TDNF_ERROR(dwError);
}
}

if(!hPkgTemp)
{
dwError = ERROR_TDNF_INVALID_PARAMETER;
BAIL_ON_TDNF_ERROR(dwError);
}

hy_packagelist_push(hPkgListGoal, hPkgTemp);

cleanup:
if(hPkgInstalled)
{
hy_package_free(hPkgInstalled);
}
return dwError;
error:
goto cleanup;
}

uint32_t
TDNFAddPackagesForDowngrade(
HySack hSack,
HyPackageList hPkgListSource,
HyPackageList hPkgListGoal
)
{
uint32_t dwError = 0;
HyPackage hPkg = NULL;
HyPackage hPkgTemp = NULL;
HyPackage hPkgInstalled = NULL;
int i = 0;

if(!hPkgListSource || !hPkgListGoal)
if(!hSack || !hPkgListSource || !hPkgListGoal)
{
dwError = ERROR_TDNF_INVALID_PARAMETER;
BAIL_ON_TDNF_ERROR(dwError);
Expand All @@ -980,22 +1054,46 @@ TDNFAddPackagesForDowngrade(
break;
}
}
if(hPkg == NULL)

if(hPkg != NULL)
{
dwError = ERROR_TDNF_NO_SEARCH_RESULTS;
dwError = TDNFPackageGetDowngrade(hPkgListSource, hPkg, &hPkgTemp);
BAIL_ON_TDNF_ERROR(dwError);
}
else
{
hPkgTemp = hy_packagelist_get(hPkgListSource, 0);
//this could be instruction to downgrade to a specific
//version so find out which version is installed.
dwError = TDNFFindInstalledPkgByPkg(
hSack,
hPkgTemp,
&hPkgInstalled);
BAIL_ON_TDNF_ERROR(dwError);

dwError = TDNFPackageGetDowngrade(hPkgListSource, hPkg, &hPkgTemp);
if(dwError == ERROR_TDNF_NO_DOWNGRADES)
//If installed pkg is lesser than the downgrade dest,
//there is no downgrade path
if(hy_package_cmp(hPkgInstalled, hPkgTemp) < 0)
{
hPkgTemp = NULL;
dwError = ERROR_TDNF_NO_DOWNGRADE_PATH;
BAIL_ON_TDNF_ERROR(dwError);
}
}

if(!hPkgTemp)
{
dwError = ERROR_TDNF_NO_SEARCH_RESULTS;
dwError = ERROR_TDNF_INVALID_PARAMETER;
BAIL_ON_TDNF_ERROR(dwError);
}
BAIL_ON_TDNF_ERROR(dwError);

hy_packagelist_push(hPkgListGoal, hPkgTemp);

cleanup:
if(hPkgInstalled)
{
hy_package_free(hPkgInstalled);
}
return dwError;

error:
Expand Down
9 changes: 9 additions & 0 deletions client/prototypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,13 @@ TDNFFindInstalledPkgByName(
HyPackage* phPkg
);

uint32_t
TDNFFindInstalledPkgByPkg(
HySack hSack,
HyPackage hPkgToFind,
HyPackage* phPkg
);

uint32_t
TDNFGetInstalled(
HySack hSack,
Expand Down Expand Up @@ -253,12 +260,14 @@ TDNFAddPackagesForInstall(

uint32_t
TDNFAddPackagesForUpgrade(
HySack hSack,
HyPackageList hPkgListSource,
HyPackageList hPkgListGoal
);

uint32_t
TDNFAddPackagesForDowngrade(
HySack hSack,
HyPackageList hPkgListSource,
HyPackageList hPkgListGoal
);
Expand Down
12 changes: 12 additions & 0 deletions client/resolve.c
Original file line number Diff line number Diff line change
Expand Up @@ -529,6 +529,7 @@ TDNFPrepareSinglePkg(
else if (nAlterType == ALTER_UPGRADE)
{
dwError = TDNFAddPackagesForUpgrade(
pTdnf->hSack,
hPkgListGoalTemp,
hPkgListGoal);
BAIL_ON_TDNF_ERROR(dwError);
Expand All @@ -537,6 +538,7 @@ TDNFPrepareSinglePkg(
nAlterType == ALTER_DOWNGRADEALL)
{
dwError = TDNFAddPackagesForDowngrade(
pTdnf->hSack,
hPkgListGoalTemp,
hPkgListGoal);
BAIL_ON_TDNF_ERROR(dwError);
Expand Down Expand Up @@ -567,6 +569,16 @@ TDNFPrepareSinglePkg(
return dwError;

error:
if(dwError == ERROR_TDNF_NO_UPGRADE_PATH)
{
dwError = 0;
fprintf(stderr, "There is no upgrade path for %s.\n", pszPkgName);
}
if(dwError == ERROR_TDNF_NO_DOWNGRADE_PATH)
{
dwError = 0;
fprintf(stderr, "There is no downgrade path for %s.\n", pszPkgName);
}
if(dwError == ERROR_TDNF_NO_SEARCH_RESULTS)
{
dwError = 0;
Expand Down
1 change: 1 addition & 0 deletions client/rpmtrans.c
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,7 @@ doCheck(PTDNFRPMTS pTS)
rpmProblemFree(prob);
}
rpmpsFreeIterator(psi);
nResult = ERROR_TDNF_RPM_CHECK;
}
}
return nResult;
Expand Down
3 changes: 3 additions & 0 deletions include/tdnferror.h
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,9 @@ extern "C" {
#define ERROR_TDNF_RPM_GET_RSAHEADER_FAILED 1512
#define ERROR_TDNF_RPM_GPG_PARSE_FAILED 1513
#define ERROR_TDNF_RPM_GPG_NO_MATCH 1514
#define ERROR_TDNF_RPM_CHECK 1515
#define ERROR_TDNF_NO_UPGRADE_PATH 1516
#define ERROR_TDNF_NO_DOWNGRADE_PATH 1517

//RPM Transaction
#define ERROR_TDNF_TRANS_INCOMPLETE 1525
Expand Down
4 changes: 4 additions & 0 deletions tests/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ EXTRA_DIST = init.at $(srcdir)/package.m4 $(TESTSUITE)
TESTSUITE_AT = testsuite.at
TESTSUITE_AT += version.at
TESTSUITE_AT += list.at
TESTSUITE_AT += install.at
TESTSUITE_AT += erase.at
TESTSUITE_AT += update.at
TESTSUITE_AT += downgrade.at
EXTRA_DIST += $(TESTSUITE_AT)

DISTCLEANFILES = atconfig testsuite
Expand Down
34 changes: 34 additions & 0 deletions tests/downgrade.at
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#
# Copyright (C) 2015 VMware, Inc. All Rights Reserved.
#
# Licensed under the GNU Lesser General Public License v2.1 (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.
#

AT_BANNER(tdnf downgrade tests)

AT_SETUP([downgrade check])
AT_KEYWORDS([downgrade])
AT_CHECK([
TDNF_CHROOT_CLEAN
TDNF_CHROOT_INIT
TDNF_BUILD_INSTALL_RPMS
TDNF_CLI_W_CHROOT install tdnf-test-multiversion -y
TDNF_CLI_W_CHROOT downgrade -y
],
[0],
[ignore],
[ignore])
AT_CLEANUP

AT_SETUP([downgrade by version])
AT_KEYWORDS([downgrade])
AT_CHECK([
TDNF_CLI_W_CHROOT install tdnf-test-multiversion -y
TDNF_CLI_W_CHROOT downgrade tdnf-test-multiversion-1.0.1 -y
],
[0],
[ignore],
[ignore])
AT_CLEANUP
2 changes: 1 addition & 1 deletion tests/init.at
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ EOF
]])

m4_define([TDNF_BUILD_INSTALL_RPMS],[[
rpmbuild --define "_topdir $abs_top_builddir/tests/testroot" -r $abs_top_builddir/tests/testroot -ba $abs_top_builddir/tests/specs/tdnf-test-one.spec
rpmbuild --define "_topdir $abs_top_builddir/tests/testroot" -r $abs_top_builddir/tests/testroot -ba $abs_top_builddir/tests/specs/*.spec
createrepo $abs_top_builddir/tests/testroot/RPMS
cat << EOF > $abs_top_builddir/tests/testroot/etc/yum.repos.d/basic.repo
[basic]
Expand Down
11 changes: 11 additions & 0 deletions tests/install.at
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,14 @@ TDNF_CLI_W_CHROOT install pkg-not-found
[ignore],
[ignore])
AT_CLEANUP

AT_SETUP([install by version])
AT_KEYWORDS([install])
AT_CHECK([
TDNF_CLI_W_CHROOT install tdnf-test-multiversion-1.0.1 -y
TDNF_CLI_W_CHROOT install tdnf-test-multiversion-1.0.2 -y
],
[0],
[ignore],
[ignore])
AT_CLEANUP
Loading

0 comments on commit 4a8985d

Please sign in to comment.