Skip to content

Commit

Permalink
Merge pull request #346 from oliverkurth/topic/okurth/skip-broken
Browse files Browse the repository at this point in the history
add --skip-broken option
  • Loading branch information
oliverkurth authored Oct 13, 2022
2 parents b3dc18f + 33e5cea commit 562b022
Show file tree
Hide file tree
Showing 9 changed files with 107 additions and 13 deletions.
10 changes: 5 additions & 5 deletions client/api.c
Original file line number Diff line number Diff line change
Expand Up @@ -224,11 +224,6 @@ TDNFGetSkipProblemOption(

*pdwSkipProblem = SKIPPROBLEM_NONE;

if (strcasecmp(pTdnf->pArgs->ppszCmds[0], "check"))
{
goto cleanup;
}

for (pSetOpt = pTdnf->pArgs->pSetOpt; pSetOpt; pSetOpt = pSetOpt->pNext)
{
if (!strcasecmp(pSetOpt->pszOptName, "skipconflicts"))
Expand All @@ -242,6 +237,11 @@ TDNFGetSkipProblemOption(
}
}

if (pTdnf->pArgs->nSkipBroken)
{
*pdwSkipProblem |= SKIPPROBLEM_BROKEN;
}

cleanup:
return dwError;

Expand Down
1 change: 0 additions & 1 deletion client/goal.c
Original file line number Diff line number Diff line change
Expand Up @@ -359,7 +359,6 @@ TDNFSolv(
{
dwError = TDNFGetSkipProblemOption(pTdnf, &dwSkipProblem);
BAIL_ON_TDNF_ERROR(dwError);

dwError = SolvReportProblems(pTdnf->pSack, pSolv, dwSkipProblem);
BAIL_ON_TDNF_ERROR(dwError);
}
Expand Down
1 change: 1 addition & 0 deletions client/init.c
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ TDNFCloneCmdArgs(
pCmdArgs->nNoAutoRemove = pCmdArgsIn->nNoAutoRemove;
pCmdArgs->nJsonOutput = pCmdArgsIn->nJsonOutput;
pCmdArgs->nTestOnly = pCmdArgsIn->nTestOnly;
pCmdArgs->nSkipBroken = pCmdArgsIn->nSkipBroken;

pCmdArgs->nArgc = pCmdArgsIn->nArgc;
pCmdArgs->ppszArgv = pCmdArgsIn->ppszArgv;
Expand Down
6 changes: 5 additions & 1 deletion client/resolve.c
Original file line number Diff line number Diff line change
Expand Up @@ -345,9 +345,13 @@ TDNFPrepareSinglePkg(
if (dwError == ERROR_TDNF_NO_MATCH)
{
pr_err("%s package not found or not installed\n", pszPkgName);
if (pTdnf->pArgs->nSkipBroken)
{
dwError = 0;
}
}

BAIL_ON_TDNF_ERROR(dwError);

if (dwCount == 0)
{
dwError = ERROR_TDNF_NO_SEARCH_RESULTS;
Expand Down
2 changes: 2 additions & 0 deletions include/tdnftypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ typedef enum
SKIPPROBLEM_CONFLICTS = 0x01,
SKIPPROBLEM_OBSOLETES = 0x02,
SKIPPROBLEM_DISABLED = 0x04,
SKIPPROBLEM_BROKEN = 0x08
} TDNF_SKIPPROBLEM_TYPE;

typedef struct _TDNF_ *PTDNF;
Expand Down Expand Up @@ -225,6 +226,7 @@ typedef struct _TDNF_CMD_ARGS
int nNoAutoRemove; //overide clean_requirements_on_remove config option
int nJsonOutput; //output in json format
int nTestOnly; //run test transaction only
int nSkipBroken;
char* pszDownloadDir; //directory for download, if nDownloadOnly is set
char* pszInstallRoot; //set install root
char* pszConfFile; //set conf file location
Expand Down
37 changes: 37 additions & 0 deletions pytests/repo/tdnf-missing-dep.spec
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#
# tdnf-missing spec file
#
Summary: basic install test file.
Name: tdnf-missing-dep
Version: 1.0.1
Release: 2
Vendor: VMware, Inc.
Distribution: Photon
License: VMware
Url: http://www.vmware.com
Group: Applications/tdnftest

# requires something we do not have
Requires: missing

%description
Part of tdnf test spec. Basic install/remove/upgrade test

%prep

%build

%install
mkdir -p %_topdir/%buildroot/lib/systemd/system/
cat << EOF >> %_topdir/%buildroot/lib/systemd/system/%name.service
[Unit]
Description=%name.service for whatprovides test.
EOF

%files
/lib/systemd/system/%name.service

%changelog
* Fri Sep 16 Oliver Kurth <[email protected]> 1.0
- Initial build. First version
44 changes: 44 additions & 0 deletions pytests/tests/test_install.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,50 @@ def test_install_testonly(utils):
assert not utils.check_package(pkgname)


# install multiple packages, one that doesn't exist
# expect other pkg will be installed if invoked with --skip-broken
def test_install_skip_broken_missing_pkg(utils):
pkgname = utils.config["mulversion_pkgname"]
utils.erase_package(pkgname)
pkgname_missing = "missing"

utils.run(['tdnf', 'install', '-y', '--nogpgcheck', '--skip-broken', pkgname, pkgname_missing])
assert utils.check_package(pkgname)


# install multiple packages, one that doesn't exist
# expect fail if invoked without --skip-broken
def test_install_missing_pkg(utils):
pkgname = utils.config["mulversion_pkgname"]
utils.erase_package(pkgname)
pkgname_missing = "missing"

utils.run(['tdnf', 'install', '-y', '--nogpgcheck', pkgname, pkgname_missing])
assert not utils.check_package(pkgname)


# install multiple packages, one with a missing dependency
# expect other pkg will be installed if invoked with --skip-broken
def test_install_skip_broken_missing_dep(utils):
pkgname = utils.config["mulversion_pkgname"]
utils.erase_package(pkgname)
pkgname_missing = "tdnf-missing-dep"

utils.run(['tdnf', 'install', '-y', '--nogpgcheck', '--skip-broken', pkgname, pkgname_missing])
assert utils.check_package(pkgname)


# install multiple packages, one with a missing dependency
# expect fail if invoked without --skip-broken
def test_install_missing_dep(utils):
pkgname = utils.config["mulversion_pkgname"]
utils.erase_package(pkgname)
pkgname_missing = "tdnf-missing-dep"

utils.run(['tdnf', 'install', '-y', '--nogpgcheck', pkgname, pkgname_missing])
assert not utils.check_package(pkgname)


def test_install_memcheck(utils):
pkgname = utils.config["mulversion_pkgname"]
utils.erase_package(pkgname)
Expand Down
17 changes: 11 additions & 6 deletions solv/tdnfpackage.c
Original file line number Diff line number Diff line change
Expand Up @@ -1576,6 +1576,12 @@ SkipBasedOnType(
type == SOLVER_RULE_PKG_INSTALLED_OBSOLETES;
}

if (dwSkipProblem & SKIPPROBLEM_BROKEN)
{
/* see https://github.com/openSUSE/libsolv/blob/master/src/rules.h */
result = result || type & SOLVER_RULE_PKG;
}

if (dwSkipProblem & SKIPPROBLEM_DISABLED)
{
/**
Expand Down Expand Up @@ -1686,11 +1692,6 @@ SolvReportProblems(
type = solver_ruleinfo(pSolv, dwProblemId,
&dwSource, &dwTarget, &dwDep);

if (SkipBasedOnType(pSolv, type, dwSource, dwSkipProblem))
{
continue;
}

pszProblem = solver_problemruleinfo2str(pSolv, type, dwSource,
dwTarget, dwDep);

Expand All @@ -1703,7 +1704,11 @@ SolvReportProblems(
}
}

dwError = ERROR_TDNF_SOLV_FAILED;
if (!SkipBasedOnType(pSolv, type, dwSource, dwSkipProblem))
{
dwError = ERROR_TDNF_SOLV_FAILED;
}

pr_err("%u. %s\n", ++total_prblms, pszProblem);
}

Expand Down
2 changes: 2 additions & 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[] =
{"sec-severity", required_argument, 0, 0}, //--sec-severity
{"security", no_argument, 0, 0}, //--security
{"setopt", required_argument, 0, 0}, //--set or override options
{"skip-broken", no_argument, &_opt.nSkipBroken, 1},
{"skipconflicts", no_argument, 0, 0}, //--skipconflicts to skip conflict problems
{"skipdigest", no_argument, 0, 0}, //--skipdigest to skip verifying RPM digest
{"skipobsoletes", no_argument, 0, 0}, //--skipobsoletes to skip obsolete problems
Expand Down Expand Up @@ -339,6 +340,7 @@ TDNFCopyOptions(
pArgs->nNoAutoRemove = pOptionArgs->nNoAutoRemove;
pArgs->nJsonOutput = pOptionArgs->nJsonOutput;
pArgs->nTestOnly = pOptionArgs->nTestOnly;
pArgs->nSkipBroken = pOptionArgs->nSkipBroken;

cleanup:
return dwError;
Expand Down

0 comments on commit 562b022

Please sign in to comment.