Bug#833656: cme fails with dpkg error

Brendan O'Dea bod at debian.org
Sun Aug 14 07:27:39 UTC 2016


On Sun, Aug 14, 2016 at 12:36:03AM +0200, gregor herrmann wrote:
>use AptPkg::Config '$_config';
>use AptPkg::System '$_system';
>use AptPkg::Version;
>use AptPkg::Cache ;
>
>$_config->init;
>$_system = $_config->system;
>my $vs = $_system->versioning;
>my $apt_cache = AptPkg::Cache->new ;

This is a bit puzzling, but I am guessing that the bug is in apt:
getDpkgStatusLocation is modifying the global _config object of libapt-pkg in
such a way that if debSystem::Initialize is called twice, the results will be
different.

As far as I can make out, the code appears to be modifying the configuration
in order to get a derived value for Dir::State::status, which it then returns
so that the caller can set the value.  This means that you are effectively
doing:


  Cnf.Set("Dir::State::status", {
    Cnf.Set("Dir::State::status", "status");
    return Cnf.FindFile("Dir::State::status");
  });

along with some other manipulations.  If I understand your intent correctly, I
would recommend rewriting getDpkgStatusLocation to take a const reference to
the Configuration, and to use an internal temporary instance.  A brief comment
to explain what the heck it is trying to achieve wouldn't go astray either.

You could argue that the Initialize method shouldn't be called twice, but that
may be out of the caller's hands.

To clarify what's actually happening here, this line:

  $_config->init;

invokes pkgInitConfig under the hood, on the global C++ _config object.  This
populates it with general APT things, e.g. Dir::State, but not Debian-specific
things like Dir::State::status.  After that, the following line:

  $_system = $_config->system;

calls pkgInitSystem, passing in the global _config object, and populating the
global _system object (which is magically bound to $_system, so that
assignment works).  That indirectly calls debSystem::Initialize, which sets
Debian-specific things like Dir::State::status and Dir::State::extended_status.

Adding some debugging of the working code from the example directory, after
the $_config->init line I get as expected:

  RootDir=
  Dir=/
  Dir::State=var/lib/apt/
  Dir::State::status=
  Dir::State::extended_states=

and after the $_system = ... line:

  RootDir=
  Dir=/
  Dir::State=var/lib/apt/
  Dir::State::status=/var/lib/dpkg/status
  Dir::State::extended_states=extended_states

For the case of libconfig-model-dpkg-perl, I'm seeing the following for after the init:

  RootDir=
  Dir=
  Dir::State=var/lib/apt/
  Dir::State::status=var/lib/dpkg/status
  Dir::State::extended_states=extended_states

which suggests that the _config object has been modified prior to this code
being run.  Not sure where, perhaps there is another use of AptPkg in cme?

--bod



More information about the pkg-perl-maintainers mailing list