<?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>4120</bug_id>
          
          <creation_ts>2013-03-26 17:13:43 +0000</creation_ts>
          <short_desc>rootfs_deb doesn&apos;t support BAD_RECOMMENDATIONS</short_desc>
          <delta_ts>2025-02-06 16:14:36 +0000</delta_ts>
          <reporter_accessible>1</reporter_accessible>
          <cclist_accessible>1</cclist_accessible>
          <classification_id>7</classification_id>
          <classification>Build System, Metadata &amp; Runtime</classification>
          <product>OE-Core</product>
          <component>core</component>
          <version>1.4</version>
          <rep_platform>x86</rep_platform>
          <op_sys>Multiple</op_sys>
          <bug_status>NEW</bug_status>
          <resolution></resolution>
          
          
          <bug_file_loc></bug_file_loc>
          <status_whiteboard></status_whiteboard>
          <keywords></keywords>
          <priority>Medium</priority>
          <bug_severity>enhancement</bug_severity>
          <target_milestone>Future</target_milestone>
          
          
          <everconfirmed>1</everconfirmed>
          <reporter name="Ross Burton">ross.burton</reporter>
          <assigned_to name="Unassigned">unassigned</assigned_to>
          <cc>dvhart</cc>
    
    <cc>liezhi.yang</cc>
    
    <cc>manish.das</cc>
    
    <cc>mark.hatle</cc>
    
    <cc>meta.mr.watcher</cc>
    
    <cc>meta.watcher</cc>
    
    <cc>randy.macleod</cc>
    
    <cc>richard.purdie</cc>
    
    <cc>sgw</cc>
    
    <cc>tim.orling</cc>
          
          
          <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>31186</commentid>
    <comment_count>0</comment_count>
    <who name="Ross Burton">ross.burton</who>
    <bug_when>2013-03-26 17:13:43 +0000</bug_when>
    <thetext>BAD_RECOMMENDATIONS is only implemented for rootfs_ipkg at present.

(see 3916 for the rootfs_rpm bug)</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>34615</commentid>
    <comment_count>1</comment_count>
    <who name="Mark Hatle">mark.hatle</who>
    <bug_when>2013-07-16 17:28:34 +0000</bug_when>
    <thetext>This is about image generation and not deployment.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>36141</commentid>
    <comment_count>2</comment_count>
    <who name="Hongxu Jia">hongxu.jia</who>
    <bug_when>2013-09-02 09:02:03 +0000</bug_when>
    <thetext>Move to 1.6</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>81963</commentid>
    <comment_count>3</comment_count>
    <who name="Manish Das">manish.das</who>
    <bug_when>2018-10-29 08:34:41 +0000</bug_when>
    <thetext>We tried to add below &quot;handle_bad_recommendations(self)&quot; function in package_manger.py to handle BAD_RECOMMENDATION for dpkg
here we are adding 

&quot;Status: hold ok not-installed&quot; in dpkg status file and trying to hold the specified package for  bad_recommendation.

It looks like  that &quot;Status: hold ok not-installed&quot; is not working for &quot;apt-get&quot; command.

After modifying &quot;status:hold ok not-installed&quot; in dpkg status file also, it is not able to hold for particular package which is specified in &quot;BAD_RECOMMENDATION&quot; and it is getting installed. 

It seems that issue is with apt-get.
Till the time apt-get  does not support to  prevent installation  of specific package, from a list of specified packages, BAD_RECOMMENDATIONS will not work for DPKG 


    def handle_bad_recommendations(self):
        bad_recommendations = (self.d.getVar(&quot;BAD_RECOMMENDATIONS&quot;, True) or &quot;&quot;).strip()
        if not bad_recommendations:
            return
        status_file = self.target_rootfs + &quot;/var/lib/dpkg/status&quot;
        with open(status_file + &quot;.tmp&quot;, &quot;w&quot;) as status:
            for pkg in bad_recommendations.split():
                pkg_info = (&apos;apt-cache&apos;, &apos;show&apos;, pkg)
                try:
                    output = subprocess.check_output(pkg_info, stderr=subprocess.STDOUT).decode(&quot;utf-8&quot;)
                except subprocess.CalledProcessError as e:
                    bb.fatal(&quot;Cannot get package info. Command &apos;%s&apos; &quot;
                             &quot;returned %d:\n%s&quot; % (&apos; &apos;.join(pkg_info), e.returncode, e.output))
                for line in output.splitlines():
                    if not line:
                        status.write(&quot;Status: hold ok not-installed\n\n&quot;)
                        break
                    if line.startswith(&apos; &apos;) or line.split(&apos;: &apos;, 1)[0] not in (&apos;Filename&apos;, &apos;Size&apos;, &apos;MD5sum&apos;, &apos;MSDOS-Filename&apos;):
                        status.write(line + &quot;\n&quot;)
        os.rename(status_file + &quot;.tmp&quot;, status_file)

So it looks like once apt-get support for &quot;Status: hold ok not-installed&quot; then by using above method we BAD_RECOMMENDATIONS should work for DPKG.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>81964</commentid>
    <comment_count>4</comment_count>
    <who name="Ross Burton">ross.burton</who>
    <bug_when>2018-10-29 11:09:11 +0000</bug_when>
    <thetext>I believe this syntax works with apt:

$ apt-get install foo bar-

Where foo recommends bar, but bar won&apos;t be installed because it has a - suffix.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>81984</commentid>
    <comment_count>5</comment_count>
    <who name="Manish Das">manish.das</who>
    <bug_when>2018-11-01 01:23:44 +0000</bug_when>
    <thetext>&quot;$ apt-get install foo bar-
Where foo recommends bar, but bar won&apos;t be installed because it has a - suffix&quot;

