add opkg_compare_versions function

* not used in opkg but can be usefull, e.g. instead of
  opkg-utils/opkg-compare-versions.c

Signed-off-by: Martin Jansa <Martin.Jansa@gmail.com>
Ensure we use the uname/gname fields when extracting tarballs

When updating packages on the target device we ideally want to match
user and group numbers from the existing file system. This patch encourages
opkg to lookup the uname/gname fields first and only use the hardcoded
numerical values if that fails.

Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Signed-off-by: Martin Jansa <Martin.Jansa@gmail.com>
Fix dependency issues for preinst scripts

There is a problem with dependency order when installing packages. The key
problem revolves around the satisfy_dependencies_for() function which is
called from opkg_install_pkg just before the installation (and preinst)
happens.

The satisfy_dependencies_for() function calls pkg_hash_fetch_unsatisfied_dependencies()
which will only return packages which were previously not marked as
*going* to be installed at some point. For the purposes of
opkg_install_pkg() we really need to know which dependencies haven't been
installed yet.

This patch adds pkg_hash_fetch_satisfied_dependencies() which returns a
list of package dependencies. We can then directly check the status of
these and ensure any hard dependencies (not suggestions or recommendations)
are installed before returning.

Consider the situation (where -> means 'depends on'):

X -> A,E
A -> B,E
E -> B
B -> C

Currently X would install A and E. When installing A the packages B, E
and C would be marked as "to install". When the package B is considered
the second time (as a dependency of E rather than A), it would install
straight away even though C was not currently installed, just marked
as needing to be installed.

The patch changes the behaviour so B can't install until C really is installed.

This change is required to run the postinst scripts in the correct order.

Signed-off-by: Martin Jansa <Martin.Jansa@gmail.com>
Failed postinst script is not fatal with conf->offline_root

When we have an offline root and have specified force-postinstall,
attempt to run the postinstall but if it fails, just leave it in the
status file as needing to run. We can issue a NOTICE this is happened
but supress errors. This means the OE class doesn't have to do any
further post processing of the postinstalls itself.

Signed-off-by: Martin Jansa <Martin.Jansa@gmail.com>
Do not read /etc/opkg/*.conf if -f is specified

If a configuration file is specified on the command line, we should
assume it contains all of the configuration and not try to read the
configuration in /etc/opkg.

Signed-off-by: Paul Eggleton <paul.eggleton@linux.intel.com>
Signed-off-by: Martin Jansa <Martin.Jansa@gmail.com>
detect circular dependencies

Add logic to detect circular dependencies. If we see any dependency from
any given parent twice, ignore it the second time and print a notice message
that we did so.

Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Signed-off-by: Martin Jansa <Martin.Jansa@gmail.com>
merge newpkg->provides even when oldpkg->provides existed

* introduced in http://code.google.com/p/opkg/source/diff?spec=svn277&r=277&format=side&path=/trunk/libopkg/pkg.c
* the problem happens when oldpkg provide 1 and newpkg provide 2
  provides_count is merged to 2, but oldpkg->provides has only 1 entry
  causing SIGSEGV:
  pkg_formatted_field (fp=fp@entry=0x1444ce0, pkg=pkg@entry=0x120c620, field=<optimized out>, field@entry=0x7ffff7bd2abe "Provides") at pkg.c:739
  739                           fprintf(fp, "%s %s", i == 1 ? "" : ",",
  (gdb) bt
  #0  pkg_formatted_field (fp=fp@entry=0x1444ce0, pkg=pkg@entry=0x120c620, field=<optimized out>, field@entry=0x7ffff7bd2abe "Provides") at pkg.c:739
  #1  0x00007ffff7bc32fc in pkg_print_status (pkg=0x120c620, file=0x1444ce0) at pkg.c:887
  #2  0x00007ffff7bbff59 in opkg_conf_write_status_files () at opkg_conf.c:400
  #3  0x00007ffff7bbad8a in write_status_files_if_changed () at opkg_cmd.c:65
  #4  0x00007ffff7bbb73e in opkg_upgrade_cmd (argc=<optimized out>, argv=<optimized out>) at opkg_cmd.c:577
  #5  0x00007ffff7bbbcc2 in opkg_cmd_exec (cmd=cmd@entry=0x7ffff7dda080, argc=argc@entry=1, argv=argv@entry=0x7fffffffe768) at opkg_cmd.c:1319
  #6  0x000000000040165f in main (argc=3, argv=0x7fffffffe758) at opkg-cl.c:377

Signed-off-by: Martin Jansa <Martin.Jansa@gmail.com>
Add the --prefer-arch-to-version option

If there were more than one candidate which had the same pkg name in the
candidate list, for example, the same pkg with different versions, then
it would use the last one which was the highest version one in the past,
but it will use the higher arch priority when this option is specified.

Signed-off-by: Robert Yang <liezhi.yang@windriver.com>
pkg_depends: fix version constraints

* factor parsing version constraint to str_to_constraint and use that
  from pkg (pkg_version_satisfied) and also pkg_depends (parseDepends)
* fix constraint_to_str(), for EARLIER and LATER it was using '<' and
  '>' which is parsed later as EARLIER_EQUAL and LATER_EQUAL
* show notice when deprecated '<' or '>' is used

Signed-off-by: Martin Jansa <Martin.Jansa@gmail.com>
pkg_depends: fix version_constraints_satisfied

* with
  Package: a
  Version: 1
  and
  Conflicts: a (<< 1)
  we have comparison == 0, but constraint EARLIER is not satisfied!

Signed-off-by: Martin Jansa <Martin.Jansa@gmail.com>
Fix: RRECOMMENDS and RDEPENDS being basically the same

While removing a package with opkg, the process shouldn't be blocked if
another package RECOMMENDS the package wanted to be removed. This is
because, while generating the dependencies, opkg adds dependencies to
depended_upon_by even if dependency's type is RECOMMEND. The fix is to
skip dependencies of type RECOMMEND while constructing depended_upon_by.

Bug info:
https://bugzilla.yoctoproject.org/show_bug.cgi?id=2431

Signed-off-by: Andrei Gherzan <andrei@gherzan.ro>
Don't print provides if nothing is provided

Every package provides itself. While printing package information all
fields are printed only if there is any relevant info for them. For
example: a package with no "Replaces" won't get this printed at all.
Packages which provide only themselves, were printing this field but with
no values. This patch skips this field if the package provides only
itself.

Signed-off-by: Andrei Gherzan <andrei@gherzan.ro>
Do not call sync wen installing into an offline root

When installing into an offline root, calling sync() is pointless and just
hurts performance.  Don't let's do that.

Signed-off-by: Phil Blundell <philb@gnu.org>