<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<!DOCTYPE bugzilla SYSTEM "https://bugzilla.yoctoproject.org/page.cgi?id=bugzilla.dtd">

<bugzilla version="5.0.6"
          urlbase="https://bugzilla.yoctoproject.org/"
          
          maintainer="it-coreprojects-helpdesk@linuxfoundation.org"
>

    <bug>
          <bug_id>11362</bug_id>
          
          <creation_ts>2017-04-13 19:58:34 +0000</creation_ts>
          <short_desc>[libsolv] Replacing a package runs the installation scripts in an unexpected order</short_desc>
          <delta_ts>2018-02-01 17:56:35 +0000</delta_ts>
          <reporter_accessible>1</reporter_accessible>
          <cclist_accessible>1</cclist_accessible>
          <classification_id>6</classification_id>
          <classification>Yocto Project Subprojects</classification>
          <product>opkg</product>
          <component>opkg</component>
          <version>0.3.4</version>
          <rep_platform>x86</rep_platform>
          <op_sys>x86_64</op_sys>
          <bug_status>RESOLVED</bug_status>
          <resolution>FIXED</resolution>
          
          
          <bug_file_loc></bug_file_loc>
          <status_whiteboard></status_whiteboard>
          <keywords></keywords>
          <priority>Undecided</priority>
          <bug_severity>normal</bug_severity>
          <target_milestone>0.3.6</target_milestone>
          
          
          <everconfirmed>1</everconfirmed>
          <reporter name="Paul Spangler">paul.spangler</reporter>
          <assigned_to name="Alejandro del Castillo">alejandro.delcastillo</assigned_to>
          
          
          
          <cf_os>---</cf_os>
          <cf_regression_type>---</cf_regression_type>
          
          <cf_docchange>Don&apos;t know</cf_docchange>

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>72495</commentid>
    <comment_count>0</comment_count>
      <attachid>3721</attachid>
    <who name="Paul Spangler">paul.spangler</who>
    <bug_when>2017-04-13 19:58:34 +0000</bug_when>
    <thetext>Created attachment 3721
Example reproduction packages

When two packages have a Provides, Conflicts, and Replaces for the same virtual package, installing either one will automatically remove (replace) the other. However, opkg runs the installation scripts of the two packages in an unexpected order. Specifically, it runs the preinst of the replacing package prior to running the prerm of the replaced package.

See the attached packages that don&apos;t install any files but replace one another.

Expectation
-----------
Either run the scripts like an upgrade (prerm of the old, preinst of the new, replace files, postrm of the old, postinst of the new) or completely remove the replaced package first. apt appears to do the latter:

$ apt-get -v
apt 1.2.19 (amd64)
$ sudo apt-get install --allow-unauthenticated -o Acquire::ForceHash=md5sum test-package-2
The following packages will be REMOVED:
  test-package-1:x64
The following NEW packages will be installed:
  test-package-2:x64
0 upgraded, 1 newly installed, 1 to remove and 1 not upgraded.
Need to get 838 B of archives.
After this operation, 0 B of additional disk space will be used.
Do you want to continue? [Y/n] 
Get:1 ... test-package-2 1.0.0-1 [838 B]
Fetched 838 B in 0s (56.5 kB/s)       
(Reading database ... 319302 files and directories currently installed.)
Removing test-package-1:x64 (1.0.0-1) ...
Running prerm script from /var/lib/dpkg/info/test-package-1.prerm
Running postrm script from /var/lib/dpkg/info/test-package-1.postrm
(Reading database ... 319304 files and directories currently installed.)
Preparing to unpack .../test-package-2_1.0.0-1_x64.ipk ...
Running preinst script from /var/lib/dpkg/tmp.ci/preinst
Unpacking test-package-2:x64 (1.0.0-1) ...
Setting up test-package-2:x64 (1.0.0-1) ...
Running postinst script from /var/lib/dpkg/info/test-package-2.postinst

Actual Result
-------------
# opkg -v
opkg version 0.3.4 (libsolv 0.6.24)
# opkg install test-package-2
Installing test-package-2 (1.0.0) on root
Running preinst script from /tmp/opkg-jJumYW/test-package-2-JoBT1z/preinst
Removing test-package-1 (1.0.0) from root...
Running prerm script from ///var/lib/opkg/info/test-package-1.prerm
Running postrm script from ///var/lib/opkg/info/test-package-1.postrm
Configuring test-package-2.
Running postinst script from ///var/lib/opkg/info/test-package-2.postinst</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>72850</commentid>
    <comment_count>1</comment_count>
    <who name="Alejandro del Castillo">alejandro.delcastillo</who>
    <bug_when>2017-04-25 22:58:14 +0000</bug_when>
    <thetext>this is not a problem with the internal solver (a is installed, and b replaces/conflicts/provides a):