As per our understating above command will remove the  specified package AFTER that package is installed. However, our target here is to prevent the installation of specified package which has been mentioned for &quot;bad_recommendations&quot;

We tried to remove the package after installation using below specified function under class DpkgPM(OpkgDpkgPM) but we don&apos;t think it is the correct way. Please let us know if there is any apt -get command which can prevent installation of specific package from a list of specified packages.

def install(self, pkgs, attempt_only=False): 
bad_recommendations = (self.d.getVar(&quot;BAD_RECOMMENDATIONS&quot;, True) or &quot;&quot;).strip()
if  bad_recommendations:
    pkg=bad_recommendations.split()
    cmd = &quot;%s --admindir=%s/var/lib/dpkg --instdir=%s&quot;&quot; -P --force-depends %s&quot; % \
          (bb.utils.which(os.getenv(&apos;PATH&apos;), &quot;dpkg&quot;),self.target_rootfs, self.target_rootfs,&apos; &apos;.join(pkg))
    try:
        bb.note(&quot;Installing the following packages: %s&quot; % &apos; &apos;.join(pkgs))
        subprocess.check_output(cmd.split(), stderr=subprocess.STDOUT)
    except subprocess.CalledProcessError as e:
        (bb.fatal, bb.warn)[attempt_only](&quot;Unable to install packages. &quot;
                                      &quot;Command &apos;%s&apos; returned %d:\n%s&quot; %
                                      (cmd, e.returncode, e.output.decode(&quot;utf-8&quot;)))</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>81990</commentid>
    <comment_count>6</comment_count>
    <who name="Ross Burton">ross.burton</who>
    <bug_when>2018-11-01 11:25:26 +0000</bug_when>
    <thetext>That might be what the docs say but it&apos;s not what happens: it doesn&apos;t install a package and then uninstall it.

eg a2ps in Debian:

Package: a2ps
Version: 1:4.14-2
Installed-Size: 3624
Maintainer: Debian QA Group &lt;packages@qa.debian.org&gt;
Architecture: amd64
Depends: file, psutils, libc6 (&gt;= 2.14), libpaper1
Recommends: bzip2, lpr | rlpr | cupsys-client, wdiff
Suggests: emacsen-common, ghostscript, graphicsmagick-imagemagick-compat | imagemagick, groff, gv, html2ps, t1-cyrillic, texlive-base-bin

$ sudo apt-get install a2ps
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following additional packages will be installed:
  lpr psutils wdiff
Suggested packages:
  graphicsmagick-imagemagick-compat | imagemagick groff gv html2ps t1-cyrillic texlive-base-bin magicfilter
  | apsfilter gs wdiff-doc
The following NEW packages will be installed:
  a2ps lpr psutils wdiff
0 upgraded, 4 newly installed, 0 to remove and 0 not upgraded.
Need to get 916 kB of archives.
After this operation, 4,925 kB of additional disk space will be used.

Note how the recommends lpr and wdiff are being installed.

Here I tell it not to install the recommendations:

$ sudo apt-get install a2ps lpr- lprng- cups-bsd- wdiff-
Reading package lists... Done
Building dependency tree
Reading state information... Done
Package &apos;lpr&apos; is not installed, so not removed
Package &apos;lprng&apos; is not installed, so not removed
Package &apos;wdiff&apos; is not installed, so not removed
Package &apos;cups-bsd&apos; is not installed, so not removed
The following additional packages will be installed:
  psutils
Suggested packages:
  graphicsmagick-imagemagick-compat | imagemagick groff gv html2ps t1-cyrillic texlive-base-bin
Recommended packages:
  lpr | rlpr | cupsys-client wdiff
The following NEW packages will be installed:
  a2ps psutils
0 upgraded, 2 newly installed, 0 to remove and 0 not upgraded.
Need to get 700 kB of archives.
After this operation, 3,935 kB of additional disk space will be used.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>82167</commentid>
    <comment_count>7</comment_count>
    <who name="Manish Das">manish.das</who>
    <bug_when>2018-11-12 06:49:26 +0000</bug_when>
    <thetext>We tried the commands mentioned below:
sudo apt-get install a2ps lpr- lprng- cups-bsd- wdiff-

But when we use this command it gives error due to the package dependency while installing. So it throws  error and bitbake stops, this  behavior is  for &apos;core-image-sato-sdk&apos;We tired other packages like &apos;acl&apos;,&apos;debianutils&apos;,&apos;connman&apos; etc. all gave error due to dependency. 


We tried the method which is first install and then remove the package mentioned in BAD_RECOMMENDATIONS as mentioned below
  
def install(self, pkgs, attempt_only=False):
bad_recommendations = (self.d.getVar(&quot;BAD_RECOMMENDATIONS&quot;, True) or &quot;&quot;).strip()
if  bad_recommendations:
    pkg=bad_recommendations.split()
    cmd = &quot;%s purge %s&quot; % (self.apt_get_cmd, &apos; &apos;.join(pkg))

    try:
        bb.warn(&quot;It will be remove :  %s  package from the list &quot; % &apos; &apos;.join(pkgs))
        subprocess.check_output(cmd.split(), stderr=subprocess.STDOUT)
    except subprocess.CalledProcessError as e:
        (bb.fatal, bb.warn)[attempt_only](&quot;Unable to remove packages. &quot;
                                      &quot;Command &apos;%s&apos; returned %d:\n%s&quot; %(cmd, e.returncode, e.output.decode(&quot;utf-8&quot;)))

This works fine and removes the package mentioned in BAD_RECOMMENDATIONS with a warning. 

@Ross: Please suggest if this solution is OK or we need to look for other alternative solutions.</thetext>
  </long_desc>
      
      

    </bug>

</bugzilla>