[wpkg-users] On remove only the first check is executed

Rainer Meier r.meier at wpkg.org
Thu Jun 18 18:47:18 CEST 2009


Hi Stefan,

Pendl Stefan wrote:
> Hi Rainer,
>      if I have four checks defined and a package is removed, only the first check is executed, if it returns a positive result, the additional three checks are not executed.
> 
> Is this by design?

It's actually an optimization. Let's explain...


> On install all checks are executed.

If you specify the checks in "flat" order eg
<check ... />
<check ... />
<check ... />

Then the checks are evaluated loke you would use a logical AND for the checks.

WPKG will evaluate all of them in order and the result is true (installed) only
if all of them are true (none fails).

If one of them fails, then the result is clear anyway: it will be false!
There is no way that the final evaluation will be true if one of the checks fail.

So WPKG stops executing further checks if one of them fails.

The result is equal to the following construct:

<check type='logical' condition='and'>
	<check ... />
	<check ... />
	<check ... />
</check>


If you use logical 'or' then you will see only the checks evaluated until the
first one returns true because the result will be true anyway.


This is the usual way of evaluating and/or-connected evaluations.
Use any programming language and write something like
boolean v = true;
if (v == true || runSomeMethod()){
}

you will never see runSomeMethod() evaluated because "v==true" evaluates true
already and there is no need to evaluate runSomeMethod() because it would anyway
not change the result.

You can use this to optimize some code too. Simply writing something like

runCodeWhichShouldReturnTrue() && runCodeDepending();

Then runCodeOnDepending() is run only if the left part is true, because then the
program needs to know the value of runCodeDepending() to know the result. If
runCodeWhichShouldReturnTrue() returns false, then runCodeDepending() is never
executed because it will not change the term result anyway, no matter what its
exit code is.

br,
Rainer



More information about the wpkg-users mailing list