adelcast@delcastillo2 ~/git/opkg/tests $ opkg -o /tmp/opkg --force-postinstall install b
Removing a (1.0) from root...
prerm a
postrm a
Installing b (1.0) on root.
Downloading file:/tmp/opk/b_1.0_all.opk.
preinst b
Configuring b.
postinst b</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>72881</commentid>
    <comment_count>2</comment_count>
    <who name="Alejandro del Castillo">alejandro.delcastillo</who>
    <bug_when>2017-04-26 21:48:38 +0000</bug_when>
    <thetext>I believe this is a bug with the default ordering give by libsolv, when transaction_order is being called. I opened a bug report to libsolv to get this addressed [1]

As a workaround, we could alter the ordering manually, making sure we do the removal operations before the install/upgrade ones.


[1] https://github.com/openSUSE/libsolv/issues/194</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>72960</commentid>
    <comment_count>3</comment_count>
    <who name="Alejandro del Castillo">alejandro.delcastillo</who>
    <bug_when>2017-05-01 21:56:48 +0000</bug_when>
    <thetext>Digging deeper, this is not a libsolv issue, but an issue with opkg. The operation described in this ticket is best described as an upgrade, instead of as a erase/install pair. An upgrade allows config data to be migrated, which is not possible if you first remove a package, then install it&apos;s replacement. The flags 
SOLVER_TRANSACTION_SHOW_OBSOLETES &amp;&amp; SOLVER_TRANSACTION_OBSOLETE_IS_UPGRADE tells libsolv to represent this operation as an upgrade, which is what we want. However, to be able to use this flags, opkg upgrade operation needs to support the case where you are upgrading from packages with different names. The work to get this implemented sounds substantial, I&apos;ll try to get it in for 0.3.5, but might need to be defered to 0.3.6.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>79297</commentid>
    <comment_count>4</comment_count>
    <who name="Alejandro del Castillo">alejandro.delcastillo</who>
    <bug_when>2018-02-01 17:56:35 +0000</bug_when>
    <thetext>fixed on commit b3f0f7cf02c6f9eb4eaf985a806aec9333164cf5</thetext>
  </long_desc>
      
          <attachment
              isobsolete="0"
              ispatch="0"
              isprivate="0"
          >
            <attachid>3721</attachid>
            <date>2017-04-13 19:58:34 +0000</date>
            <delta_ts>2017-04-13 19:58:34 +0000</delta_ts>
            <desc>Example reproduction packages</desc>
            <filename>TestPackages.zip</filename>
            <type>application/x-download</type>
            <size>1368</size>
            <attacher name="Paul Spangler">paul.spangler</attacher>
            
              <data encoding="base64">UEsDBBQAAAAIANR1jUq5vVZsAgIAAFYCAAArAAAAVGVzdFBhY2thZ2VzL3Rlc3QtcGFja2FnZS0x
XzEuMC4wLTBfeDY0Lmlwa1O0SSxKzrDjSklNykzM003KzEssqlRQUDA0sTS0NDAxMTVTUDBQAAEI
aWhgYGZioqBgogADCVxGegZcyfl5JUX5OXoliUV66VWE9RsbwkxI4JLv5mBQ//MmgoH57cSDXsyG
Am3f5yw/wf3GLHM7r45SV5wNx9Gte4/nrGk2jFS7mVRb5R4tyrVVXFzwe/MEH6PJPyfvl0jdq9wy
Y6pq/ezOv5XSJzoDhC3naSzcMSFIa+bHzP+XNq3p9lT2PChwqbzy+Lnv8t/dNdzUfrQc/Hrj8Yz/
T0Nqf+qz/rSfpzW18OLiZf7/dv5/niGnEDnZaoto/bypOZmGTh9Ep7dquOjdkFFUWOJ79OXqmsUb
E8PnTTt3U239w9ZXGp6z3fcuSt1k+PSt2SnV3dceCPN2i85/fe7jrqt1T3U+TZ52SOndIWP+Vk7/
5WvUdN+/FeeUUdkwUXfRUVWXHcUl/9vM9HJNON6avZ8m9Sm2Wu9mb+5cM7N3U9YwBi+/265UJvhn
L/NkvrnnDdcstIz4d7uMl4eH54/Eegcv3n0MXAwMKYklifAgJyLWLA0RsYYI9cuX0xdYGgCBsWEg
w0WHBj9ni7ZjbM+Otbkde8b2jIutra3tWRsP17It5VLMzpmFnkmCFzRdf/5U/XFFcJL79zsaEqyL
E0R4ihgY3gSJf2RgY2DgAgBQSwMEFAAAAAgA1HWNSgLfcTr8AQAAVAIAACsAAABUZXN0UGFja2Fn
ZXMvdGVzdC1wYWNrYWdlLTJfMS4wLjAtMV94NjQuaXBrU7RJLErOsONKSU3KTMzTTcrMSyyqVFBQ
MDSxNLQ0MDWxNFNQMFAAAQhpaGBgZmKioGCiAAM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