Bug#833656: cme fails with dpkg error

David Kalnischkies david at kalnischkies.de
Sun Aug 14 11:00:33 UTC 2016


On Sun, Aug 14, 2016 at 05:27:39PM +1000, Brendan O'Dea wrote:
> 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.

No, the setting of Dir::State::status is guarded by a check for
existence, so you could call it a million times and still get the same
result.

The problem is the value it sets the first time around is not a value
which starts with "/" as it expects "Dir" to be set, but it isn't in
this case, so that later then the "Dir::State::status" value is read via
FindFile it will recognize that Dir::state::status isn't an absolute
path (as it is missing the / in the front) and hence prefixes the values
of Dir::state and Dir – which by now are set letting you end up with a:
/ (<- Dir)
var/lib/apt (<- Dir::state)
var/lib/dpkg/status (<- Dir::state::status, which is what it generates if
neither Dir nor Dir::state where set at the time this value was set itself,
but it "should" be /var/lib/dpkg/status – mind the gap^Wslash)


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

So, for brevities sake lets say its: Cnf.CndSet("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

Your are right, that works in the current instance (I tried something else
first where it wouldn't have work and … If all you have is a hammer…) and it is
actually a bit shorter by avoiding the back and forth, too. Thanks!


> 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.

That is what is supposed to happen, yes (at least as far as the description
goes, no idea about the perl part)


> 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?

The first is correct, the later indicates that $_config->init was never called
as Dir couldn't be empty in that case (and that Dir::State gets its default
value here is actually an unattended but harmless side effect of the dpkg/status
finding code in its current form). Given that the error message has a '/' in
front I lean towards assuming that the configuration is eventually initialized,
just too late.


Best regards

David Kalnischkies
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 801 bytes
Desc: not available
URL: <http://lists.alioth.debian.org/pipermail/pkg-perl-maintainers/attachments/20160814/345b17ec/attachment-0001.sig>


More information about the pkg-perl-maintainers mailing list